Skip to content

gpu: reuse the Q8Act byte owners in fit and scratch accounting - #667

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-review-bot-issue-653-gpu
Oct 22, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-review-bot-issue-653-gpu

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

한 열의 활성값 바이트 계산을 placement가 가진 계산 하나로 모았고, 그 계산이 지원하는 모든 폭에서 같은 값을 내는지 확인하는 시험을 더했습니다.

What and why

Closes #653.

act_col_bytes in crates/gpu/src/model/fit.rs held its own copy of the byte formula for one q8_1 activation column. The owner of that formula is q8_act_bytes in the placement crate. A second copy can drift from it, so act_col_bytes now calls the owner and keeps its signature and callers.

The same total was also added up by hand in three more places. They now use the existing owners:

  • crates/gpu/src/model/probe.rs: act_write_bytes takes the column bytes from act_col_bytes instead of summing the five planes again. act_planes stays, because it gives the partial plane reads of one GEMV, which is a different quantity.
  • crates/gpu/src/arch/qwen3moe/scratch.rs: ApartRows and Arena call Q8Act::device_bytes; the private act_bytes helper is removed.
  • crates/gpu/src/arch/deepseek2/scratch.rs: MoeScratch and LayerScratch call Q8Act::device_bytes; the local act closure is removed.

The new test model::fit::tests::activation_column_bytes_keep_the_placement_padding pins 11 boundary widths (for example k=255 is 0, k=256 and k=511 are 2088, k=512 is 2128) and compares act_col_bytes with q8_act_bytes(1, k) for every width from 0 to Q8ACT_MAX_K.

Release notes: internal: the q8_1 activation byte count has one owner, so the copies in fit, probe and scratch accounting cannot drift

Code shape

  • No second copy. The column formula had one extra copy in fit.rs, the five-plane sum had copies in probe.rs and in both scratch files; each now calls its owner. I searched the GPU crate's fit, probe, scratch, tensor and GEMM activation code for the same sum. LegBufs already used the owners. The plane allocations themselves and the partial plane sums (act_planes, the placement's tile scratch) answer different questions and stay.
  • Model code holds only architecture facts. The two scratch files lost code; no common owner gained a branch.
  • Dead code is gone. The act_bytes helper and the act closure are removed.
  • No silent failure. The usize conversion of the owner's result is try_from with an expect; the supported widths are unchanged.
  • Comments state what is true now. The module doc of fit.rs says the column count is delegated to the placement owner.
  • No relaxed gate. No gate, band or tolerance changes.
  • cargo fmt is clean on what I touched, dup-scan finds no candidate. cargo clippy was not run here.

Duplication found or removed (path:line): crates/gpu/src/model/fit.rs:41 (the formula), crates/gpu/src/model/probe.rs:84, crates/gpu/src/arch/qwen3moe/scratch.rs:1168 and :1997, crates/gpu/src/arch/deepseek2/scratch.rs:117 and :261.

What I ran

FAIL first. I moved the width the production call hands to the owner up by one super-block (q8_act_bytes(1, k as u64 + 256)) and ran the fit tests on a DGX Spark.

The new test fails and the existing largest-fit test passes:

cargo oxide test --arch sm_121 -- -p bloomery-gpu --release --lib model::fit::tests -- --nocapture
assertion `left == right` failed: k=0
  left: 2088
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 381 filtered out

With this commit (c7a69262, a second DGX Spark):

cargo oxide test --arch sm_121 -- -p bloomery-gpu --release --lib model::fit::tests -- --nocapture
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 382 filtered out

The mutant run was on the same change before it was rebased onto the current main; the rebase left the four changed files unchanged. The full test tier (worker t0, 107 checks, 0 red) also ran on that earlier base.

Not run: just gate-gpu-lib and the other affected just gate-gpu-* gates, which a maintainer runs.

This change touches no kernel, launch, device copy, sync or placement formula, and I made no speed claim.

What I ran into

This does not block the PR. act_planes in probe.rs still computes the per-plane sizes of one GEMV read on its own. I left it because it is a different quantity from the column total; a later change could derive it from the placement owner as well.

Hardware (if the change is for a machine)

The fit tests ran in a CUDA 13.3.1 container on DGX Spark (GB10) machines, nvidia-smi driver and CUDA lines:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: CLEAN: The shared owners preserve the existing activation byte counts.

Non-blocking

⚠ Complete the refactor verification: crates/gpu/src/model/fit.rs:42.
Provide identical base/head ptx-scan tables and the affected just gate-* commands with output, as AGENTS.md requires for this refactor.
The reported fit tests cover the adapter; recording the remaining evidence now verifies the affected paths before merge.

Checked

Duplicates: 1 new item checked, the test; no duplicate contract found. Dryer reported 0 pairs.
Complexity: crapper flagged no functions; no production branches added.
Silent failure: 1 conversion site followed; failure produces a named panic, with no fallback value.
Tests: an independent arithmetic check matched both formulas for every k from 0 through 20,480 and all 11 pins. Changing fit.rs:42 to pass k + 256 fails the new test's k=0 assertion.
Bounds: invalid Q8Act allocation shapes are rejected; partial-width rounding and multiple-column totals retain their previous behavior.
Gates: no existing gate, band, tolerance or case changed. The PR supplies FAIL-first output for the new test.
Escape catalog: none of C1–C4 matched.

Notes

No Rust/GPU tests or PTX scans were run during this review. The PR lacks a complete GPU gate evidence set.

Card check: needs-gpu. This pull request changes crates/gpu/src/arch/deepseek2/scratch.rs, crates/gpu/src/arch/qwen3moe/scratch.rs, crates/gpu/src/model/fit.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 1c9d241 into midagedev:main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gpu fit: Q8Act byte arithmetic duplicates the placement owner

1 participant