Sure!
You can adapt @albanD’s code and pass an additional flag to it, if that’s what you are looking for:
 
def forward(self, x, y, training=True):
    if training:
        pass
    else:
        pass

Also, if your forward method behavior switches based on the internal training status (model.train() vs. model.eval()), you don’t even have to pass an additional flag, but can just use the internal one:
class MyModel(nn.Module):
    def __init__(self):
        super(MyModel, self).__init__()
        self.fc = nn.Linear(10, 2)
        
    def forward(self, x):
        if self.training:
            return x
        else:
            return self.fc(x)

x = torch.randn(1, 10)
model = MyModel()
print(model(x).shape)
> torch.Size([1, 10])
model.eval()
print(model(x).shape)
> torch.Size([1, 2])