the python implementation of forward relay.