Skip to content

gpu: a row table's rows go to the card as read and decode there, in one owner for every row format - #1068

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-row-upload
Nov 1, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-row-upload

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8의 행 테이블(PLE) 값을 읽은 그대로 카드로 올려 카드에서 풀고, 그 일을 모든 행 형식이 쓰는 공용 owner 하나로 모았습니다.

What and why

The Qwen3.8 per-layer embedding row table came in three formats (IQ4_NL, F8 E4M3 rows, NVFP4 rows), and body38.rs decoded each one on the host into f32 before uploading it. This PR adds crates/gpu/src/rows.rs, one owner that uploads the bytes as read and decodes them on the card with one kernel per layout. It also moves the read-ahead buffer handling (PleRead, now RowRead) there, and moves the NVFP4 planes kernel out of ple.rs. PleHost in body38.rs keeps only row naming, hashing and history. The verify path still decodes on the host because its staging receives values.

A second commit makes the helper that reads a large row range split the read over the worker pool's threads (threads::helper::Parts, HelperOptions::spread). The part count comes from threads::report(), so the constant PLE_WORKERS = 12 in body38.rs and the fixed single worker in the DeepSeek V4.1 engram reader are gone. The helper record now carries parts= and parts_from=, and bloomery-serve-qwen38 prints it at load.

Undefined input is refused by name before the upload (an E4M3 NaN scale byte, a scale that leaves f32's range, an F8 NaN byte, a planes span larger than staging), and the output is left unchanged.

The speed result is no change: IQ4_NL and NVFP4 upload 1,440 B per position instead of 10,240 B of f32, but at these batch sizes the upload is not the limit, and every cell below is within run-to-run noise and its sample ranges overlap. The PR makes no speed claim.

Release notes: Under the hood: PLE row tables decode on the card through one shared owner, and the row-reading helper splits large reads over the worker pool's threads.

Code shape

  • No second copy. The decode core is shared: cores::half_to_f32, iq::iq4_word, cores::table16_word, mxfp4::ue4m3_half and q8f32::Mxfp8Bytes::value are reused, and the host side calls the gguf decoders (dequant_row, E4m3Rows, Nvfp4Rows). The helper part count has one source, threads::report().
  • Model code holds only architecture facts. rows.rs is format code and has no model branch. body38.rs lost its decode code.
  • Dead code is gone. The old NVFP4 planes kernel in ple.rs, PleRead, PLE_WORKERS and the fixed worker count in gpu-deepseek41/src/chain/glue.rs are removed.
  • No silent failure. Undefined spans are refused by name before the upload (gate_ple rows clause, four refusals).
  • Comments state what is true now. No dates, issue numbers or how a bug was found.
  • No relaxed gate. The tools/unsafe-ratchet.txt gpu count moves 2879 to 2891 with a PIN line, because code moved in and new code arrived, not because old code was relaxed. The ple_rows_nvfp4 rows in the PTX shape tables become the four new rows_* entries.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": the NVFP4 planes kernel in crates/gpu/src/ple.rs and PleRead in crates/gpu/src/arch/qwen3moe/body38.rs moved into crates/gpu/src/rows.rs, and the old copies are deleted. The DeepSeek V4.1 engram card decode kernels (ds41_glue_engram_rows_q3k, _iq4nl, _q5k in crates/gpu-deepseek41/src/chain/glue.rs) do the same kind of work and are left as they are.

What I ran

Card: NVIDIA GB10. Base 996b23be30a2cd4332906bbd18af9c03d75e7452, head b15f054ef56418bbc18d9807f5068c040bdd9cc7.

Gates on the card:

BLOOMERY_BOX_LOCAL=1 just gate-gpu-ple
BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-e2e
BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-nvfp4
BLOOMERY_BOX_LOCAL=1 just gate-gpu-ds41-step
BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen38-serve
  • gate-gpu-ple: gate_ple: 36 clauses, 0 failed. The new rows clause compares all four layouts (NVFP4 planes, NVFP4 rows, IQ4_NL rows, F8 rows) with the host decode bit for bit at tensor scale 1e0 and 3.3242362e-5, over 10485760 values at offset 7680 (bits=true PASS for all eight). The four refusals keep the output (e_kept=true PASS), and the four new kernels have ld_local=0 st_local=0.
  • gate-gpu-qwen4exp-e2e: gate_qwen4exp_e2e ran 449 s (exit 0). Eager against graph, pass against step and the ubatch path agree on logits bit for bit.
  • gate-gpu-qwen4exp-nvfp4: gate_qwen4exp_nvfp4 ran 107 s (exit 0) on the real NVFP4 folder.
  • gate-gpu-ds41-step: PASSED: gate_deepseek41_step --feed.
  • gate-gpu-qwen38-serve: lookup_off_1_moves_slots_with_its_cache: PASS and the three matching lookup_off_2, lookup_lookup_1 and lookup_lookup_2 checks.

Host tests that cover the changed code: bloomery-threads (--test pool --test helper, including a_parted_helper_is_listed_with_the_pools_threads), the gguf nvfp4 and e4m3 tests (9 passed) and arch::qwen3moe::body38::tests (7 passed).

The user-facing binary, built with the release feature set and run on the three Qwen3.8 files, with --ctx-size 16896:

cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features "$F" --release --bin bloomery-serve
./target/release/bloomery-serve -m <file> --host 127.0.0.1 --port 18741 --ctx-size 16896
  • UD-Q4_K_XL GGUF: loaded in 39.4 s. The short request generated ' Paris. The capital of Germany is Berlin. ...' (24 tokens) and the long request (prompt_n 4701) generated 48 tokens.
  • NVFP4: loaded in 17.0 s. Short and long requests generated normally.
  • FP4-Local: loaded in 10.4 s. Short and long requests generated normally.

The NVFP4 and FP4-Local loads print helper name=engram-prefetch asked=float pinned=float cpus=20 parts=20 parts_from=pool.

Speed, base against head, from one A/B on the GB10 with a 4,096-id prompt, 128 generated tokens and three rounds per side, on four arms (fp4l-off, fp4l-mtp, nvfp4-off, q4-off). The greedy output is identical between base and head (24 requests, 3,072 tokens, no first difference). No cell moved beyond run-to-run noise.

Metric Base Head Difference Ranges overlap
fp4l-off code-fn decode tok/s 31.379 31.560 +0.58% yes
fp4l-off code-fn prefill tok/s 2878.6 2867.0 -0.41% yes
fp4l-mtp prose-en decode tok/s 40.70 41.25 +1.35% yes
nvfp4-off code-fn decode tok/s 22.807 22.841 +0.15% yes
nvfp4-off code-fn prefill tok/s 2568.9 2573.8 +0.19% yes
q4-off code-fn decode tok/s 30.741 30.715 -0.08% yes
q4-off code-fn prefill tok/s 1660.7 1659.2 -0.09% yes

AI help

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

…threads on this machine

The PLE reader's prefetch helper split a ubatch's rows over a fixed twelve
threads (PLE_WORKERS), a count chosen on one machine. A floating helper now
reads over as many threads as the worker pool has participants here
(threads::helper::Parts::pool: the cores the process's cpu mask leaves, or
BLOOMERY_THREADS), and one that the pool's shape cannot be read for reads
alone. HelperOptions::spread is the one constructor: a pinned helper still
reads every token alone, and a token too small to split stays on the helper.
DeepSeek V4.1's engram reader takes the same rule in place of its own one.

Every helper is listed with its part count and where it comes from, and the
helper record prints both (parts=, parts_from=); bloomery-serve-qwen38 prints
its helpers at load beside the nvtier record.
…ne owner for every row format

A Qwen3.8 PLE fill decoded its rows on the step thread and copied the
values (10,240 B a position) to the card, except NVFP4 rows read from the
NVMe tier in two planes, which the card decoded. The decode and the reader
now sit in one format-neutral owner, gpu::rows:

- RowFormat names a row's encoding (IQ4_NL blocks; bloomery's F8 rows and
  NVFP4 rows at the table's scale) and how a read lays it (whole rows, or
  NVFP4 code and scale planes). Its host decode is the gguf decoders'.
