probe(megakernel): MK-KDA 11차 — 배리어 17µs 카운터화 기각 확증 + 스탬프 진단 도구 - #240
probe(megakernel): MK-KDA 11차 — 배리어 17µs 카운터화 기각 확증 + 스탬프 진단 도구#240choiceoh wants to merge 1 commit into
Conversation
10차 결산이 커널 내에 남긴 마지막 항목(배리어 대기 ~17µs)을 세 판 A/B 로 닫는다
(srv4, srv2 와 같은 조건의 한 세션 안):
- 기준선(배리어 4개) 172.8 µs / 전체 카운터 판(타일·헤드별 readiness,
norm|o_proj 만 배리어) 176.3 / 부분 판(conv 우선 + delta 진입만 카운터) 173.9.
- 기전: 배리어 대기 med(6.1/4.2/7.4)의 대부분은 임계 경로 밖 흡수 — 놀던 블록의
자리였고, 카운터화는 대기를 스핀으로 옮기기만 한다. p0 뒤 체인은 진짜 데이터
의존성으로 직렬(gates→마지막 타일, delta→헤드의 conv+gates, o_proj→전 헤드).
conv 조기 시작은 p0 의 W4 스트림과 충돌(+4µs), delta 조기 시작의 상태 쓰기
홍수는 뒤 배리어 대기를 2.0→5.9 로.
- VLLM_GLM53_MK_KSR_IN 스윕: r=1 206.7 만 확실히 나쁘고 r∈{3,4,6} 는 ±4µs
노이즈 밴드 — 모델의 r=4 유지.
판정: 기각, .cu 는 HEAD 그대로. 10차의 "남은 것은 커널 밖이다" 확증.
- probes/diag_kda_stamps.py: 8차·10차가 스크래치로만 쓰던 KDA 스탬프 리더를
랜딩(VLLM_GLM53_MK_PHASE_TS=1 + read_kda_ts).
- README: 10차에서 기각된 prefetch.global.L2 예열이 살아있는 것처럼 읽히던
stale 문장 정정 + 배리어가 레버 아님을 명시.
- 전체 벤치 VERDICT PASS(환경 안정 후 MHC 25.6/42.0, KDA 304~306 — srv2 값과
일치; 워커 공존 중 OOM/드리프트 주의는 원장에 기록).
Co-Authored-By: ZCode <noreply@zcode.ai>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_535ceaf2-a860-4663-8bdd-58b14c30bda6) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟡 Changes recommended
The new diag_kda_stamps.py probe has a couple of correctness/robustness issues (misleading docstring, potential crash without MK_PHASE_TS, and miscomputed waits if stamps are incomplete) plus a typo in MEASUREMENTS.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR closes out the MK‑KDA “~17 µs barrier wait” investigation in writing (confirming counter-based replacements were neutral-to-worse and reverted), and adds an offline stamp-diagnosis probe to read/print KDA phase timestamps.
Changes:
- Add
probes/diag_kda_stamps.pyto run the KDA fixture and report per-phase stamps, barrier waits, and span fromread_kda_ts(). - Update
overlay/modules/glm53_megakernel/README.mdto clarify barrier waits are not a remaining tuning lever and point readers to the new probe and 11차 measurements. - Extend
MEASUREMENTS.mdwith the 11차 write-up and environment notes (srv4 drift/OOM caveats).
File summaries
| File | Description |
|---|---|
| probes/diag_kda_stamps.py | New offline diagnostic probe that reads/prints MK‑KDA stamp data and barrier waits. |
| overlay/modules/glm53_megakernel/README.md | Documentation updates reflecting the 11차 conclusion and pointing to the probe/measurements. |
| MEASUREMENTS.md | Adds the 11차 ledger entry with A/B results and measurement-environment cautions. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| kda = ext.read_kda_ts() # [NB*16], cleared on read | ||
|
|
||
| def s(slot): | ||
| return [kda[b * 16 + slot] for b in range(NB) if kda[b * 16 + slot]] |
| for bar, sin, sout in (("bar1", 1, 2), ("bar2", 5, 6), | ||
| ("bar3", 7, 8), ("bar4", 9, 10)): | ||
| ent, out = s(sin), s(sout) | ||
| waits = [(o - e) / 1e3 for e, o in zip(ent, out) if e and o] | ||
| if waits: | ||
| print(f" {bar} wait: med {_med(waits):6.1f} max {max(waits):6.1f}") |
|
|
||
| 구현은 동작했다(교착 0, 수치 동일급, 그래프 재현 정확성은 consume-카운터 프로토콜 — 마지막 소비자가 도달 카운터를 지나간 뒤 초과화). **먹히지 않은 기전 넷**: (1) 배리어 대기 med 의 대부분은 **임계 경로 밖 흡수** — 놀고 있던 블록이 다른 블록의 임계 경로(p0 마지막 타일, delta 토큰 사슬)가 끝나기를 기다리던 자리였고, 카운터화는 그 대기를 스핀으로 옮기기만 한다. 배리어의 진짜 임계 비용은 producing phase 의 도착 스프레드 ~2-3 µs 뿐. (2) p0 뒤 체인은 **진짜 데이터 의존성으로 직렬** — gates 는 in_proj 마지막 타일(48-50)을, delta 는 자기 헤드의 conv+gates 를, o_proj 는 전 헤드의 norm 을 기다린다. (3) conv 조기 시작은 p0 의 W4 스트림과 DRAM 에서 충돌해 conv 자체 +4 µs. (4) delta 조기 시작의 상태 쓰기 홍수(8 MB/레이어)가 꼬리와 겹쳐 뒤 배리어 대기 2.0→5.9. | ||
|
|
||
| `VLLM_GLM53_MK_KSR_IN` 스윕(같은 조건): r=1 206.7 / r=3 177.7 / r=4(모델) 175.7~182 / r=6 175.3 — r=1 만 확실히 나쁘고 나머지는 ±4 µs 노이즈 밴트. 모델의 r=4 유지, 채택 없음. |
| span. 11차: phases 1-3 hand work to their consumers through the | ||
| g_mk_kda_* readiness counters, so a phase's end stamp includes its own | ||
| producers' waits and the old bar1/bar2/bar3 waits no longer exist. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60ea58dc79
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| torch.cuda.init() | ||
| ext = mk._build() |
There was a problem hiding this comment.
Enable phase stamps before compiling
When this probe is launched using the documented command in a clean scratch container, it never sets VLLM_GLM53_MK_PHASE_TS=1 before calling _build(). Consequently the extension is compiled without timestamp support, read_kda_ts() returns an empty vector, and the first s(0) call raises IndexError instead of producing diagnostics. Set the environment variable before importing/building the extension, or fail early with an actionable message.
Useful? React with 👍 / 👎.
|
|
||
| import torch # noqa: E402 | ||
|
|
||
| NB = 48 # grid cap; the probe refuses anything else |
There was a problem hiding this comment.
Derive the stamp block count from the compiled grid
When VLLM_GLM53_MK_GRID is set below 48 for a grid-size experiment, _build() compiles MK_GRID_CAP to that smaller value and read_kda_ts() returns only MK_GRID_CAP * 16 entries, but this probe still indexes 48 blocks and raises IndexError. The comment says non-48 geometry is refused, yet the only assertion checks the device's SM count; either reject a mismatched compiled grid explicitly or derive the block count from the returned stamp buffer.
Useful? React with 👍 / 👎.
요약
10차 결산(#230)이 커널 내에 남겨둔 마지막 항목 — KDA 배리어 대기 ~17µs — 을 실험으로 닫았다. 결론: 기각. 배리어 대기는 비용이 아니라 일이 없는 블록의 자리였다.
.cu는 HEAD 그대로(코드 변경 없음), 이 PR 은 기각 원장 + 진단 도구 + README 정정이다.세 판 A/B (srv4, 한 세션 안, 스탬프 스팬 med)
카운터 프로토콜은 동작했다(교착 0, 수치 동일급, consume-카운터로 그래프 재현 정확성 유지 — 마지막 소비자가 스핀을 지나간 뒤 초과화).
안 먹힌 기전 넷
VLLM_GLM53_MK_KSR_IN스윕: r=1 206.7 만 확실히 나쁘고 r∈{3,4,6} 는 ±4µs 노이즈 밴드 → 모델 r=4 유지.변화분
probes/diag_kda_stamps.py(신규): 8차·10차가 스크래치로만 쓰던 KDA 스탬프 리더 랜딩.README.md: 10차에서 기각된prefetch.global.L2예열이 살아있는 것처럼 읽히던 stale 문장 정정 + "배리어는 레버 아님" 명시.MEASUREMENTS.md11차: 위 표와 기전, srv4 측정 환경 주의(워커 공존 OOM·드리프트).검증
tests/test_logic.py41,219 checks OK.10차 결산의 "남은 것은 커널 밖이다"(서빙 무장 브래킷, MHC 꼬리→다음 GEMM 체인 융합)가 직접 실험으로 확증됐다.
🤖 Generated with ZCode
Note
Low Risk
Documentation and an offline srv4 probe only; no serving kernel or runtime path changes. Risk is limited to misleading ops guidance if the new ledger is wrong, not production behavior.
Overview
Closes the MK-KDA “~17 µs barrier” experiment in writing: producer–consumer counter replacements for bar1/bar2/bar3 were reverted (span med ~172.8 µs baseline vs 176.3 / 173.9 on counter variants). The ledger records why—most median barrier wait is idle blocks off the critical path, not removable sync cost—and reaffirms no
.cuchange in this PR.Adds
probes/diag_kda_stamps.pyto run the acc=3 fixture withVLLM_GLM53_MK_PHASE_TS=1,drain=True, and print per-phase stamps, barrier waits, and span viaread_kda_ts()(replaces scratch-only readers from earlier rounds).Updates
glm53_megakernel/README.md: barrier waits are not a tuning lever; corrects stale text that idle blocks prefetch o_proj during delta (10차 rejected); points phase timing to the new probe and MEASUREMENTS.md 11차.Reviewed by Cursor Bugbot for commit 60ea58d. Bugbot is set up for automated code reviews on this repo. Configure here.