[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:
@@ -1031,19 +1031,12 @@ def test_residual_dispatch_falls_back_to_addmm(
|
|||||||
assert output is fallback
|
assert output is fallback
|
||||||
|
|
||||||
|
|
||||||
def test_fallback_preserves_default_method(monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_fallback_preserves_default_method() -> None:
|
||||||
fallback = torch.empty(2, 8)
|
x = torch.randn(2, 4)
|
||||||
monkeypatch.setattr(
|
weight = torch.randn(3, 4)
|
||||||
k3_gemm.UnquantizedLinearMethod,
|
# CPU tensors fail the runtime check, forcing the base-method fallback.
|
||||||
"apply",
|
|
||||||
lambda *args: fallback,
|
|
||||||
)
|
|
||||||
# 1-D input fails the runtime check, forcing the base-method fallback.
|
|
||||||
method = k3_gemm.KimiK3LowLatencyLinearMethod({}, {})
|
method = k3_gemm.KimiK3LowLatencyLinearMethod({}, {})
|
||||||
|
|
||||||
output = method.apply(
|
output = method.apply(SimpleNamespace(weight=weight), x)
|
||||||
SimpleNamespace(weight=torch.empty(0)),
|
|
||||||
torch.empty(0),
|
|
||||||
)
|
|
||||||
|
|
||||||
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."""
|
"""Mixin: try the precomputed plan, else defer to the base method."""
|
||||||
|
|
||||||
def __init__(self, plan: dict[int, ResolvedCall]) -> None:
|
def __init__(self, plan: dict[int, ResolvedCall]) -> None:
|
||||||
|
super().__init__()
|
||||||
self._plan = plan
|
self._plan = plan
|
||||||
|
|
||||||
def apply(
|
def apply(
|
||||||
|
|||||||
Reference in New Issue
Block a user