- RowKernels::enqueue copies a read's bytes to the card as they are (1,440
  B a position for IQ4_NL and NVFP4) and decodes them with one launch for
  each layout: NVFP4 planes (moved from ple.rs), NVFP4 rows, IQ4_NL and
  F8. Each value is the host decode's bit for bit; the host refuses an
  undefined span by name before anything is enqueued. Rows past the
  staging (F8 rows, a byte a value) go up in parts, in order.
- RowRead, the NVMe tier's reader, holds a prompt call's reads ahead keyed
  by position, count and row ids and drains a stale one, as body38's
  PleRead did.

PleHost names the rows and lands them through the owner on every path that
copied values: the step, a pass, a ubatch (late or not) and a slot's rows.
On the host it gathers the rows from the mapping instead of decoding them.
A verify's rows, which its staging takes as values, decode on the host.
gate_ple's rows clause runs every layout against the host decode, from a
position past the first and through a staging that takes F8 rows in parts,
and the refusals of each.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 1, 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: No proven must-fix defect remains in the reviewed findings.

Non-blocking

⚠ Supply the dispatch proof: crates/gpu/src/rows.rs:374.
The one-token F8 arena allocates 2,560 / 16 × 9 = 1,440 B for 2,560 input bytes. The loop performs two H2D calls and two decode launches: one more H2D call and two more launches per token than the base [derived].
Attach the base/head PTX scan comparison, new clauses' FAIL-first results, and same-lease A/B commands with output to complete the dispatch proof.

Checked

Duplicates: dryer reported 0 candidate pairs in the crates it scanned; GPU and GPU-gate crates were outside that scan.

Complexity: enqueue is new at 27, with span validation followed by chunk dispatch. rows_clauses 13→22 adds format/refusal cases. run 20→21 adds entries; Q38::open 71→72 adds helper records; Kernels38::load 17→18 adds a loader. No correctness defect found in these functions.

Silent failure: 3 added candidates followed. Unsupported formats reach a named error; source construction limits plane counts to 1 or 2; failed read-ahead naming is retried and refused by the fill.

Tests: source mutation audit only. Assertions reject dropped row validation, an accepted zero-worker count, and missing pinned-reader normalization. Helper assertions cover the default part count, recorded metadata, and pool-plan refusal. Row comparisons catch substituting row zero and dropping the stored scale plane; read-ahead assertions cover replaced guesses and buffer reuse.

Gates: no tolerance relaxed. The unsafe-count increase has a dated PIN and reason; row-kernel coverage replaces the moved entry.

Escape catalog: C1–C4 do not match the changes.

Notes

Static review only; tests and GPU gates were not executed here. The reported card runs lack the required nvidia-smi card/driver line, so gpu.json records no complete GPU evidence.

Card check: needs-gpu. This pull request changes crates/gpu-deepseek41/src/chain/glue.rs, crates/gpu-gates/src/bin/gate_ple.rs, crates/gpu-gates/src/bin/generate_ds41.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 2b5e36d into midagedev:main Nov 1, 2026
8 of 9 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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant