Skip to content

gguf, placement, hf, model, model-hf, gpu, gpu-glm5next: a TP rank reads its parts from a GGUF file or a checkpoint folder - #618

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-tp-rank-source
Oct 21, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-tp-rank-source

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

TP rank가 GGUF 파일이나 체크포인트 폴더에서 자기 몫의 조각만 읽게 합니다.

Part of #565.

What and why

This lets each tensor-parallel rank read only its own parts of a model, from a GGUF file or from a safetensors checkpoint folder, through one entry point. Before, a folder could only be read whole, so a rank that needs one slice of every split tensor had no way to start from the folder.

The entry point is the trait model::part::Source, implemented for a GGUF file (gguf::Split, in crates/model/src/part.rs) and for a checkpoint folder (Checkpoint, in crates/model-hf/src/part.rs). plan(rule) checks every part against the tensor headers before any value is read, so a part that is out of range or mis-sized is refused at the input boundary. read(&Planned) then returns the card type's bytes and the tensor scale. The layer holds no model name and no rank count. With one rank, every tensor is read whole.

  • Cut rules (crates/placement/src/placement/tp.rs): part_of, Cut::span, check_rank and check_bytes own where a rank's part starts and ends.
  • Source trait (crates/model/src/part.rs): Source, Planned, Part and the GGUF implementation.
  • GGUF side (crates/gguf/src/lib.rs): tensor_runs, tensor_scales and scaled_weight.
  • Checkpoint side (crates/hf/src/modelopt.rs): normalize_part and check_part, plus the plain BF16 and F32 expert stacks.
  • GLM-5.3-Flash (crates/model/src/arch/glm5next/tp.rs, crates/model-hf/src/arch/glm5next.rs): cut_of and rank_span name each tensor's cut, and PlacementError::Tp reports a refused part. glm5next::open opens the folder and returns the geometry, the tensor list and the checkpoint.
  • Card upload (crates/gpu-glm5next/src/tp/source.rs, crates/gpu/src/weights.rs): tp::load takes any &impl Source. It checks every part's plan and card format first, then reads and uploads in groups of a gibibyte through Weights::add_parts, which replaces Weights::load_parts. The other caller of the old function, the Raon test helper in crates/gpu/src/arch/raon1/rda.rs, moved to the new API too (Weights::default(), add_parts, pieces with scale: None). A group joins the resident weights only after its uploads have synchronized, so a part refused late in a group leaves none of that group on the card. An NVFP4 part carries its own tensor scale.
  • Features (crates/gpu-glm5next/Cargo.toml): the hf crates are optional behind a new feature hf. Only the folder test needs them, so the gates that read a GGUF file leave the feature off.
  • Binary (crates/gpu-gates/src/bin/generate_glm5next.rs): --place tp uploads rank 0's parts to the card. It then stops with a named refusal, because the step between nodes is not built.

Release notes: Added: a tensor-parallel rank reads only its own parts of a GGUF file or a safetensors checkpoint folder through one shared entry point.

Code shape

  • No second copy. The cut rule, the scale names and the NVFP4 scale rule each have one owner in a CPU crate, and the GPU loader calls them. The -exp conversion has one function, neg_exp in crates/model-hf/src/arch/mod.rs, which both GLM-5.3-Flash and Qwen call. It refuses a non-finite input before converting and a non-finite or zero result after, and each caller wraps the refusal with its tensor name. The temporary-folder helper that three test modules copied lives once in model_hf::test_support.
  • Model code holds only architecture facts. GLM's files give tensor names, roles and cut axes. Source and the cut rules carry no model name and no rank count.
  • Dead code is gone. The reads_scale filter in part_format is removed.
  • No silent failure. A part that is out of range, mis-sized or of a card type that cannot carry a scale is refused by tensor name before any value is read.
  • Comments state what is true now.
  • No relaxed gate. No band or tolerance moved. The planned bytes per rank in the header-fixture and trunk tests changed, because the budget is now the bytes that sit on the card: a BF16 tensor counts at its F32 size, and the host embedding is left out (next paragraph). Each changed expectation carries a dated PIN comment with the reason.

