Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions extension/llm/export/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ def __init__(
{1: torch.export.Dim("token_dim", max=self.max_seq_len - 1)},
)
else:
# Two input arguments: tokens and input_pos but input_pos is static shape
# Two input arguments: tokens and input_pos but input_pos is static shape.

# A runtime assertion is added by torch.ops.llama.update_cache requires that
# L['tokens'].size()[1] + input_pos[0].item() < self.max_seq_len
# This consttaint L['tokens'].size()[1] to be elf.max_seq_len-1
# run with TORCH_LOGS=+dynamic for details
self.dynamic_shapes = (
{1: torch.export.Dim("token_dim", max=self.max_seq_len)},
{1: torch.export.Dim("token_dim", max=self.max_seq_len - 1)},
{"input_pos": {0: 1}},
)

Expand Down
2 changes: 1 addition & 1 deletion extension/llm/export/test/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_get_dynamic_shape_with_dynamic_shape_enabled_with_kv_cache(self) -> Non
# Check first element (tokens dimension)
self.assertIsInstance(result[0], dict)
self.assertIn(1, result[0])
self.assertEqual(result[0][1].max, self.max_seq_len)
self.assertEqual(result[0][1].max, self.max_seq_len - 1)

# Check second element (input_pos dimension)
self.assertIsInstance(result[1], dict)
Expand Down
Loading