Skip to content

fix(glm53): split-K head gate 가 block_k 로 K 를 못 나누면 조용한 오답 대신 실패 - #233

Merged
choiceoh merged 1 commit into
mainfrom
fix/glm53-indexer-gate-blockk-guard
Sep 2, 2026
Merged

fix(glm53): split-K head gate 가 block_k 로 K 를 못 나누면 조용한 오답 대신 실패#233
choiceoh merged 1 commit into
mainfrom
fix/glm53-indexer-gate-blockk-guard

Conversation

@choiceoh

@choiceoh choiceoh commented Sep 2, 2026

Copy link
Copy Markdown
Owner

무엇

#231 리뷰의 잔여 결함 1건. head_gate_splitk(x, w, block_k=…) 의 노출된 block_k 인자가 K 를 나누지 않으면, 부분합 커널이 w 행을 [0, split*block_k) 에 걸쳐 마스크 없이 읽는 구조라 꼬리 행이 조용히 빠진 채 곱이 나왔다. 현재 호출부는 전부 디폴트(128 — K=4096 을 나눔)라 오늘 위험은 없지만, v1 의 교훈(조용한 형상 미스 = 죽은 노브) 그대로의 지뢰라 진입에서 큰 소리로 죽인다.

변경 (3파일, +12)

  • head_gate_splitk: K % block_kValueError (overlay + build 쌍둥이 동기화)
  • tests/test_logic.py: 계약 검사 1건 추가 — 커널에 가드가 있는 문자열 계약

게이트

  • tests/test_logic.py 2665 검사 전부 OK (기존 2664 + 신규 1)
  • 기본 경로 미변경(디폴트 block_k 는 항상 K 를 나눔) → srv4 오프라인 재측정 불필요, EXP-9 수치(~1.2%) 무영향

Note

Low Risk
Defensive validation on an optional split-K fast path; default callers are unaffected and invalid configurations fail fast instead of returning wrong numerics.

Overview
head_gate_splitk now raises ValueError when inner dimension K is not divisible by block_k, instead of producing silently wrong matmul results. The split-K partial Triton kernel loads weight rows over [0, split·block_k) without masking the tail; a mismatched block_k would drop trailing K rows from the product.

The guard is applied in both build/glm53/glm53_indexer_gate.py and the overlay twin so they stay in sync. tests/test_logic.py adds a string contract check that the kernel source includes K % block_k and raise ValueError.

Production routing via head_gate still uses the default block_k=128, which tiles K=4096; behavior on the supported decode path is unchanged.

Reviewed by Cursor Bugbot for commit c52ae93. Bugbot is set up for automated code reviews on this repo. Configure here.

부분합 커널은 w 행을 [0, split*block_k) 에 걸쳐 마스크 없이 읽는다 —
block_k 가 K 를 나누지 않으면 꼬리 행이 조용히 빠진 채 곱이 나온다
(v1 의 교훈: 조용한 형상 미스는 죽은 노브). head_gate_splitk 진입에서
큰 소리로 죽인다. 계약 검사 1건 추가 (2664 -> 2665).
Copilot AI lite review requested due to automatic review settings September 2, 2026 13:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T13:38:33.095724Z c52ae93 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@choiceoh
choiceoh merged commit 175b3d0 into main Sep 2, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new guard still allows block_k<=0 to raise ZeroDivisionError / produce invalid launch shapes instead of a clear ValueError, so input validation needs to be completed to ensure consistent fail-fast behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens the glm53 split-K head-gate fast path by adding a fail-fast guard when block_k does not tile K, preventing silently wrong matmul results due to unmasked weight-row reads in the partial kernel.

Changes:

  • Add ValueError guard in head_gate_splitk when K % block_k != 0 (kept in sync across overlay + build twin).
  • Add a contract test asserting the kernel source includes the new loud-failure guard.
File summaries
File Description
overlay/modules/glm53_indexer_gate_splitk/glm53_indexer_gate.py Adds a tiling validation guard for block_k in head_gate_splitk.
build/glm53/glm53_indexer_gate.py Mirrors the same tiling guard in the build twin to keep artifacts in sync.
tests/test_logic.py Adds a string-contract assertion that the guard exists in the kernel source.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +89 to +93
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
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}")

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved. Cursor Bugbot completed with no findings that need human review, and no approval policy requires extra review. No reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants