[Kimi-K3][Bugfix] Fix low-latency GEMM fallback initialization (#54167)

Signed-off-by: Thien Tran <gau.nernst@yahoo.com.sg>
This commit is contained in:
Thien Tran
2026-08-28 08:32:20 +00:00
committed by GitHub
parent 9236159bb6
commit f956e1c343
2 changed files with 7 additions and 13 deletions
+6 -13
View File
@@ -1031,19 +1031,12 @@ def test_residual_dispatch_falls_back_to_addmm(
assert output is fallback
def test_fallback_preserves_default_method(monkeypatch: pytest.MonkeyPatch) -> None:
fallback = torch.empty(2, 8)
monkeypatch.setattr(
k3_gemm.UnquantizedLinearMethod,
"apply",
lambda *args: fallback,
)
# 1-D input fails the runtime check, forcing the base-method fallback.
def test_fallback_preserves_default_method() -> None:
x = torch.randn(2, 4)
weight = torch.randn(3, 4)
# CPU tensors fail the runtime check, forcing the base-method fallback.
method = k3_gemm.KimiK3LowLatencyLinearMethod({}, {})
output = method.apply(
SimpleNamespace(weight=torch.empty(0)),
torch.empty(0),
)
output = method.apply(SimpleNamespace(weight=weight), x)
assert output is fallback
torch.testing.assert_close(output, torch.nn.functional.linear(x, weight))
@@ -725,6 +725,7 @@ class _KimiK3LowLatencyApply:
"""Mixin: try the precomputed plan, else defer to the base method."""
def __init__(self, plan: dict[int, ResolvedCall]) -> None:
super().__init__()
self._plan = plan
def apply(