The per-rank memory budget counts the bytes a rank puts on the card, not the stored size and not tensors that stay on the host. mapped_tp in crates/model-hf/src/arch/glm5next.rs sets each TpTensor::bytes with CardFormat::resident_bytes, the same owner the upload uses, and a BF16 tensor is counted as Bf16AsF32, at its F32 size. Two kinds of tensor are never uploaded: the NextN layer after the trunk, and the token embedding, which stays in the host file. in_trunk in crates/model/src/arch/glm5next/tp.rs decides whether a layer belongs to the trunk, and card_holds adds the embedding exclusion to it. The plan (mapped_tp), the checkpoint's part list and tp::load all ask these two functions, so none of them keeps its own judgment. The embedding is still checked for presence and by the required-name check. A tensor name's layer number is parsed once, by layer_of in the same file. Before, every rank's budget counted the embedding, which asked each rank for an F32 size that the upload never used. A quantized expert stack with a single expert is read as well, whole or in parts: the plan finds the expert axis from the stored 2-D shape, so a stack of one expert no longer reads as a plain matrix.

Duplication found or removed: the three test-module copies of the temporary-folder helper are replaced by one owner, the two -exp copies are replaced by neg_exp, the layer-number parsing and the NextN judgment each have one owner (layer_of, in_trunk), and the part_format scale filter is removed because the NVFP4 rule already decides it.

What I ran

The PR head is 9c98934013a385e58b05fe80e2c1e657fc2ce95b, on main d4429af1cf39f7a503ce728d6791fa20f97445fa. The other checks ran on the same commit before a rebase onto main with no conflicts. The checks that put the NextN judgment back (below, and in the GPU section) ran on an earlier commit of this branch.

On that commit, just contrib-check --tier t0 passed, including these unit-test recipes:

  • test-bloomery-gguf
  • test-bloomery-hf
  • test-bloomery-placement

The fixture budget test for the written fixtures, hw_the_written_fixtures_hold_their_recorded_budget, also ran on that commit, on an RTX 5090 machine: 1 passed.

To check that the NextN judgment has one owner, a_glm_folder_gives_each_rank_its_gguf_s_part ran with each caller put back to the old judgment, and with the owner's layer limit and its embedding exclusion removed. All five variants failed on an assertion ("the card plan holds no NextN tensor", "the checkpoint makes no NextN tensor" or !plan.contains_key("token_embd.weight")) with exit 101, and the restored source passed. The test checks, for one, two and four ranks, that the plan's card bytes equal the resident bytes of what each source reads, from a GGUF file and from a folder, with the embedding and the NextN layer left out of both.

The oracle for the card test is the whole tensor read on the card. The parts of one, two and four ranks, joined on the card, must equal that tensor bit for bit. The test is hw_a_folder_s_rank_parts_join_into_its_whole_on_the_card. It builds synthetic folders in NVFP4 expert stacks, MXFP8, FP8 with 128x128 blocks, BF16 and F32. It also checks the refusals that must happen before any read, and that a group with one refused part publishes none of its parts. For BF16 it checks that rank 0's head buffer equals resident_bytes (65,536 divided by the rank count) at one, two and four ranks. The folder also holds the embedding and a NextN tensor, and the test checks that no rank's load puts either on the card.

GPU evidence

The card is a DGX Spark (GB10) in the dev container image bloomery-dev:cuda13.3.1. The raw nvidia-smi table lines come from an earlier run on the same card and image. The run of the final code printed the query line NVIDIA GB10, 595.84 before each GPU test.

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

The folder test needs --features hf. Without it the folder test is not built, and the run finds no test. The card test, run on that card:

bash tools/gate.sh --oxide -p bloomery-gpu-glm5next --release --features hf --lib -- --include-ignored hw_a_folder_s_rank_parts_join_into_its_whole_on_the_card --nocapture
test result: ok. 1 passed; 0 failed; 0 ignored

The fixture-tier gate for the same path, run on that card:

