MCPcopy Create free account
hub / github.com/AI-Hypercomputer/maxtext / test_autoregression

Method test_autoregression

tests/attention_test.py:366–410  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

364
365 @pytest.mark.tpu_only
366 def test_autoregression(self):
367 prefill_length = self.cfg.max_prefill_predict_length
368 decode_total_length = self.cfg.max_target_length
369 lnx, decoder_segment_ids, decoder_positions = self.get_structured_data(self.dtype)
370
371 mha_full, _ = self._attention_as_mha_generic(
372 lnx,
373 lnx,
374 decoder_segment_ids=decoder_segment_ids,
375 inputs_positions=decoder_positions,
376 deterministic=True,
377 model_mode=MODEL_MODE_TRAIN,
378 )
379
380 lnx_prefill = lnx[:, 0:prefill_length, :]
381 decoder_segment_ids_prefill = decoder_segment_ids[:, 0:prefill_length]
382 decoder_positions_prefill = decoder_positions[:, 0:prefill_length]
383
384 mha_prefill, _ = self._attention_as_mha_generic(
385 lnx_prefill,
386 lnx_prefill,
387 decoder_segment_ids=decoder_segment_ids_prefill,
388 inputs_positions=decoder_positions_prefill,
389 deterministic=True,
390 model_mode=MODEL_MODE_PREFILL,
391 )
392
393 self.assertTrue(
394 jax.numpy.allclose(mha_prefill, mha_full[:, :prefill_length, :], rtol=1e-02, atol=1e-02, equal_nan=False)
395 )
396
397 for idx in range(prefill_length, decode_total_length):
398 lnx_idx = lnx[:, idx : idx + 1, :]
399 decoder_positions_idx = decoder_positions[:, idx : idx + 1]
400 mha_idx, _ = self._attention_as_mha_generic(
401 lnx_idx,
402 lnx_idx,
403 inputs_positions=decoder_positions_idx,
404 deterministic=True,
405 model_mode=MODEL_MODE_AUTOREGRESSIVE,
406 )
407
408 mha_full_this_idx = mha_full[:, idx : idx + 1, :]
409 self.assertTrue(mha_full_this_idx.shape == mha_idx.shape)
410 self.assertTrue(jax.numpy.allclose(mha_full_this_idx, mha_idx, rtol=1e-02, atol=1e-02, equal_nan=False))
411
412 @pytest.mark.tpu_only
413 def test_model_mode_prefill_dtype_float32(self):

Callers

nothing calls this directly

Calls 1

get_structured_dataMethod · 0.95

Tested by

no test coverage detected