Skip to content

Commit e9dbd65

Browse files
ds-hwangchanglan
authored andcommitted
Fixed the timeout in decoder_test.py in CI.
GitOrigin-RevId: 488b81c
1 parent a6569cb commit e9dbd65

1 file changed

Lines changed: 58 additions & 12 deletions

File tree

axlearn/common/decoder_test.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# pylint: disable=no-self-use,too-many-branches
66
import contextlib
77
import unittest
8-
from typing import Callable, Literal, Optional
8+
from typing import Callable, Optional
99
from unittest import mock
1010

1111
import chex
@@ -473,25 +473,71 @@ def test_extend_step(
473473
StackedTransformerLayer.default_config(),
474474
RepeatedTransformerLayer.default_config(),
475475
],
476+
cross_attention_mode=["none"],
477+
prefix_length=[jnp.array([1, 1])],
478+
method=["sample_decode"],
479+
pad_token_id=[-1],
480+
)
481+
def test_decode_stack(
482+
self, stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id
483+
):
484+
self._test_decode(stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id)
485+
486+
@parameterized.product(
487+
stack_cfg=[StackedTransformerLayer.default_config()],
476488
cross_attention_mode=["none", "full", "broadcast"],
477-
num_decodes=[5],
489+
prefix_length=[jnp.array([1, 1])],
490+
method=["sample_decode"],
491+
pad_token_id=[-1],
492+
)
493+
def test_decode_xatten(
494+
self, stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id
495+
):
496+
self._test_decode(stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id)
497+
498+
@parameterized.product(
499+
stack_cfg=[StackedTransformerLayer.default_config()],
500+
cross_attention_mode=["none"],
478501
# Each is of shape [batch], representing per-example prefix lengths.
479502
prefix_length=[jnp.array([1, 1]), jnp.array([1, 3, 6])],
503+
method=["sample_decode"],
504+
pad_token_id=[-1],
505+
)
506+
def test_decode_prefix_len(
507+
self, stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id
508+
):
509+
self._test_decode(stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id)
510+
511+
@parameterized.product(
512+
stack_cfg=[StackedTransformerLayer.default_config()],
513+
cross_attention_mode=["none"],
514+
prefix_length=[jnp.array([1, 1])],
480515
method=["sample_decode", "beam_search_decode"],
516+
pad_token_id=[-1],
517+
)
518+
def test_decode_method(
519+
self, stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id
520+
):
521+
self._test_decode(stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id)
522+
523+
@parameterized.product(
524+
stack_cfg=[StackedTransformerLayer.default_config()],
525+
cross_attention_mode=["none"],
526+
prefix_length=[jnp.array([1, 1])],
527+
method=["sample_decode"],
481528
pad_token_id=[0, -1],
482529
)
483-
# pylint: disable-next=too-many-statements
484-
def test_decode(
485-
self,
486-
stack_cfg: InstantiableConfig,
487-
cross_attention_mode: Literal["none", "full", "broadcast"],
488-
num_decodes: int,
489-
prefix_length: utils.Tensor,
490-
method: Literal["sample_decode", "beam_search_decode"],
491-
pad_token_id: int,
530+
def test_decode_pad_token_id(
531+
self, stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id
492532
):
533+
self._test_decode(stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id)
534+
535+
# Running everything as product tests causes CI timeout.
536+
# pylint: disable-next=too-many-statements
537+
def _test_decode(self, stack_cfg, cross_attention_mode, prefix_length, method, pad_token_id):
493538
"""Test beam search and sample decoding from a randomly initialized decoder."""
494539
batch_size, src_len, tgt_len, vocab_size = prefix_length.shape[0], 11, 10, 6
540+
num_decodes = 5
495541
bos_id = eos_id = 1
496542
num_layers, num_heads = 3, 4
497543
hidden_dim, src_dim = 12, 10
@@ -714,7 +760,7 @@ def test_token_scores_match_between_decoded_and_prefix(self):
714760
# No need to test multiple batches
715761
batch_size = 1
716762
# Long enough target length to get enough token scores to compare.
717-
target_length = 32
763+
target_length = 16
718764
# Prefix length long enough to check that we reconstruct the prefix for the second pass
719765
# from the output sequence of the first pass.
720766
prefix_1_length = 4

0 commit comments

Comments
 (0)