Repository navigation
dsv41: JANGHT bundles natively + exact sampled dSpark - #30
Merged
Merged
Conversation
… vision) in the runtime and the dSpark draft
A JANGHT bundle declares every module's format in config.json "quantization":
the release FP8 projections repacked byte-exact as MLX mxfp8 (attention,
indexer wq_b, shared experts, engram wkv, dSpark attention/shared/main_proj),
embed/head affine 8-bit, routed experts JANGT trellis (Hadamard-128 + signs,
K in {1, 1.5, 2, 2.5}) and the vision/aligner Linears affine 8-bit.
- BundleSpecs reads those formats (fail closed on an unlisted module or an
unknown jangt block); affine bundles keep the shape-inferred bits.
- qlinear builds mxfp8 Linears; grouped_qmm runs the block-diagonal wo_a for
affine (biases) and mxfp8 (no biases), prefill group-major and decode
row-wise as before.
- Routed experts of a JANGT layer are a vmlx_engine.jangt JTMixedSwitchGLU
(rotate-once fused gate+up+SwiGLU with the clamp, rotated weighted down,
expert-sorted NAX prefill tiles); Block.moe routes as before and adds the
shared expert through one helper for both formats.
- quantize_listed_linears quantizes exactly the vision/aligner Linears the
config lists.
- load_dspark loads a JANGHT dspark/dspark.safetensors as stored: mxfp8
projections (no bf16 dequantization) and JANGT experts.
Measured on the 94.8 GiB DSV4.1-Flash-1017 JANGHT bundle (M5 Max, 128 GB)
against the verification runtime that passed the bundle gates, same prompts:
teacher-forced argmax agreement 98.4 %, KL mean 0.002-0.005 (the bundle's
held-out quantization KL is 0.134); greedy output diverges only after near
ties. Affine bundles are unchanged.
…lti-row mxfp8 projections - Rope takes (start, step) positions at every call site but a multi-segment batch and runs mx.fast.rope on the rotated tail (one kernel instead of the angle / cos / sin / rotate graph); the compressed rows are (g0, ratio). Same fp32 angles and bf16 store. VMLX_DSV41_FAST_ROPE=0 keeps the old path. - wo_a runs group-major for every multi-row forward, not only prefill: the token-major layout re-read the 8 group matrices per row (DSpark 6-row verify, 40 layers, mxfp8: 10.6 -> 4.5 ms). Verify rows were not bit-identical to 1-row decode anyway (the other projections switch kernels with the row count). - mxfp8 Linears (MxLinear) and the grouped wo_a send 3..7 rows through vMLX's multi-row mxfp8 QMV when available: each weight read once, every row bit-identical to its 1-row call. - JANGHT bundles: fp32 copies, once, of the router gate and the pooled compressors' wkv/wgate (every use computes in fp32; value-identical). - dSpark windows/drafts pass consecutive positions as (start, 1). DeepSeek-V4.1 JANGHT, M5 Max, chat prompts, greedy, adaptive DSparkRunner vs AR (3 interleaved probes, median): code 75.8 vs 27.4 tok/s, code2 38.9 vs 25.1, structured 39.8 vs 23.5, prose 23.5 vs 24.1 (governor stays on AR); code and code2 token-identical to AR.
…reads it; an fp32 copy disabled that path)
…+ mxfp8 shared kernels Block.moe and the dSpark draft MoE send <= 8 rows of a JANGT layer through vmlx_engine.jangt.fused_moe.jt_moe_decode (four dispatches instead of about fourteen; each row bit-identical to the stock routed + shared path, checked on first use). VMLX_DSV41_FUSED_MOE=0 or VMLX_JANGT_FUSED_MOE=0 keeps the stock path; the calibration capture hook keeps it too.
…Gumbel noise, coupled drafting) DSparkRunner was greedy-only, so every request at the release sampling defaults (temperature 1.0 / top_p 1.0, what the apps send) decoded at AR speed. decode_stream(sampler=SpecSampler(...)) samples instead: the token at each target position is argmax(f(logprobs) / T + g_pos), g_pos i.i.d. Gumbel noise keyed by the request seed and the absolute position (f = mlx_lm's top_p / min_p / top_k filters in make_sampler's order), so it is a draw from the AR sampler's distribution. The verify keeps a draft exactly when it IS the sample; every committed token is the target's sample whatever the draft proposed. The draft's Markov chain draws with the same noise (coupled drafting), so a drafter close to the target proposes the target's sample. Noise must be keyed by position, not by round: with fresh noise per round, the rejected row of a partial accept was re-sampled from the same logits with new noise, i.e. from the target conditioned on the coupled draft's rejection (biased; TV 0.070 on the test below vs <= 0.041 for plain sampling). tests/test_spec_sampler.py: a Markov-chain backbone and a different drafter drive the real decode_stream (verify, partial-accept commit, refeed, adaptive governor), 6000 seeds x 3 tokens: TV to the exact sequential- sampling distribution 0.033 (plain sampling at the same N: mean 0.032, max 0.041); a sampler that accepts the draft instead (control) scores 0.40.
…er: shared weights read per row) In-process interleaved A/B on the DeepSeek-V4.1 JANGHT bundle (M5 Max, 4 probes per arm): AR decode 29.5 -> 30.2 tok/s (code2) and 29.0 -> 29.8 (structured) with the fused kernel, AR tokens identical; DSpark 45.9 -> 38.8 and 47.1 -> 39.9. The fused shared slot streams the mxfp8 shared weights once per row, while the stock multi-row path reads them once for all rows (FP8_ROWS). Draft and verify rows keep the stock path.
cd274fb dropped the module's os import with the pread Engram path; an unseeded sampled request (the serving default at temperature > 0) then raised NameError in the engine loop. Test covers the unseeded sampler.
Keeps the repo's except-Exception site count within the invariant's threshold (the two optional-dependency imports were the only new sites).
jjang-ai
force-pushed
the
feat/dsv41-janght-runtime
branch
from
October 26, 2026 15:25
f61b5fc to
21d1681
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On main (after #29). The
jang_tools.dsv41runtime loads and serves JANGHT bundles(
OsaurusAI/DeepSeek-V4.1-Flash-1017-JANGHT1.4) natively, and dSpark serves sampled requests exactly.BundleSpecsfrom the config's per-module quantization; MXFP8 projections (MxLinear, therelease FP8 repacked byte-exact) with vMLX's multi-row MXFP8 QMV for 2..8 rows; JANGT routed experts through vMLX's
JTMixedSwitchGLU; 8-bit vision linears; the JANGHT dSpark drafter loaded as stored. Router gate stays bf16 so therouter GEMV keeps serving it.
mx.fast.ropewith (start, step) positions; group-majorwo_afor every multi-row forward(6-row verify 10.6 -> 4.5 ms); fused JANGT routed + MXFP8 shared MoE for 1-row decode (multi-row measured slower).
SpecSampler): the token at each position is the AR sampler's draw (top_p / min_p / top_k asmlx_lm) with Gumbel noise keyed by request seed and absolute position; drafting is coupled to the same noise.
tests/test_spec_sampler.pychecks the output distribution against sequential sampling (and that fresh noise perround is detectably biased), plus the unseeded case.
Measured on M5 Max (JANGHT1.4): teacher-forced vs the gate-passing reference, argmax agreement 96.9-100 %, KL
0.003-0.005; AR ~31 tok/s; dSpark greedy code 67-89 / code2 50 / structured 52 tok/s; T=1.0 code 65-84 tok/s;
cold prefill 524 / 822 / 936 tok/s at 1.6k / 6.5k / 26.5k (served); 256k needle retrieval correct, KV 230 MiB.