I want to import the model parameters and some other variables from the model file, but what it does instead is going into training again when I try to import it…
how can I make sure it just imports stuff without starting training again?
The training state is also a part of state_dict and will thus be restored when you load you trained model.
After load_state_dict(), you should call dual_encoder.eval() or dual_encoder.training == True. (IIRC, they do the same thing)
Could you post the model.py code?
If seems that you have some training procedure code in there without protecting it with if __name__=='__main__:
Importing a Python module calls each “global” line in the script. You should therefore move all code into functions like in the imagenet example.
The main function won’t be called when you import the module, just if you call it directly (e.g. from your terminal).