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
14 changes: 14 additions & 0 deletions tests/models/kimi_k3/test_kda.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from vllm.models.kimi_k3.amd.ops.third_party.kda import (
fused_recurrent_kda_packed_decode as fused_recurrent_kda_packed_decode_amd,
)
from vllm.models.kimi_k3.nvidia import kda as nvidia_kda
from vllm.models.kimi_k3.nvidia.kda import (
_flashkda_prefill,
_store_cache_checkpoints_kernel,
Expand Down Expand Up @@ -59,6 +60,19 @@
}


def test_kda_warmup_skips_missing_metadata(monkeypatch):
monkeypatch.setattr(
nvidia_kda,
"get_forward_context",
lambda: SimpleNamespace(attn_metadata={}),
)
layer = object.__new__(nvidia_kda.KimiK3DeltaAttention)
object.__setattr__(layer, "prefix", "language_model.model.layers.0.self_attn")
empty = torch.empty(0, device=DEVICE)

assert layer._forward(empty, empty, empty, empty, empty) is None


Comment on lines +63 to +75

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_kda_warmup_skips_missing_metadata(monkeypatch):
monkeypatch.setattr(
nvidia_kda,
"get_forward_context",
lambda: SimpleNamespace(attn_metadata={}),
)
layer = object.__new__(nvidia_kda.KimiK3DeltaAttention)
object.__setattr__(layer, "prefix", "language_model.model.layers.0.self_attn")
empty = torch.empty(0, device=DEVICE)
assert layer._forward(empty, empty, empty, empty, empty) is None

I don't think we need a specific unit test for this update though

def test_kda_recoverssm_config_state_layout():
vllm_config = SimpleNamespace(
model_config=SimpleNamespace(
Expand Down
4 changes: 3 additions & 1 deletion vllm/models/kimi_k3/amd/kda.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ def _forward(
return

assert isinstance(attn_metadata_raw, dict)
attn_metadata_narrowed = attn_metadata_raw[self.prefix]
attn_metadata_narrowed = attn_metadata_raw.get(self.prefix)
if attn_metadata_narrowed is None:
return
assert isinstance(attn_metadata_narrowed, GDNAttentionMetadata)
m = attn_metadata_narrowed
has_initial_state = m.has_initial_state
Expand Down
4 changes: 3 additions & 1 deletion vllm/models/kimi_k3/nvidia/kda.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ def _forward(
)

assert isinstance(attn_metadata_raw, dict)
attn_metadata_narrowed = attn_metadata_raw[self.prefix]
attn_metadata_narrowed = attn_metadata_raw.get(self.prefix)
if attn_metadata_narrowed is None:
return
assert isinstance(attn_metadata_narrowed, KimiK3KDAMetadata)
m = attn_metadata_narrowed
has_initial_state = m.has_initial_state
Expand Down
Loading