Skip to content

placement, model, gpu-gates: --place tp plans GLM-5.3-Flash's Hugging Face checkpoint over N ranks, each in its own node's pool - #519

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-glm-tp-place
Oct 19, 2026
Merged

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-glm-tp-place

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

TP=2를 위해 GLM-5.3-Flash-FP4-Local의 텍스트 본체를 N개 rank에 나누는 배치 계획(--place tp --plan)을 더하고, 설정에 있는 모든 텍스트 층과 필수 텐서가 폴더에 있는지 검사합니다.

What and why

Part of #494, the "TP=2 placement" and "GLM-5.3-Flash names and layouts from the Hugging Face checkpoint to the names the body reads" items, and of #493, the "quantization config" and "safetensors folder source" items.

Under tensor parallel, each of N ranks holds a 1/N part of every split tensor and all of every whole one, resident in its own node's memory, with no host or NVMe tier. This PR adds the plan of that placement for GLM-5.3-Flash's Hugging Face checkpoint and prints it; the tensor-parallel load and decode are later items of #494, and a run without --plan is refused by name.

What the PR adds:

  • hf::safetensors::Folder reads a Hugging Face model folder (its model.safetensors.index.json and every shard's header, shards in subfolders included) as one tensor source, every dtype quantized checkpoints store held raw. A shard path that leaves the folder (.., a leading /, a drive prefix or a \), and an index whose weight_map holds no tensors, are refused by name.
  • hf::quant_config reads a checkpoint's quantization config (ModelOpt's hf_quant_config.json and the quantization_config in config.json) into one format a tensor, with each format's companion tensors checked. It knows NVFP4 (with plain, csf and csf_32x2_v1 scales), MXFP4, MXFP8, FP8 per tensor, per channel and per block (block scales [r, c] or [r, 1, c, 1]), packed INT4, BF16 and F32. A zero or malformed group size, an FP8 field of the wrong type, and a [ class in a ModelOpt module pattern (the reader matches * and ? only) are refused when the config is read. Quark checkpoints are refused by name; their config is not read. A packed weight whose unpacked width exceeds the platform's word is refused when it is placed. A tensor scale ModelOpt shares across a module's parts (Qwen3.8's PLE table) is found on the declared module. Published checkpoint configs are fixtures.
  • Format::held gives a format's bytes on the card and the block a cut must keep, with one owner per format: a format held in a GGUF card type reads its QRow and uses gguf::tensor_bytes, so NVFP4 in every scale encoding is GGUF's 64-value block with one F32 tensor scale a matrix. MXFP8 and FP8 block weights have no card type row yet and keep their own block and one scale a block.
  • model::arch::glm5next::hf maps the checkpoint's names and layouts to the glm5next names and ggml dims the body reads, and tp_cut names the dim and unit each tensor splits on: heads for KDA and latent attention, inner width for the dense blocks and the shared and routed experts, vocabulary rows for the head. Norms, the low-rank inputs every head shares, the indexer, the router, the hyper-connection mixes and the embedding stay whole on every rank. A stem with no rule, a split tensor with other dims than its stem has, two checkpoint tensors for one routed expert, a routed expert that is not a matrix, a layer holding part of a set of tensors that come together (a dense block's gate without its up, say), a kv_b_proj whose head count overflows, a tensor with a zero dimension or a byte count past 64 bits, and a checkpoint with no text tensors are refused by name. At the folder entry, one required-name table reads the config's layer kinds and the existing role tables. Every trunk layer must have its configured attention and feed-forward groups and its hyper-connections; configured shared experts, the embedding, the head and the final norm are required too. Configured NextN layers must have their latent attention, routed block, shared expert, input projection and input norms. NextN is validated but is not part of this trunk-only plan. The tensor-table API still accepts layer subsets.
  • refset family hf-map-glm5next and just dump-ref-glm5next-hf-map write the mapping oracle: the checkpoint's shard headers and small tensors beside the GGUF's tensor table and the same tensors. The family pins the checkpoint and GGUF revisions, the architecture and the writer's md5, and refuses by name a set of another revision, a changed file or an unfinished dump. just gate-glm5next-hf-map takes no argument and opens the set through the family.
  • placement::tp::plan_tp takes the tensors and one pool a rank and gives each rank's split and whole bytes. A part that is not whole units of the tensor's role (a head's rows), a part off the format's block, a rank past its pool, and two ranks on one device (a node that answers for this process's own card) are refused by name. The code takes any N; the tests run N = 1, 2, 3, 4 and 64.
  • generate_glm5next --place tp --plan reads the folder BLOOMERY_REF_MODEL names, plans rank 0 on this process's card and the other ranks on the nodes BLOOMERY_TP_NODES lists (each node's tier_server answers its census), and prints one tp rank= record a rank (record::TP_RANK, in the binary's --records-schema). BLOOMERY_TP_NODES takes the tier node rules (an off-host node needs BLOOMERY_TIER_LINK=rdma) and is refused beside BLOOMERY_TIER_NODES, as are BLOOMERY_DRAFT=mtp and an empty node list.

Existing paths: every other --place word parses as before, and Place::on refuses tp for every other binary. No GGUF load, plan or kernel changes.

Release notes: Under the hood: --place tp --plan prints the tensor-parallel plan of GLM-5.3-Flash's Hugging Face checkpoint over N nodes; the load is not built yet.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. A format's bytes and cut block live once, on Format::held, and read the GGUF card type's QRow where one exists. A rank's pool comes from the existing census through unified_of and node_cards.
  • Model code holds only architecture facts. glm5next::hf holds the checkpoint's names, layouts and the axis each tensor splits on; no common owner gained a per-model branch.
  • Dead code is gone.
  • No silent failure. Every refusal above is a named error.
  • Comments state what is true now.
  • No relaxed gate.
  • 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": none.

What I ran

Head 09355ef647a9253f5d2a21890823059131e2a7b4 on upstream main 821d7b85abc11611a7a416be21407352e2ebba85. The first three commits are the shared base da0786c473042a8e8197841b48bbd5bb680b48ff. The checks below ran on 188006905955a1eb775b3e742a30ac1f84aabc9e. git range-diff between that head and this one shows every commit equal except the model commit, which moves one fixture, glm-5.3-flash-ud-q4_k_xl-layers-0-3.tsv, from crates/model/data to crates/hf/tests/fixtures, and changes the one path in hf.rs that reads it.

The rank-byte reference is an independent count of the 42 shard headers of nvidia/GLM-5.3-Flash-FP4-Local at revision 76348ddb2be2e35e39ecfc00e75dc07703f4f3d5: the text trunk, block scales decoded to plain E4M3, BF16 as shipped and A_log as F32.

Check Reference Result
Layers 0, 3 and 4 fixture, scaled by the configured layer kinds, N = 1 181,433,466,872 B a rank equal
Same, N = 2 91,600,737,016 B a rank equal
Same, N = 4 46,684,372,088 B a rank equal
--place tp --plan on two DGX Sparks, the real folder 91,600,737,016 B a rank both ranks weights=91600737016

On a Linux x86_64 machine, the library tests, cargo fmt --check and clippy with -D warnings on the touched crates ran on 18800690:

cargo test -p bloomery-refset --lib
cargo test -p bloomery-hf --lib
cargo test -p bloomery-model --lib glm5next -- --nocapture
cargo test -p bloomery-placement --lib tp::
cargo fmt --check
cargo clippy -p bloomery-hf -p bloomery-gguf -p bloomery-model -p bloomery-placement -p bloomery-refset -p bloomery-levers --all-targets -- -D warnings

The library results were 256, 72, 42 and 4 passed, respectively, with no failures. Refset has three ignored tests. Format and clippy exited 0. Output: r10-fixes.log, lines 715 to 918. On 09355ef6, the lint and unit tier finished with DONE tier=t0 total=94 red=0 (lint.log, line 101), and the GPU crates compiled in the DGX Spark container (gpu-check.log).

The folder test writes a complete indexed safetensors folder with three trunk layers and one NextN layer. Its omission table covers an entire trunk layer, both attention kinds, dense and routed feed-forward groups, hyper-connections, shared experts, the embedding, head and final norm, and the NextN layer and its required groups and inputs. On bb23c488, all 17 omissions returned successful rank plans on the original reader; the corrected entry refused each by tensor name, and seven malformed config rows were also refused. Output: r9-fixes.log, lines 168 to 206 and 463 to 493. The test can be run alone:

cargo test -p bloomery-model --lib a_folder_requires_the_whole_configured_text_model -- --nocapture

The pinned FP4-Local index also covered all required names in the production table on bb23c488: 46 configured text layers including NextN, 1,368 required names and zero missing. This metadata-only check uses the real index's names and fixture shape templates, not model weights. Output: r9-fixes.log, lines 277 to 287. The two-node plan below is carried from 47cb6318, because the index satisfies the same coverage check and the returned trunk tensors and byte rules are unchanged. NextN remains outside those byte totals.

Mapping oracle gate

The oracle compares the Hugging Face NVFP4 export with the unsloth GLM-5.3-Flash UD-Q4_K_XL export. The gate computes the set of value tensors it must compare from the map and stops before comparing when the oracle lacks one of them, holds one the gate does not compare, or misses a layer from 0 to 44. Write the set and run the gate with:

just dump-ref-glm5next-hf-map
BLOOMERY_BOX_LOCAL=1 just gate-glm5next-hf-map

The gate matched 1,383 names and dimensions, 212 F32 tensors and 180 BF16 tensors. The existing ssm_a allowance covered 16 values one unit apart in the last place. Output: r10-fixes.log, lines 339 to 345. The writer's gguf.safetensors has the same md5, 74c321a388fcf37a28520b29402cc055, as the earlier hand-made oracle, with 392 Hugging Face and 392 GGUF tensors. Output: the writer job's log, lines 110 to 121.

The gate failed first on these changes. With the previous gate and a set without the 34 ssm_a decay tensors, the gate passed and compared no ssm_a value (lines 324 to 330). The fixed gate refused that set by tensor name, with exit 101 (lines 356 and 370). It also refused a set of another checkpoint revision (lines 372 to 394) and a set without its # complete trailer (lines 396 to 418), each with exit 101. Replacing A_log's NegExp layout with Same failed the value comparison at blk.0.ssm_a, exit 101 (lines 431 and 447). All lines are in r10-fixes.log.

Two DGX Sparks

On two DGX Sparks joined by their direct link, rank 1 ran tier_server --listen <addr>:<port> and rank 0 ran:

BLOOMERY_REF_MODEL=<folder> BLOOMERY_TP_NODES=<rank 1 addr>:<port> BLOOMERY_TIER_LINK=rdma \
  target/release/generate_glm5next --tokens 1 --place tp --plan

This ran on 47cb6318; the later commits do not change the folder reader's tensor accounting or the plan, and the --place tp record is pinned by its test. The retained output is:

tp rank=0/2 node=local weights=91600737016 split=89832729856 (714 tensors) whole=1768007160 (669 tensors) pool=124894056448 left=33293319432
tp rank=1/2 node=<rank 1 addr>:<port> weights=91600737016 split=89832729856 (714 tensors) whole=1768007160 (669 tensors) pool=124041736192 left=32440999176

The command exited 0. Without --plan it prints the named unbuilt-load error and exits 1. An unset BLOOMERY_TP_NODES is refused by name.

Comparison with the reference

The oracle is the Hugging Face export nvidia/GLM-5.3-Flash-NVFP4 at revision da920bb0b9f4a06727223a349e55468e38352348, read against unsloth's GLM-5.3-Flash-GGUF UD-Q4_K_XL at revision a38483c8cd5df544f53d70fb281afe97369d5ab6. The refset family hf-map-glm5next pins both, and the writer's gguf.safetensors has md5 74c321a388fcf37a28520b29402cc055. Measured on 18800690; 09355ef6 only moves a fixture (see above).

Compared Oracle This head Differences
Tensor names and dimensions 1,383 1,383 equal 0
F32 tensors, byte equal after the map's layout 212 212 equal 0 (16 ssm_a values one unit apart in the last place, inside the existing allowance)
BF16 tensors, equal to the GGUF's F32 rounded 180 180 equal 0

Direct effect: with N = 2 each rank holds 91,600,737,016 B of weights, 50.5 % [derived] of the 181,433,466,872 B one rank holds alone, and both ranks on two DGX Sparks print the same figure. The end-to-end number this opens is GLM-5.3-Flash decode over two nodes, which this PR does not measure: the plan expects 23 to 31 tok/s at one request [derived], against 4.68 tok/s on main's expert tier.

What I ran into

--place tp without --plan returns the named unbuilt-load error. This does not block the capacity-only change.

Hardware (if the change is for a machine)

Two DGX Sparks (GB10, 128 GB unified memory each) on a direct 200 Gb/s link, in the CUDA 13.3.1 container with BLOOMERY_ARCH=sm_121. The unit tests and the mapping gate ran on a Linux x86_64 machine.

AI help

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

…ry dtype quantized checkpoints store held raw

safetensors holds I8, U16, U32, I32, F8_E5M2 and F8_E8M0 beside U8 and
F8_E4M3 as stored bytes, so the shards of the FP8, MXFP4, NVFP4 and
compressed-scale checkpoints open; widening stays BF16, F16 and F32.

Folder opens model.safetensors.index.json and every shard it names, each
mapped with its header validated, so opening reads the index and the headers
and no tensor's bytes. Every name of the index must be in the shard it names
and every tensor of a shard in the index under that shard; a shard named by a
path outside the folder (a shard may sit in a folder of it, as FP4-Local's
tensors/native-QB.safetensors), and a shard's own refusal, are named with
the file. A tensor reads whole, by a range of its rows (one contiguous range) or
by a range of the
columns of a 2-D tensor (each row's piece, row after row).

The tests open the real headers of two nvidia/GLM-5.3-Flash-NVFP4 shards with
their index entries, and one deepseek-ai/DeepSeek-V4.1-Flash shard, written
as files whose data sections are holes. refuses_unknown_dtypes_and_bad_ranges
used I8 as its unknown dtype; it now uses C64.
quant_config reads the supported configs quantized checkpoints carry: ModelOpt's
hf_quant_config.json (quant_algo, quantized_layers, exclude_modules),
transformers' fp8 (weight_block_size, modules_to_not_convert),
compressed-tensors (config_groups, ignore). Quark checkpoints are refused
by name. Each module is declared a format:
NVFP4-ModelOpt, FP8 by block, channel or tensor, MXFP4-OCP or INT4-pack; an
unknown quant_method, algorithm or scheme is refused by name when the config
is read. ModelOpt's file takes a module first and config.json's own config
the modules it leaves, as DeepSeek-V4.1-Flash-NVFP4 needs.

plan gives every tensor of a table one format: a weight's stored dtype,
shape and companion scales are matched against its module's formats, a
tensor scale may be shared from the module ModelOpt names (Qwen3.8's PLE
shards), and BF16 and F32 are placed as stored. A quantized weight the
config leaves unquantized, one that fits none of its formats, a companion no
placed weight reads and any other dtype are refused by name. input_scale and
kv_cache_quant_algo are reported, not used.

The fixtures are the configs of twelve checkpoints and every tensor of
GLM-5.3-Flash-NVFP4's layers 0 and 3.
…s unit-axis block scales, NVFP4 with csf and csf_32x2_v1 scales

ModelOpt's FP4-Local exports declare MXFP8 (group 32 or weight_block_size [1, 32]), FP8_PB_WO with its block grid stored [r, 1, c, 1], W4A16_NVFP4, and NVFP4 whose weight_scale is stored compressed (weight_scale_encoding csf or csf_32x2_v1). The reader refused MXFP8 by name and so read neither config. Each format now places its weight with its own companions: MXFP8 its E8M0 scale a 32 values, FP8 blocks a 2-D or unit-axis 4-D grid, csf its fixed slab and exceptions, csf32 its five parts. An unknown encoding, or an encoding on another algorithm, is refused by name. Decoding the compressed scales is not part of this reader.
…and layouts

glm5next::hf maps a GLM-5.3-Flash checkpoint's tensors to the glm5next names
the program reads, with the layouts llama.cpp's converter (Glm5NextModel)
writes: the routed experts of a projection stacked by id, kv_b_proj split per
head into the key half (transposed) and the value half, the KDA conv taps as
[kernel, 1, channels], A_log as -exp of its heads, dt_bias as the ssm_dt
bias, under a model.language_model. or model. prefix. The next-token layers
and the vision tower are left out; any other name, a stack missing an expert
and a kv_b_proj of the wrong rows are refused by name. Layout::apply moves a
tensor's elements; the names come from glm5next::names.

The test maps layers 0 and 3 and the unlayered tensors of
nvidia/GLM-5.3-Flash-NVFP4 (placed by hf::quant_config) to exactly the names
and ggml dims of unsloth's UD-Q4_K_XL for those layers. An ignored test
checks every layer and the small F32 tensors byte for byte against that GGUF.
…r N ranks, each rank in its own node's pool

Tensor parallel is a new placement beside the expert tier: each of N ranks
holds a 1/N part of every split tensor and all of every whole one, resident in
its own node's pool, with no host or NVMe tier. placement::tp::plan_tp takes
the tensors and one pool a rank and gives each rank's split and whole bytes; a
cut whose parts are not whole units of the tensor's role (a head's rows) or
cut off its format's block, and a rank past its pool, are refused by name. A
rank's pool is its node's census reading: the unified pool on a device that
allocates from host memory, else the card's usable bytes capped by its free
reading.

A format's bytes and cut units are written once, on the format
(hf::quant_config::Format::held): a format held in a GGUF card type reads its
row (QRow::cut: one block along a row, any row), so NVFP4 in every scale
encoding is GGUF's 64-value block; MXFP8 and FP8 block formats, which have no
card type row, keep their own block and one scale a block. The family gives
only the axis: model::arch::glm5next::hf::tp_cut names the dim and unit each
glm5next tensor is cut on (heads for KDA and latent attention, inner width for
dense, shared and routed experts, vocabulary for the head) or keeps it whole
(norms, shared low-rank inputs, indexer, router, hyper-connections,
embedding).

generate_glm5next --place tp --plan reads the Hugging Face folder
BLOOMERY_REF_MODEL names, plans rank 0 on this process's one card and the
other ranks on the nodes BLOOMERY_TP_NODES lists (each node's tier_server
answers its census), and prints one `tp rank=` line a rank. The load is not
built and is refused by name, as are BLOOMERY_DRAFT=mtp, an empty node list,
and BLOOMERY_TP_NODES beside BLOOMERY_TIER_NODES; an off-host node needs
BLOOMERY_TIER_LINK=rdma as a tier node does. Every other --place word parses
as before, and Place::on refuses tp for every other binary.

On GLM-5.3-Flash-FP4-Local's layers 0, 3 and 4 the per-rank sums, scaled by
the layer kinds the config lists, equal an independent count of all 42
headers: 91,600,737,016 B a rank at N = 2 and 46,684,372,088 B at N = 4. 64
heads into 3 ranks and a routed down's 2,048 inputs into 64 ranks are refused.
@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 placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 19, 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 merge-blocking defect survived the failure-path checks.

Non-blocking

⚠ Assert routed-expert stacking order: crates/model/src/arch/glm5next/hf.rs:213. Replacing by_id.values() with by_id.values().rev() escapes the assertions: the mapping test discards layout at line 657, and the oracle's VALUES list excludes expert weights. Assert numeric expert-ID order in each Layout::Stack in the existing mapping test to catch an ordering regression.

Checked

Duplicates: 146 new declarations checked; no proven duplication. All three dryer pairs read: distinct error variants or conversion domains, with no common owner to reuse.
Complexity: new GLM layer/tp_cut and quant modelopt_format/held dispatch architecture or format rules. New map combines name dispatch, expert stacking and group validation; layout combines format-specific companion checks; required combines config validation and role selection; HfMapSet::read combines headers, file rows and completion checks; Folder::open combines index validation and shard checks. Existing Dtype::of/name, levers::read, Family::check_set and cli::run grow through cases and guards.
Silent failure: 13 added production fallback/conversion sites followed. Required malformed values reach named errors; remaining fallbacks represent optional metadata or implicit dimensions.
Tests: mutation review of 23 new tests and two changed tests. Wrong types/layouts/byte totals and dropped presence, cut, pool, overflow, identity and RDMA guards meet assertions. Reversed expert stacking remains uncovered, as above.
Gates: no existing band or pin relaxed. The new writer PIN matches its source md5. The PR reports FAIL-first for missing oracle values, stale identity, unfinished sets and the A_log transform.
Adversarial checks: missing configured layers, partial experts, head/block boundary cuts, duplicate device UUIDs and overflowing packed widths are refused. Unavailable peers propagate connection errors.
Escape catalog: no C1–C4 match. Changed paths perform planning, metadata reads or tooling; no decode/prefill hot path changed.

Notes

Tests were inspected, not executed in this review. GPU evidence is incomplete: the PR provides no nvidia-smi card-and-driver line.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/generate_glm5next.rs, crates/gpu-gates/src/generate.rs, crates/gpu-gates/src/record.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.

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 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