Repository navigation
fix(metal): subtract delta tap distance before reducing the ring - #1098
Conversation
Avoid overflowing the position word when looking up ring predecessors near u32::MAX. Keep the shared oracle on the same guarded subtraction and pin the original expression with a boundary mutant. Fixes midagedev#795
There was a problem hiding this comment.
Verdict: CLEAN: Guarded subtraction avoids ring-slot overflow, and the extended gate checks positions near the u32 limit.
Checked
Duplicates: no new functions, types or constants; the added mutant has a unique name. Dryer reported no pairs.
Complexity: diagnostics report delta_ring rising from 17 to 24 through a boundary-case loop and comparisons of four outputs.
Silent failure: the shader and oracle zero-return guards supply convolution padding for predecessors before the sequence starts.
Tests: the added loop compares g, partials, state and ring bits at three upper-boundary positions against ring-equivalent small positions. The new mutant restores the addition at delta.metal:168; the PR reports rejection on g[0].
Gates: no thresholds, tolerances, pins or cases removed or relaxed. The PR supplies an oracle overflow before the fix and mutant-failure output afterward.
Performance: the ring read removes one unsigned addition. Launches, copies and floating-point order are unchanged in the diff.
Boundary checks: sequence-start subtraction is guarded; geometry requires 11 ring rows; chunk-position overflow is refused.
Escape catalog: no C1–C4 patterns matched. No ledger lessons were in force.
Notes
Metal gates were not run locally. The PR supplies Apple Silicon delta_ring and delta_rows passes and rejection of delta_ring_overflow.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Metal delta 커널과 공유 oracle의 ring slot 계산에서 u32 덧셈 넘침을 없애는 버그 수정입니다.
Fixes #795.
What and why
The Metal delta tap computed its ring slot as
(pos0 + ring_rows - back) % ring_rows. Oncepos0is withinring_rowsofu32::MAX, the addition wraps and the kernel reads the wrong slot (and the shared oracle panics with an overflow in debug builds). Thepos0 < backguard already runs first, so the subtraction cannot go negative and the addition is not needed. The fix is(pos0 - back) % ring_rowsincrates/metal/kernels/delta.metal(tap_x) and incrates/metal/src/bin/shared/oracle_delta.rs(tap). Launches, memory accesses and float operation order are unchanged.The
delta_ringgate clause now also checks the last safe position, the first overflowing position andu32::MAXagainst their ring-equivalent small positions, comparingg, partials, state and ring bits. A new mutant,delta_ring_overflow, restores the old expression and must be rejected by that clause.Release notes: Fixed: Metal delta layers read the correct ring slot at positions near the u32 limit.
Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none. The shader and the oracle are separate-language owners of the same slot rule and both changed.What I ran
Base
e9f238b0d53e12f8a5e75d89450b59fd0c6a2b11(upstream/main), PR head93be74347a3a0f6812ee5cb1749129677dac7d36. The gate needs no model file: the delta shape uses drawn parameters.Before the fix, the new boundary check makes the oracle overflow:
On the PR head:
Lint ratchet on the workspace (
cargo clippy --workspace --all-targetswith the repository's feature set):Hardware (if the change is for a machine)
Apple silicon Mac (
Mac17,2), macOS 27.0.1, Metal shaders compiled from source at run time (gemm: architecture=applegpu_g17g metal4=true matrix-units=true engine-path=tensor).AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.