Hi,
self.training is available everywhere in your code as it is defined in nn.Module which when you extend this class to create your own, it will be copied to your model definition too. So, you can set it to false in init.
class MyModel(nn.Module):
    def __init__(self):
        super(MyModel, self).__init__()
        self.training = False
        self.fc = nn.Linear(1, 1)
        
    def forward(self, x):
        x = self.fc(x)
        if self.training:
            x = x + 1000
        return x

model = MyModel()
x = torch.ones(1, 1)

testing
model.training = False
model(x)  # a small number such as 1.3203

model.training = True
model(x)  # a large number around thousand

Bests