Run tuning only if epochs and learning_rate are both > 0
@@ -136,6 +136,14 @@ class NMTEngine:
self._model_loaded = True
def tune(self, suggestions, epochs=None, learning_rate=None):
+ # Set tuning parameters
+ if epochs is None or learning_rate is None:
+ _epochs, _learning_rate = self._estimate_tuning_parameters(suggestions)
+
+ epochs = epochs if epochs is not None else _epochs
+ learning_rate = learning_rate if learning_rate is not None else _learning_rate
+
+ if learning_rate > 0. or epochs > 0:
if self._tuner is None:
from nmmt.NMTEngineTrainer import NMTEngineTrainer
self._tuner = NMTEngineTrainer(self, gpu_ids=([0] if self.using_cuda else None))
@@ -144,13 +152,6 @@ class NMTEngine:
self._tuner.min_perplexity_decrement = -1.
self._tuner.set_log_level(logging.NOTSET)
- # Set tuning parameters
- if epochs is None or learning_rate is None:
- _epochs, _learning_rate = self._estimate_tuning_parameters(suggestions)
-
- epochs = epochs if epochs is not None else _epochs
- learning_rate = learning_rate if learning_rate is not None else _learning_rate
-
self._tuner.min_epochs = self._tuner.max_epochs = epochs
self.optimizer.lr = learning_rate
