(self, rope_type)
| 1188 | ) |
| 1189 | @pytest.mark.tpu_only |
| 1190 | def test_autoregression(self, rope_type): |
| 1191 | cfg, mla = self.init_mla(self.config_arguments, rope_type) |
| 1192 | prefill_length = cfg.max_prefill_predict_length |
| 1193 | decode_total_length = cfg.max_target_length |
| 1194 | lnx, decoder_segment_ids, decoder_positions = self.get_structured_data(cfg, cfg.dtype) |
| 1195 | |
| 1196 | mla_full, _ = mla( |
| 1197 | lnx, |
| 1198 | lnx, |
| 1199 | decoder_segment_ids=decoder_segment_ids, |
| 1200 | inputs_positions=decoder_positions, |
| 1201 | deterministic=True, |
| 1202 | model_mode=MODEL_MODE_TRAIN, |
| 1203 | ) |
| 1204 | |
| 1205 | lnx_prefill = lnx[:, 0:prefill_length, :] |
| 1206 | decoder_segment_ids_prefill = decoder_segment_ids[:, 0:prefill_length] |
| 1207 | decoder_positions_prefill = decoder_positions[:, 0:prefill_length] |
| 1208 | |
| 1209 | mla_prefill, _ = mla( |
| 1210 | lnx_prefill, |
| 1211 | lnx_prefill, |
| 1212 | decoder_segment_ids=decoder_segment_ids_prefill, |
| 1213 | inputs_positions=decoder_positions_prefill, |
| 1214 | deterministic=True, |
| 1215 | model_mode=MODEL_MODE_PREFILL, |
| 1216 | ) |
| 1217 | |
| 1218 | self.assertTrue( |
| 1219 | jax.numpy.allclose(mla_prefill, mla_full[:, :prefill_length, :], rtol=1e-02, atol=1e-02, equal_nan=False) |
| 1220 | ) |
| 1221 | |
| 1222 | for idx in range(prefill_length, decode_total_length): |
| 1223 | lnx_idx = lnx[:, idx : idx + 1, :] |
| 1224 | decoder_positions_idx = decoder_positions[:, idx : idx + 1] |
| 1225 | mla_idx, _ = mla( |
| 1226 | lnx_idx, |
| 1227 | lnx_idx, |
| 1228 | inputs_positions=decoder_positions_idx, |
| 1229 | deterministic=True, |
| 1230 | model_mode=MODEL_MODE_AUTOREGRESSIVE, |
| 1231 | ) |
| 1232 | |
| 1233 | mla_full_this_idx = mla_full[:, idx : idx + 1, :] |
| 1234 | self.assertEqual(mla_full_this_idx.shape, mla_idx.shape) |
| 1235 | # TODO (b/394626702) uncomment last check when decode and kv_cache are implemented for MLA |
| 1236 | # self.assertTrue(jax.numpy.allclose(mla_full_this_idx, mla_idx, rtol=1e-02, atol=1e-02, equal_nan=False)) |
| 1237 | |
| 1238 | def test_projection_initialization(self): |
| 1239 | """Tests that MLA and Attention layers initialize the correct projection weights.""" |
nothing calls this directly
no test coverage detected