-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[None][fix] share Kimi auxiliary streams #18728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+106
−30
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/unittest/_torch/modeling/test_kimi_linear_modeling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import pytest | ||
| import torch | ||
| from torch import nn | ||
|
|
||
| from tensorrt_llm._torch.configs.kimi_linear import KimiLinearConfig | ||
| from tensorrt_llm._torch.model_config import ModelConfig | ||
| from tensorrt_llm._torch.models import modeling_kimi_linear | ||
| from tensorrt_llm._torch.utils import AuxStreamType | ||
|
|
||
| pytestmark = pytest.mark.cpu_only | ||
|
|
||
|
|
||
| def test_kimi_linear_model_builds_shared_aux_stream_registry( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| streams = [object() for _ in range(4)] | ||
| stream_iter = iter(streams) | ||
| layer_aux_stream_dicts = [] | ||
|
|
||
| class _FakeDecoderLayer(nn.Module): | ||
| def __init__(self, _model_config, _config, _layer_idx, aux_stream_dict) -> None: | ||
| super().__init__() | ||
| layer_aux_stream_dicts.append(aux_stream_dict) | ||
|
|
||
| monkeypatch.setattr(torch.cuda, "Stream", lambda: next(stream_iter)) | ||
| monkeypatch.setattr(modeling_kimi_linear, "KimiLinearDecoderLayer", _FakeDecoderLayer) | ||
|
|
||
| config = KimiLinearConfig( | ||
| vocab_size=16, | ||
| hidden_size=8, | ||
| num_hidden_layers=3, | ||
| num_attention_heads=2, | ||
| rms_norm_eps=1e-5, | ||
| attn_res_block_size=1, | ||
| linear_attn_config={"kda_layers": [1, 3], "full_attn_layers": [2]}, | ||
| ) | ||
| model = modeling_kimi_linear.KimiLinearModel(ModelConfig(pretrained_config=config)) | ||
|
|
||
| aux_stream_dict = model.aux_stream_dict | ||
| assert set(aux_stream_dict) == { | ||
| AuxStreamType.Attention, | ||
| AuxStreamType.MoeShared, | ||
| AuxStreamType.MoeChunkingOverlap, | ||
| AuxStreamType.MoeBalancer, | ||
| AuxStreamType.MoeOutputMemset, | ||
| } | ||
| assert aux_stream_dict[AuxStreamType.Attention] is streams[0] | ||
| assert aux_stream_dict[AuxStreamType.MoeShared] is streams[0] | ||
| assert aux_stream_dict[AuxStreamType.MoeChunkingOverlap] is streams[1] | ||
| assert aux_stream_dict[AuxStreamType.MoeBalancer] is streams[2] | ||
| assert aux_stream_dict[AuxStreamType.MoeOutputMemset] is streams[3] | ||
| assert len(layer_aux_stream_dicts) == config.num_hidden_layers | ||
| assert all(stream_dict is aux_stream_dict for stream_dict in layer_aux_stream_dicts) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.