Sets up two sub learners for encoder/decoder respectively.
(self, ema_decay: Optional[float], method: str)
| 1052 | @parameterized.product(ema_decay=(None, 0.9), method=("update", "forward_and_backward")) |
| 1053 | # pylint: disable-next=too-many-statements |
| 1054 | def test_learner(self, ema_decay: Optional[float], method: str): |
| 1055 | """Sets up two sub learners for encoder/decoder respectively.""" |
| 1056 | encoder_lr = 0.1 |
| 1057 | opt1_cfg = config_for_function(sgd_optimizer).set( |
| 1058 | learning_rate=encoder_lr, decouple_weight_decay=True, weight_decay=1.0 |
| 1059 | ) |
| 1060 | opt2_cfg = config_for_function(adam_optimizer).set( |
| 1061 | learning_rate=0.0, b1=0.9, b2=0.99, eps=1e-5, l2_regularizer_weight=1.0 |
| 1062 | ) |
| 1063 | learner_rules = [(".*encoder.*", "encoder"), (".*decoder.*", "decoder")] |
| 1064 | |
| 1065 | cfg = CompositeLearner.default_config().set( |
| 1066 | name="test", |
| 1067 | rules=learner_rules, |
| 1068 | learners={ |
| 1069 | "encoder": Learner.default_config().set( |
| 1070 | optimizer=opt1_cfg, enable_per_variable_summaries=True |
| 1071 | ), |
| 1072 | "decoder": Learner.default_config().set( |
| 1073 | optimizer=opt2_cfg, enable_per_variable_summaries=False |
| 1074 | ), |
| 1075 | }, |
| 1076 | ) |
| 1077 | cfg.ema.decay = ema_decay |
| 1078 | learner: CompositeLearner = cfg.instantiate(parent=None) |
| 1079 | |
| 1080 | param_specs = dict( |
| 1081 | encoder=dict( |
| 1082 | weight=ParameterSpec( |
| 1083 | dtype=jnp.float32, |
| 1084 | shape=[3, 4], |
| 1085 | factorization=FactorizationSpec(axes=("row", "col")), |
| 1086 | mesh_axes=PartitionSpec("data", "model"), |
| 1087 | ), |
| 1088 | bias=ParameterSpec( |
| 1089 | dtype=jnp.float32, |
| 1090 | shape=[4], |
| 1091 | factorization=None, |
| 1092 | mesh_axes=PartitionSpec("model"), |
| 1093 | ), |
| 1094 | mean=ParameterSpec( |
| 1095 | dtype=jnp.float32, |
| 1096 | shape=[2], |
| 1097 | factorization=None, |
| 1098 | mesh_axes=PartitionSpec("model"), |
| 1099 | ), |
| 1100 | ), |
| 1101 | decoder=dict( |
| 1102 | head=ParameterSpec( |
| 1103 | dtype=jnp.float32, |
| 1104 | shape=[2, 3], |
| 1105 | factorization=FactorizationSpec(axes=("row", "col")), |
| 1106 | mesh_axes=PartitionSpec("model", None), |
| 1107 | ), |
| 1108 | scalar=ParameterSpec( |
| 1109 | dtype=jnp.float32, |
| 1110 | shape=[], |
| 1111 | factorization=None, |
nothing calls this directly
no test coverage detected