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
5 changes: 5 additions & 0 deletions build/glm53/glm53_indexer_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def head_gate_splitk(x: torch.Tensor, w: torch.Tensor, block_k: int = _BLOCK_K)
fp32, contiguous). Returns a fresh contiguous fp32 [M, N] tensor."""
M, K = x.shape
N = w.shape[1]
if K % block_k:
# The partial kernel reads w rows unmasked over [0, split*block_k): a K
# the block does not tile would drop the tail and answer quietly wrong.
raise ValueError(
f"head_gate_splitk: K={K} is not a multiple of block_k={block_k}")
Comment on lines +89 to +93
bn = _bn_for(N)
split = K // block_k
part = torch.empty(split * MAX_M, bn, device=x.device, dtype=torch.float32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def head_gate_splitk(x: torch.Tensor, w: torch.Tensor, block_k: int = _BLOCK_K)
fp32, contiguous). Returns a fresh contiguous fp32 [M, N] tensor."""
M, K = x.shape
N = w.shape[1]
if K % block_k:
# The partial kernel reads w rows unmasked over [0, split*block_k): a K
# the block does not tile would drop the tail and answer quietly wrong.
raise ValueError(
f"head_gate_splitk: K={K} is not a multiple of block_k={block_k}")
Comment on lines +89 to +93
bn = _bn_for(N)
split = K // block_k
part = torch.empty(split * MAX_M, bn, device=x.device, dtype=torch.float32)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7184,6 +7184,8 @@ def test_glm53_indexer_gate_splitk_contracts() -> None:
"applicability guards x's layout and the K match (the kernel assumes both)")
check("w.dtype == torch.float32" in kern and "w.is_contiguous()" in kern,
"applicability: fp32 contiguous weight only")
check("K % block_k" in kern and "raise ValueError" in kern,
"a non-tiling block_k fails loud (the partial kernel reads w rows unmasked)")
check("return torch.mm(x.float(), w)" in kern, "the helper falls back to the stock product")
check("[indexer-gate]" in kern and "logger.warning" in kern,
"routing is announced once per shape so an armed boot that never runs split-K is visible")
Expand Down