Skip to content

Commit 9ee9191

Browse files
lingvo-botcopybara-github
authored andcommitted
Add option to keep legacy hparams after copying them to learners. This enables the learner to be replaced or turned off in a child class.
PiperOrigin-RevId: 592037634
1 parent 5e13c40 commit 9ee9191

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lingvo/core/learner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,15 @@ def _AddEvalMetric(self, key, value, weight):
523523
]
524524

525525

526-
def ExtractLearnerFromLegacyParams(tp, cls=Learner):
526+
def ExtractLearnerFromLegacyParams(tp, cls=Learner, remove_legacy_params=True):
527527
"""Extracts legacy learner params from 'tp' to a Learner params.
528528
529529
Args:
530530
tp: BaseTask training params (p.train). Its legacy params will be cleared to
531531
be None after the conversion.
532532
cls: Learner class where we set the params.
533+
remove_legacy_params: Whether to keep the legacy hparams. Default to True
534+
which sets legacy hparams to None.
533535
534536
Returns:
535537
A params for Learner.
@@ -542,7 +544,8 @@ def ExtractLearnerFromLegacyParams(tp, cls=Learner):
542544
v)
543545
continue
544546
setattr(lp, k, v)
545-
setattr(tp, k, None)
547+
if remove_legacy_params:
548+
setattr(tp, k, None)
546549
for line in lp.ToText().split('\n'):
547550
tf.logging.info('Learner params: %s', line)
548551
return lp

0 commit comments

Comments
 (0)