env BLOOMERY_TIER=fixture just gate-gpu-glm5next-tp
test result: ok. 8 passed; 0 failed; 0 ignored
test result: ok. 1 passed; 0 failed; 0 ignored

just gate-gpu-glm5next-tp ends with exit 0. The recipe passes --features hf itself. The first result is the tp module's tests, and the second is the gate binary's test.

To check that the card test can fail, tp::load was changed to ask for the old judgment, which lets the NextN tensor onto the card. The test failed on assertion failed: off_card.iter().all(|n| whole.get(n).is_none()) with exit 101. With the source restored it passed again.

Reference Result
one rank's whole tensor on the card the ranks' parts joined bit-equal, PASS

Each rank's parts, read from a checkpoint folder and joined in rank order on the card, equal the whole tensor bit for bit for every format the folder holds.

The change touches crates/gpu/src/weights.rs, so the compiled PTX was compared with main. The scan set is the one just canon-check picks: three binaries, bloomery-serve-ds41, gate_kquant and gate_swap. Each was built on main and on the head, scanned with ptx-scan --no-jit, and compared with tools/ref/ptx-canon.py --scans:

ptx-canon: table rows identical=391 moved=0
ptx-canon: table rows identical=319 moved=0
ptx-canon: table rows identical=316 moved=0

All 1026 entries (391, 319 and 316) are identical, and no entry exists on only one side.

The DeepSeek load goes through Body::load_placed, Weights::load_placed and upload_segment, which now read the moved scale. Two fixture-tier gates cover that path.

Both ran on main and on the head, on the same card, and both exited 0 with the same PASS lines:

env BLOOMERY_TIER=fixture just gate-gpu-ds41-step
PASSED: gate_deepseek41_step
env BLOOMERY_TIER=fixture just gate-gpu-bf16
gpu-gate.sh: gate_bf16 ran 2 s (exit 0)

For gate-gpu-bf16 the normalized output of main and head differs in 0 lines. For gate-gpu-ds41-step it differs in 3 lines of 268: the card's free bytes at load (two lines) and the load time with its free bytes. The resident bytes are the same, 89101272.

What I ran into

This does not block the PR. The checks above ran on one DGX Spark with loopback peers, so they cover the upload, the plan and the per-rank parts, not a decode across machines. The fixture in the gate refuses four ranks by name because four ranks would cut a 256-value Q6_K block. The folder's two and four rank parts are joined by the card test above. The full GLM-5.3-Flash FP4-Local checkpoint was not uploaded. just stage-gpu-load-v41, which AGENTS.md asks for on a change to crates/gpu/src/weights.rs, was not run. That recipe checks a DeepSeek-V4.1 plan split over two cards against the real files, and the machine used here has one card and only the fixture sets. The same load path was compared with main by the two fixture gates above.

Hardware

A DGX Spark (GB10), driver 595.84, CUDA 13.3 in the dev container, for the card test and the gates. An RTX 5090 machine ran the fixture budget test, and a separate CPU host ran the unit tests.

AI help

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

…ads its parts from a GGUF file or a checkpoint folder

A rank's load took its parts from a GGUF file only. It now plans and reads each part from a
model::part::Source: the caller's rule gives, for a tensor's name, card type and dims, whether it
is read and which indices, and the source returns the part's bytes in its card type with the
tensor scales its type reads. A source holds no model names and no rank count; one rank reads
every tensor whole. model::part reads a GGUF file (gguf::Split), and model_hf::part::Checkpoint
reads a Hugging Face checkpoint folder.

The cut core moves to the CPU crates so both sources share it: placement::tp::part_of,
Cut::span and check_bytes, gguf::tensor_runs, tensor_scales and scaled_weight. A folder's tensor
is cut before it is normalized (hf::modelopt::normalize_part), so a part reads only its own
stored values and block scales; check_part refuses a cut that splits a stored value or scale
block from headers alone. A tensor the model moves after normalizing is made whole, moved,
then cut. A plain BF16 or F32 expert stack now normalizes into one 3-D tensor.

