Two seperate def forward calls

is there any way to have two seperate def forward, functions. I am asking because I want to create two seperate run throughs of my network which are slightly different from one another. If there is a simpler way to do this please feel free to share, the two seperate forward functions just seemed the most obvious path.

You could use one forward method with a condition calling two other functions or just running different code:

def forward(self, x):
    if cond:
        output = forward1(x)
        # or
        output = your calculation ...
    else:
        output = forward2(x)
        # or
        output = your calculation ...
    return output

I will try that, any other input is still welcome. The two different code idea i dont love but the if statement may work, thank you for your help! @ptrblck appreciate it very much

1 Like