Repository navigation
gguf: refuse F8 rows whose scaled values are not finite - #710
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: F8 overflow is rejected by the shared validator before any destination write.
Non-blocking
⚠ Debuggability: crates/gguf/src/quant.rs:329. The fix adds no retained probe, stats() output or diagnostic record, and the PR body gives no reason for omitting that layer. Explain why the named byte/index error and reproduction command provide sufficient diagnostics.
Checked
Duplicates: 3 new items checked, including the error variant; HF normalization now reuses the shared F8 validator.
Complexity: the validator scans for the first invalid value; HF normalization loses its chunk loop and scratch buffer.
Silent failure: 2 error paths followed. Row decoding and HF normalization propagate named errors before exposing decoded or normalized output. NVFP4, MXFP8 and FP8_B128 already reject overflowing products.
Tests: static mutation check of crates/gguf/src/quant.rs:994: restoring the NaN-only predicate fails the overflow expect_err assertion. Moving validation after writes at crates/gguf/src/quant.rs:1021 fails the destination-bit assertion.
Adversarial checks: late overflow cannot partially write; short input returns ShortSrc; trailing bytes outside the requested span are excluded. A NaN byte remains invalid at zero scale.
Gates: no pin, threshold or test clause moved. The PR supplies FAIL-first evidence for finite-scale overflow.
Escape catalog: no pattern matched.
Notes
The supplied test runs name f0705c9; the reviewed head is 2d64226. Tests were not rerun during review or validation.
🔨 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. |
F8 행 디코더가 f32 범위를 넘는 값을 무한대로 내보내던 결함을 고쳐, 쓰기 전에 이름 있는 오류로 거부합니다.
Part of #565. Tracked in #699.
What and why
F8 row decoding could return
Okwith infinite values.E4m3Rows::newmultiplies each E4M3 byte by the tensor scale when it builds its table, and a normal byte times a large finite scale can leave the f32 range.decoderefused only E4M3's NaN bytes, so the infinity went into the output. The per-layer embedding rows read throughPleRows::F8use the same decoder, so invalid values could reach inference. The decoder came in with #490.E4m3Rows::checknow reports the first byte whose scaled value is not finite, by index, before anything is written. A NaN byte keepsE4m3Nan. A non-finite product, or a non-finite scale, is the newQuantError::E4m3NonFinite.decodecallscheck, and a refused span leaves the output buffer bit for bit as it was. The arithmetic of finite values and the write order are unchanged.The HF FP8 tensor normalization had its own copy of this check: it decoded the tensor 256 values at a time into a scratch array and scanned the result. It now calls
E4m3Rows::checkon the bytes once, so the decoder owns the rule and no scratch array is needed. The NVFP4, MXFP8 and FP8_B128 range checks already refuse the same class of input and are untouched.Release notes: Fixed: F8 rows whose scaled values overflow f32 are refused with a named error instead of decoding to infinity.
Code shape
E4m3Rows::checkis the one owner. The HF normalization check that duplicated it is gone.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.cargo fmt --allandgit diff --checkare clean; clippy has not been run on this head.Duplication found or removed (
path:line), or "none": the per-chunk decode and finiteness scan incrates/hf/src/modelopt.rs(plain) is replaced by the sharedE4m3Rows::check.What I ran
The tested head is
f0705c9bae9e100c1271d411b84e87a6f41ed3ab, based onb9dfc4a748ea7d7b713ec831100761ef047b5472.cargo test -p bloomery-gguf --lib quant::tests::e4m3_rows_refuse_nonfinite_products_before_writing -- --exact --nocapture. With scalef32::MAXand byte0x40,expect_errpanics becausedecodereturnedOk:test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 50 filtered out; finished in 0.00s, exit 101.RUSTFLAGS='-C target-cpu=native' cargo test -p bloomery-gguf --lib quant::tests:::test result: ok. 25 passed; 0 failed; 0 ignored; 0 measured; 26 filtered out; finished in 0.51s. It includes the new test, the existing all-byte oracle and the NVFP4, MXFP8 and FP8_B128 range tests.RUSTFLAGS='-C target-cpu=native' cargo test -p bloomery-hf --lib modelopt::tests::the_table_writes_each_format_as_its_type -- --exact:test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 85 filtered out; finished in 0.00s. The NaN byte, non-finite scale and finite-scale overflow refusals still hold through the shared check.cargo check --workspace --all-targetswith the feature listjust checkuses exited 0 (Finisheddevprofile in 27.65s).nvidia-smireportedNVIDIA GeForce RTX 5090, 595.99.02, 12.0.The new test covers four scales (
f32::MAX, its negative and their halves) against positive and negative bytes. A product off32::MAXtimes 1 or -1 is accepted, times 2 is refused, and half the scale times 2 is accepted. It also checks a NaN byte after a valid span, signed zero, an infinite and a NaN scale, and that the buffer keeps its original bits when a span is refused. Restoring the NaN-only check makesexpect_errfail, and moving the write before the check makes the bit comparison fail.Not run: clippy,
t0and the full gate set. No CUDA kernel or device arithmetic changed, so I ran no GPU gate and no timing comparison.Reproduction
The first command is the new regression test.
What I ran into
This does not block the PR: I found nothing else while preparing this change.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.