model_hf::arch::glm5next::open gives the GLM folder's checkpoint, and the family's rule is
model::arch::glm5next::tp::rank_span. The folder's card plan and the rank's load hold the same
tensors on the card (model::arch::glm5next::tp::card_holds): the trunk's layers, the head and
the final norm, not the next-token layers or the token embedding, which the host reads.
gpu-glm5next's tp::load plans every part of any source, checks its card format, then reads and
uploads the parts a group at a time through Weights::add_parts, which now takes NVFP4 parts with
their tensor scales. gpu-glm5next links the hf crates only through its `hf` feature, which the
folder test on the card needs (`just gate-gpu-glm5next-tp`), so the gates that read a GGUF file
do not key them. generate_glm5next --place tp without --plan loads rank 0's parts of the folder
onto the card, then refuses by name: the ranks' step over the link between nodes is not built.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app 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 placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 21, 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 must-fix defect survived the source and boundary checks.

Non-blocking

⚠ Required staged-load evidence: crates/gpu/src/weights.rs:464.
The body reports that just stage-gpu-load-v41 was not run. Base AGENTS.md requires it for this file.
Attach that command's output from a two-card setup. It checks the shared uploader against real split files before landing; the fixture runs cover smaller loads.

Checked

Duplicates: 103 added declarations searched. Both dryer pairs read: short constructors for different error types; extracting them adds elements. No actionable duplicate found.

Complexity: all four flagged functions are new. plan_part (21) plans format-specific cuts; normalize_part (19) materializes them; Layout::apply (18) handles architecture layouts; Checkpoint::read (17) normalizes, transforms and checks the result. Existing stage helpers separate their work.

Silent failure: 9 conversion/default/filter sites followed. Failed conversions become named refusals; defaults rely on validated shapes or mapped names. Invalid scales, ranks and byte spans reach callers as errors.

Tests: 24 changed tests inspected. Mutation reasoning was static; no mutants were executed here. Production sites and mutants, with assertions that turn red by inspection:

  • GPU weights.rs:257,292,316,488: bypass size/scale/span checks or publish an upload early; the three part-validation tests and failed-group clause fail.
  • GPU tp/source.rs:49: select rank zero for every rank; the rank-wrapper test fails. tp/mod.rs:632: retain NextN or embedding; the card test fails.
  • HF modelopt.rs:1007,487: accept ragged experts or non-matrix quantized dims; the normalization and matrix-refusal tests fail. quant_config.rs:171: accept zero dims; the held-format test fails.
  • GLM glm5next.rs:144,531,702,721: drop the key transpose, count BF16 at stored size, omit required-name checks, or retain NextN; layout, budget, required-folder and rank-equivalence tests fail. The real map gate also catches a changed -exp sign at arch/mod.rs:11.
  • arch/mod.rs:12: accept an underflowed zero; its numeric test fails. Qwen qwen35moe.rs:306: drop schema validation; its input-refusal test fails.
  • Checkpoint part.rs:78,138,162: admit absent sources, allow row cuts, or normalize the whole instead of a part; the three source tests fail.
  • Model glm5next/tp.rs:135,161: omit kernel units or shift rank spans; both new cut tests fail.
  • Placement placement.rs:378: use the last node; the accessor test fails. tp.rs:111,151,183: shift a span, admit malformed sizes, or shift byte runs; the three moved cut tests fail.

Gates: changed budget expectations carry dated PIN reasons; no tolerance relaxed.
Escape catalog: C1–C4 have no matching added pattern.
Performance: load-time changes only; no changed decode, prefill or kernel work.

Notes

Source inspection only. Builds and gates were not run during this review. The body supplies GB10 gate output and identical PTX scans.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/generate_glm5next.rs, crates/gpu-glm5next/Cargo.toml, crates/gpu-glm5next/src/tp/mod.rs … and carries a gate run on the author's card, which counts as verified.

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

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 21, 2026
@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 df0bf6c into midagedev:main Oct 21, 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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja placement Placement planning: crates/placement 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