fix optimizer load check
@@ -409,12 +409,7 @@ class TorchGeneratorAgent(TorchAgent, ABC):
else:
states = {}
- if (
- # only build an optimizer if we're training
- 'train' in opt.get('datatype', '')
- # and this is the main model, or on every fork if doing hogwild
- and (shared is None or self.opt.get('numthreads', 1) > 1)
- ):
+ if self._should_initialize_optimizer():
# do this regardless of share state, but don't
self.init_optim(
[p for p in self.model.parameters() if p.requires_grad],
