neurarch 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # neurarch
2
2
 
3
- What a GPU training job needs before it takes a reservation: the peak memory at
4
- its batch, the smallest card that holds it, and what one run costs, read from a
5
- Hugging Face `config.json` (or a traced graph). No account, no download, no GPU.
3
+ The pre-check for an open-weight model change, before it takes a GPU or
4
+ traffic. From a Hugging Face `config.json` (or a traced graph), without running
5
+ the model: what a training job needs (the peak memory at its batch, the smallest
6
+ card that holds it, what one run costs), whether a parallel layout is legal and
7
+ balanced (`layout`), whether a serving launch will start and hold what it
8
+ promises (`serve-check`), and whether the data fits what the config accepts.
9
+ No account, no download, no GPU.
6
10
 
7
11
  ```
8
12
  npx neurarch rightsize jobs.csv # each past job's request next to what it needed
9
13
  npx neurarch Qwen/Qwen3-8B --batch 8 # the training peak for one model
10
14
  npx neurarch oom error.txt --model Qwen/Qwen3-8B --batch 8 # why it ran out of memory, and the least invasive fix
15
+ npx neurarch layout Qwen/Qwen3-8B --tp 4 --pp 4 --dp 8 --global-batch 512 --seq-len 4096 # is this parallel split legal and balanced
16
+ npx neurarch serve-check Qwen/Qwen3-8B --gpu l4 --gpus 4 -- vllm serve Qwen/Qwen3-8B -tp 4 --max-model-len 32768 # will this serving launch start
11
17
  npx neurarch Qwen/Qwen3-8B --inference --batch 4 --seq-len 4096 --gen 512 # weights + KV cache for a generation job
18
+ npx neurarch bert-base-uncased --seq-len 1024 --tokenizer-size 30524 # does the data fit what the config accepts
12
19
  ```
13
20
 
14
21
  The memory number is calibrated against measured runs, and every run is public
@@ -117,6 +124,34 @@ prices. Nothing was trained and nothing was measured, which is why the verb is
117
124
  "quoted": what it is good for is deciding whether to start the run, not
118
125
  predicting what comes out of it.
119
126
 
127
+ ## Does the data fit what the config accepts
128
+
129
+ Some jobs never reach their peak: they are admitted, wait for the card, load the
130
+ weights and then index past a table on the first batch. Each of these is
131
+ readable from the config before anything is reserved.
132
+
133
+ ```
134
+ $ npx neurarch bert-base-uncased --seq-len 1024 --tokenizer-size 30524
135
+
136
+ data fit checked: sequence length, tokenizer size
137
+ block Sequences of 1024 tokens are longer than the 512-row position table
138
+ fix: Truncate or chunk to 512 tokens, or pick a model whose context covers 1024.
139
+ block The tokenizer has 30524 ids and the embedding has 30522 rows
140
+ fix: Call model.resize_token_embeddings(len(tokenizer)) before training, and budget for the new rows.
141
+ ```
142
+
143
+ | flag | checked against | when it blocks |
144
+ |---|---|---|
145
+ | `--seq-len N` | the position scheme | past a learned position table (a rotary context only warns: it runs) |
146
+ | `--tokenizer-size N` | rows in the token embedding | more tokenizer ids than rows |
147
+ | `--classes N` | a `*ForSequenceClassification`-style head in the config, or a graph's final Linear | more labels than the head emits (fewer only warns) |
148
+ | `--image-size N` | the patch position table | any other size |
149
+ | `--channels N` | the first layer's input channels | any other count |
150
+
151
+ A field you do not state is not checked, and the output lists what could not be
152
+ compared and why, so a clean result never stands in for one nobody ran. A block
153
+ sets the exit code to 1. The same check is `data` on `POST /api/v1/check`.
154
+
120
155
  ## Which modules a LoRA can sit on
121
156
 
122
157
  ```
@@ -222,6 +257,468 @@ wall hours, so a request cut from 8 cards to 1 is capacity reserved and not
222
257
  needed, not a promise the same job finishes as fast. The report prints all of
223
258
  this next to the numbers.
224
259
 
260
+ ## Is this parallel split legal, balanced, and worth running
261
+
262
+ ```
263
+ npx neurarch layout <hf-id | graph.json> --tp 4 --pp 4 --dp 8 --micro 1 --global-batch 512 --seq-len 4096 \
264
+ [--gpu h100] [--gpus 128] [--cp 2] [--ep 8] [--schedule 1f1b|interleaved --virtual 2] \
265
+ [--layers 9,10,10,7] [--zero 1|2|3 | --fsdp] [--recompute] [--fused-ce] [--seq-hist hist.csv] [--json]
266
+ ```
267
+
268
+ ByteDance traced five months of its own LLM training ("Understanding
269
+ Stragglers in Large Model Training Using What-if Analysis", OSDI 2025,
270
+ arXiv:2505.05713): 10.4% of allocated GPU-hours went to stragglers, 42.5% of
271
+ jobs ran at least 10% slower than their straggler-free what-if, and machine
272
+ problems explained the majority of the slowdown in only 1.7% of straggling
273
+ jobs. In 39.3% of jobs the last pipeline stage caused most of it, because it
274
+ carries the LM head and the loss on top of an even share of transformer
275
+ layers; uneven sequence lengths affected 21.4%, at 1.34x on average. Those are
276
+ configuration choices, and all of them are readable from the model before the
277
+ job starts.
278
+
279
+ `layout` checks five things:
280
+
281
+ 1. **Legality** (exit 1): tp x pp x dp x cp against `--gpus`; TP against the
282
+ attention heads, KV heads (a multiple of them is a replication warning),
283
+ hidden and FFN widths; PP against the blocks and `--layers` against the
284
+ block count; global batch = micro x grad-accum x dp; EP against the experts
285
+ and dp x cp; CP against the sequence length; TP past one node.
286
+ 2. **Stage balance**: a predicted forward + backward time per microbatch for
287
+ every stage, the sum of its layers: matmul FLOPs at 40% of the card's peak
288
+ plus the bytes the memory-bound ops move (norms, elementwise, RoPE, the
289
+ fp32 cross-entropy) at 80% of its bandwidth. Embedding on the first stage,
290
+ LM head and loss on the last. The step is m x the slowest stage plus the
291
+ fill and drain, (sum - slowest) / v, at your microbatch count, so it prints
292
+ the predicted slowdown against a perfect split at that count, the
293
+ asymptotic one next to it, and an optimal contiguous `--layers` split with
294
+ the step speedup it predicts.
295
+ 3. **Pipeline bubble**: (p-1)/v over (m + (p-1)/v), and the microbatch count
296
+ that brings it under 15%.
297
+ 4. **Per-stage memory**: weights, gradients and Adam state for that stage's
298
+ parameters after TP / EP / ZeRO sharding, plus activations for the
299
+ microbatches 1F1B keeps in flight on that stage (four on stage 0 at PP 4,
300
+ one on the last), against the card, with the same calibrated upper bound
301
+ as the training-peak estimate. The stage with the loss also holds the fp32
302
+ copy of the seq x vocab logits and its gradient (`--fused-ce` drops it).
303
+ 5. **Sequence imbalance across DP ranks**, with `--seq-hist` (CSV of
304
+ `len,count`): the expected slowest rank over the mean, with per-sequence
305
+ work modelled as a*len + b*len^2 from the graph's own FLOPs, against a
306
+ token-packed batch.
307
+
308
+ Qwen3-8B (151,936-token vocabulary, untied head) at TP 4 x PP 4 x DP 8:
309
+
310
+ ```
311
+ $ npx neurarch layout Qwen/Qwen3-8B --tp 4 --pp 4 --dp 8 --micro 1 --global-batch 512 --seq-len 4096 --gpu h100
312
+ Parallel layout check: Qwen/Qwen3-8B
313
+ 128 GPUs (h100-sxm, 80 GB), 36 blocks, schedule 1f1b, ZeRO 0, 64 microbatches/step, global batch 512
314
+
315
+ stage blocks extra params FLOPs/tok ms/mb* mem-bound vs mean act/mb in-flight peak/GPU upper fits
316
+ 0 1-9 (9) embedding 2.36B 11.33 GFLOP 35 16% 0.92x 1.4 GB 4 16.8 GB 24.1 GB fits
317
+ 1 10-18 (9) - 1.74B 11.33 GFLOP 35 15% 0.92x 1.4 GB 3 12.4 GB 17.8 GB fits
318
+ 2 19-27 (9) - 1.74B 11.33 GFLOP 35 15% 0.92x 1.4 GB 2 11.1 GB 15.8 GB fits
319
+ 3 28-36 (9) head+loss 2.36B 15.06 GFLOP 47 17% 1.24x 1.6 GB 1 14.8 GB 21.2 GB fits
320
+ * predicted fwd+bwd ms per microbatch per GPU: matmuls at 40% of peak FLOPs plus memory-bound bytes (the mem-bound share) at 80% of memory bandwidth. Not measured.
321
+ Stage 3's peak includes 1.2 GB of fp32 logits and their gradient for the loss (--fused-ce if the loss is fused or chunked).
322
+
323
+ Balance: slowest stage 3 at 1.24x the mean stage's predicted time.
324
+ Predicted step at 64 microbatches (t = m x max + (sum - max)): 3094 ms vs 2522 ms balanced, 22.7% slower than a perfect split (24.1% as microbatches grow).
325
+ Rebalanced split 10,10,10,6: 1.02x, predicted 20.0% faster per step at 64 microbatches (2579 ms); 21.2% as microbatches grow.
326
+ Bubble: 4.5% at 64 microbatches/step.
327
+
328
+ warn Stage 3 has 24.1% more predicted time than the mean stage (it also carries the LM head and the loss)
329
+ Per-stage predicted ms per microbatch: 34.7 | 34.6 | 34.6 | 46.7. Every microbatch waits on the slowest stage, so at 64 microbatches per step the predicted step is 22.7% longer than a perfectly balanced split (t = m x max + (sum - max), m = 64 (1F1B)). Predicted from the graph, not measured.
330
+ fix: layersPerStage 10,10,10,6: predicted 20.0% faster steps at 64 microbatches (21.2% as microbatches grow).
331
+
332
+ checked: tp-heads, tp-kv-heads, tp-hidden, tp-ffn, tp-node, cp-seq, batch-arithmetic, pp-over-blocks, stage-balance, pipeline-bubble, stage-memory
333
+ skipped world-size: numGpus not given; the product tp x pp x dp x cp is taken as the world size.
334
+ skipped dp-seq-imbalance: no sequence-length histogram given (seqLenHistogram / --seq-hist); padded or packed fixed-length batches are assumed.
335
+
336
+ Derived from the graph, not measured. A stage's time is the sum of its layers: matmul FLOPs at 40% of the card's peak, plus memory-bound bytes (norms, elementwise ops, RoPE, the fp32 loss) at 80% of its memory bandwidth. Step time uses the pipeline formula m x slowest + (sum - slowest) / v at this layout's microbatch count. On 2 and 4 L4 GPUs the predicted speedup of a split landed within 5.1 points of measured; on H100 this overprices the LM head. Memory uses the same per-layer terms and calibrated upper bound as the training-peak estimate, plus the fp32 logits on the stage with the loss. Nothing here was timed on a GPU.
337
+ ```
338
+
339
+ A Llama-3.1-8B layout (128,256-token vocabulary, the ungated
340
+ `NousResearch/Meta-Llama-3.1-8B` mirror of the config) with a small global
341
+ batch and variable-length data. `hist.csv` is `256,4000 / 1024,3000 /
342
+ 2048,2000 / 4096,1000`:
343
+
344
+ ```
345
+ $ npx neurarch layout NousResearch/Meta-Llama-3.1-8B --tp 4 --pp 4 --dp 8 --micro 1 --global-batch 64 --seq-len 4096 --gpu h100 --seq-hist hist.csv
346
+ Parallel layout check: NousResearch/Meta-Llama-3.1-8B
347
+ 128 GPUs (h100-sxm, 80 GB), 32 blocks, schedule 1f1b, ZeRO 0, 8 microbatches/step, global batch 64
348
+
349
+ stage blocks extra params FLOPs/tok ms/mb* mem-bound vs mean act/mb in-flight peak/GPU upper fits
350
+ 0 1-8 (8) embedding 2.27B 11.28 GFLOP 34 15% 0.93x 1.4 GB 4 16.3 GB 23.4 GB fits
351
+ 1 9-16 (8) - 1.74B 11.28 GFLOP 34 14% 0.93x 1.3 GB 3 12.4 GB 17.8 GB fits
352
+ 2 17-24 (8) - 1.74B 11.28 GFLOP 34 14% 0.93x 1.3 GB 2 11.1 GB 15.8 GB fits
353
+ 3 25-32 (8) head+loss 2.27B 14.43 GFLOP 44 16% 1.21x 1.6 GB 1 14.1 GB 20.1 GB fits
354
+ * predicted fwd+bwd ms per microbatch per GPU: matmuls at 40% of peak FLOPs plus memory-bound bytes (the mem-bound share) at 80% of memory bandwidth. Not measured.
355
+ Stage 3's peak includes 1.1 GB of fp32 logits and their gradient for the loss (--fused-ce if the loss is fused or chunked).
356
+
357
+ Balance: slowest stage 3 at 1.21x the mean stage's predicted time.
358
+ Predicted step at 8 microbatches (t = m x max + (sum - max)): 457 ms vs 403 ms balanced, 13.3% slower than a perfect split (21.0% as microbatches grow).
359
+ Rebalanced split 8,9,9,6: 1.05x, predicted 10.2% faster per step at 8 microbatches (415 ms); 15.7% as microbatches grow.
360
+ Bubble: 27.3% at 8 microbatches/step (17+ for under 15.0%).
361
+ DP sequence imbalance: slowest rank 1.529x the mean; packed 1.016x (monte-carlo).
362
+
363
+ warn Stage 3 has 21.0% more predicted time than the mean stage (it also carries the LM head and the loss)
364
+ Per-stage predicted ms per microbatch: 34.1 | 34.0 | 34.0 | 44.3. Every microbatch waits on the slowest stage, so at 8 microbatches per step the predicted step is 13.3% longer than a perfectly balanced split (t = m x max + (sum - max), m = 8 (1F1B)). Predicted from the graph, not measured.
365
+ fix: layersPerStage 8,9,9,6: predicted 10.2% faster steps at 8 microbatches (15.7% as microbatches grow).
366
+ warn Pipeline bubble is 27.3% of each step
367
+ 1F1B with PP 4 and 8 microbatches per step: (p-1) / (m + (p-1)). Every GPU idles this share of the step.
368
+ fix: Use at least 17 microbatches per step (raise grad-accum, lower micro-batch, or lower DP) to bring it under 15.0%; the interleaved schedule also divides it by its virtual stages.
369
+ warn Uneven sequence lengths make the slowest of 8 DP ranks ~52.9% slower than the mean
370
+ Each rank draws 8 sequences per step from your histogram; work per sequence is modelled as a*len + b*len^2 from this graph's FLOPs (attention is the len^2 term). Every rank waits for the slowest at the gradient all-reduce. Monte Carlo, fixed seed; derived, not measured.
371
+ fix: Pack sequences to a fixed token budget per rank (with per-document attention masking), predicted 1.6%; or bucket by length so ranks in a step draw similar lengths.
372
+
373
+ checked: tp-heads, tp-kv-heads, tp-hidden, tp-ffn, tp-node, cp-seq, batch-arithmetic, pp-over-blocks, stage-balance, pipeline-bubble, stage-memory, dp-seq-imbalance
374
+ skipped world-size: numGpus not given; the product tp x pp x dp x cp is taken as the world size.
375
+
376
+ Derived from the graph, not measured. A stage's time is the sum of its layers: matmul FLOPs at 40% of the card's peak, plus memory-bound bytes (norms, elementwise ops, RoPE, the fp32 loss) at 80% of its memory bandwidth. Step time uses the pipeline formula m x slowest + (sum - slowest) / v at this layout's microbatch count. On 2 and 4 L4 GPUs the predicted speedup of a split landed within 5.1 points of measured; on H100 this overprices the LM head. Memory uses the same per-layer terms and calibrated upper bound as the training-peak estimate, plus the fp32 logits on the stage with the loss. Nothing here was timed on a GPU.
377
+ ```
378
+
379
+ What it is not: a timing. Every ms and every percentage above is predicted
380
+ from the graph and the card's datasheet numbers. It was checked against real
381
+ runs in `scripts/layout-calibration/` of the main repo: Qwen3-0.6B trained
382
+ with 1F1B on 2 and 4 L4s, where the predicted speedup of every split it was
383
+ asked about landed within 5.1 points of measured. On that layout:
384
+
385
+ ```
386
+ $ npx neurarch layout Qwen/Qwen3-0.6B --pp 4 --micro 1 --grad-accum 8 --seq-len 2048 --gpu l4
387
+ Parallel layout check: Qwen/Qwen3-0.6B
388
+ 4 GPUs (l4, 24 GB), 28 blocks, schedule 1f1b, ZeRO 0, 8 microbatches/step, global batch 8
389
+
390
+ stage blocks extra params FLOPs/tok ms/mb* mem-bound vs mean act/mb in-flight peak/GPU upper fits
391
+ 0 1-7 (7) embedding 266M 837.1 MFLOP 65 46% 0.75x 0.7 GB 4 7.8 GB 11.2 GB fits
392
+ 1 8-14 (7) - 110M 837.1 MFLOP 64 44% 0.73x 0.7 GB 3 4.1 GB 5.9 GB fits
393
+ 2 15-21 (7) - 110M 837.1 MFLOP 64 44% 0.73x 0.7 GB 2 3.5 GB 4.9 GB fits
394
+ 3 22-28 (7) head+loss 266M 1.77 GFLOP 156 52% 1.79x 0.7 GB 1 9.5 GB 13.6 GB fits
395
+ * predicted fwd+bwd ms per microbatch per GPU: matmuls at 40% of peak FLOPs plus memory-bound bytes (the mem-bound share) at 80% of memory bandwidth. Not measured.
396
+ Stage 3's peak includes 2.5 GB of fp32 logits and their gradient for the loss (--fused-ce if the loss is fused or chunked).
397
+
398
+ Balance: slowest stage 3 at 1.79x the mean stage's predicted time.
399
+ Predicted step at 8 microbatches (t = m x max + (sum - max)): 1441 ms vs 959 ms balanced, 50.2% slower than a perfect split (78.9% as microbatches grow).
400
+ Rebalanced split 9,9,9,1: 1.16x, predicted 36.2% faster per step at 8 microbatches (1058 ms); 54.0% as microbatches grow.
401
+ Bubble: 27.3% at 8 microbatches/step (17+ for under 15.0%).
402
+
403
+ warn Stage 3 has 78.9% more predicted time than the mean stage (it also carries the LM head and the loss)
404
+ Per-stage predicted ms per microbatch: 65.2 | 63.8 | 63.8 | 156.0. Every microbatch waits on the slowest stage, so at 8 microbatches per step the predicted step is 50.2% longer than a perfectly balanced split (t = m x max + (sum - max), m = 8 (1F1B)). Predicted from the graph, not measured.
405
+ fix: layersPerStage 9,9,9,1: predicted 36.2% faster steps at 8 microbatches (54.0% as microbatches grow).
406
+ warn Pipeline bubble is 27.3% of each step
407
+ 1F1B with PP 4 and 8 microbatches per step: (p-1) / (m + (p-1)). Every GPU idles this share of the step.
408
+ fix: Use at least 17 microbatches per step (raise grad-accum, lower micro-batch, or lower DP) to bring it under 15.0%; the interleaved schedule also divides it by its virtual stages.
409
+ info Tied LM head costed on the last stage
410
+ The checkpoint ties the output head to the embedding (151936 x 1024). The weight is shared; the matmul and the loss are not, and under PP the last stage keeps its own copy of the matrix.
411
+ fix: Nothing to change; this says why the last stage is heavier than its block count suggests.
412
+
413
+ checked: tp-heads, tp-kv-heads, tp-hidden, tp-ffn, tp-node, cp-seq, batch-arithmetic, pp-over-blocks, stage-balance, pipeline-bubble, stage-memory
414
+ skipped world-size: numGpus not given; the product tp x pp x dp x cp is taken as the world size.
415
+ skipped dp-seq-imbalance: no sequence-length histogram given (seqLenHistogram / --seq-hist); padded or packed fixed-length batches are assumed.
416
+
417
+ Derived from the graph, not measured. A stage's time is the sum of its layers: matmul FLOPs at 40% of the card's peak, plus memory-bound bytes (norms, elementwise ops, RoPE, the fp32 loss) at 80% of its memory bandwidth. Step time uses the pipeline formula m x slowest + (sum - slowest) / v at this layout's microbatch count. On 2 and 4 L4 GPUs the predicted speedup of a split landed within 5.1 points of measured; on H100 this overprices the LM head. Memory uses the same per-layer terms and calibrated upper bound as the training-peak estimate, plus the fp32 logits on the stage with the loss. Nothing here was timed on a GPU.
418
+ ```
419
+
420
+ Measured on 4 L4s: the even split's step took 1478 and 1451 ms (two runs;
421
+ predicted 1441), and 9,9,9,1 was 35.3% and 34.4% faster (predicted 36.2%).
422
+ The last rank peaked at 9.7 GB on the even split and 7.3 GB on 9,9,9,1
423
+ (predicted 9.5 and 7.1).
424
+
425
+ Where it is off: on an H100, where the large head matmul runs well above the
426
+ 40% MFU the model assumes, it overprices the LM head (head over one block
427
+ measured at 0.54x and 0.86x the predicted ratio on two models), so there the
428
+ last-stage gap and the speedup of a rebalance read high. The byte counts are
429
+ for the stock PyTorch / transformers kernels; a stack with fused norms and a
430
+ fused loss moves fewer bytes. Calibrate against one short profiled run before
431
+ trusting a percentage on a new card.
432
+
433
+ ## Will this serving launch start, and hold what it promises
434
+
435
+ ```
436
+ npx neurarch serve-check <hf-id | graph.json> --gpu h100 [--gpus 4] [--engine vllm|sglang|llamacpp] \
437
+ [--against <old-hf-id>] [--sampler temperature=0.7,top_p=0.8] [--json] -- <launch command>
438
+ npx neurarch serve-check <hf-id> --gpu l4 --cmd "vllm serve Qwen/Qwen3-8B -tp 4 --max-model-len 32768"
439
+ ```
440
+
441
+ The launch command is the one you would run (`vllm serve ...`,
442
+ `python -m sglang.launch_server ...`, `llama-server -m x.gguf ...`). It reads
443
+ that, the model's `config.json`, `tokenizer_config.json`, `chat_template.jinja`
444
+ and `generation_config.json` from the Hub, and the card. For llama.cpp give the
445
+ repo the GGUF was converted from, since a `.gguf` carries no `config.json`; the
446
+ quant type is read from the file name (`Q4_K_M`, `Q8_0`, ...).
447
+
448
+ Why: across 66,584 public issues in 17 training, fine-tuning and serving repos
449
+ (2024 to 2026), the serving trackers grew 1.58x per month, and inside them the
450
+ fastest-growing classes are the arithmetic ones: parallel config 3.96x,
451
+ quantization / dtype 2.43x, max length and KV cache 2.41x. An empirical study
452
+ of 929 inference-engine bugs (Liu et al., arXiv 2506.09713, ACM TOSEM) puts
453
+ configuration at 23% of root causes. And serving config changes quality
454
+ silently: gpt-oss-120b scored 0.400 against 0.650 on the same weights because
455
+ the repo's Jinja template diverges from the harmony training format
456
+ ([vllm-mlx #568](https://github.com/waybarrios/vllm-mlx/issues/568)); Moonshot
457
+ ships a [vendor verifier](https://github.com/MoonshotAI/K2-Vendor-Verifier)
458
+ for Kimi K2 because hosts mis-set templates, tool-call schemas and sampling.
459
+
460
+ What it checks (exit 1 on any `block`):
461
+
462
+ 1. **Parallel**: TP divides the attention heads; TP past the KV heads
463
+ replicates them (warn) or does not divide them (block); TP divides the FFN
464
+ or expert width, and a block-quantized checkpoint's per-rank slice holds
465
+ whole blocks; TP x PP x DP against `--gpus`; expert parallel against the
466
+ expert count; MoE at TP 4+ without EP (info).
467
+ 2. **Context**: the served length (`--max-model-len`, `--context-length`,
468
+ llama.cpp `-c` per slot) against `max_position_embeddings` scaled by
469
+ `rope_scaling` the way vLLM scales it. vLLM and SGLang refuse to start past
470
+ it, so that is a block; llama.cpp runs with a warning, so that is a warn; a
471
+ learned position table is a block everywhere.
472
+ 3. **Memory**: weights at the dtype or quant method per GPU after TP / PP (and
473
+ EP for experts), KV per token at the cache dtype (`--kv-cache-dtype`,
474
+ `-ctk` / `-ctv`), against card x `--gpu-memory-utilization` (default 0.9),
475
+ x `--mem-fraction-static` (0.88 assumed when unset), or the whole card for
476
+ llama.cpp, which allocates `-c` up front. Prints how many full-length
477
+ sequences fit and compares that with `--max-num-seqs` /
478
+ `--max-running-requests`.
479
+ 4. **Quant and dtype vs the card**: from the table below.
480
+ 5. **Template and sampling**: a missing or overridden chat template; tool
481
+ choice without a parser (vLLM refuses to start); a thinking template with
482
+ no reasoning parser; sampler defaults the engine will apply against
483
+ `generation_config.json` (vLLM reads it by default, `--generation-config
484
+ vllm` turns that off, llama.cpp never reads it); pad == eos; BOS added twice;
485
+ a short cited list of reported mismatches (gpt-oss Jinja vs harmony, Kimi K2
486
+ tool calls, Qwen3 greedy decoding).
487
+ 6. **Change** (`--against <old-model>`): which config keys, template and
488
+ recommended sampling changed, and the memory numbers recomputed for both
489
+ under the same flags.
490
+
491
+ Qwen3-8B on four L4s, with a length past the model and a batch the cache cannot hold:
492
+
493
+ ```
494
+ $ npx neurarch serve-check Qwen/Qwen3-8B --gpu l4 --gpus 4 -- vllm serve Qwen/Qwen3-8B --tensor-parallel-size 4 --max-model-len 65536 --max-num-seqs 256
495
+ Qwen/Qwen3-8B on vLLM
496
+ TP 4 x PP 1 x DP 1, 4 x l4 (sm89), dtype bf16, weights unquantized, KV cache auto
497
+ served length 65536 (--max-model-len 65536); the model's derived maximum 40960
498
+
499
+ memory per GPU budget 21.6 GB, weights 4.10 GB, KV room 17.50 GB
500
+ 36,864 KV bytes per token; one full-length sequence 2.42 GB
501
+ at most 7 concurrent full-length sequences (474,841 tokens)
502
+ weights: 2 bytes per parameter (16-bit)
503
+
504
+ block Served length 65536 is past the model's 40960-token context
505
+ The engine refuses to start ("User-specified max_model_len (65536) is greater than the derived max_model_len (40960)") unless VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 is set, and with it set, positions past the trained length are extrapolated.
506
+ fix: Serve at most 40960, or add rope scaling where the model card supports it, with the card's own original length (e.g. --hf-overrides '{"rope_scaling":{"rope_type":"yarn","factor":F,"original_max_position_embeddings":N}}', with N x F >= 65536; N is the native length the card states, which can be below max_position_embeddings).
507
+ warn --max-num-seqs 256, but at most 7 sequences fit at the full 65536 tokens
508
+ KV capacity is at most 474,841 tokens per replica (each GPU holds its share of every token; 17.5 GB at 36,864 bytes per token, 16-bit). Shorter requests pack more, but once long ones arrive the engine preempts or queues past ~7; the batch size the flag promises is not there.
509
+ fix: Set the flag to what fits (7), shorten the max length, use an fp8 KV cache, or add GPUs as DP replicas.
510
+ info The template has a thinking block and no --reasoning-parser is set
511
+ The reasoning text comes back inside message.content instead of reasoning_content, which breaks clients that hide or strip it.
512
+ fix: Add --reasoning-parser qwen3.
513
+ [...]
514
+
515
+ checked: gpu-count, tp-heads, tp-kv-heads, tp-ffn, context, quant-support, memory, memory-fit, chat-template, sampler
516
+ ```
517
+
518
+ The FP8 build of Qwen3-30B-A3B at TP 4: the experts are 768 wide, a quarter is
519
+ 192, and the checkpoint's FP8 blocks are 128 wide:
520
+
521
+ ```
522
+ $ npx neurarch serve-check Qwen/Qwen3-30B-A3B-FP8 --gpu h100 --gpus 4 -- vllm serve Qwen/Qwen3-30B-A3B-FP8 --tensor-parallel-size 4 --max-model-len 32768
523
+ Qwen/Qwen3-30B-A3B-FP8 on vLLM
524
+ TP 4 x PP 1 x DP 1, 4 x h100-sxm (sm90), dtype bf16, weights fp8, KV cache auto
525
+ served length 32768 (--max-model-len 32768); the model's derived maximum 40960
526
+
527
+ memory per GPU budget 72.0 GB, weights 7.79 GB, KV room 64.21 GB
528
+ 24,576 KV bytes per token; one full-length sequence 0.81 GB
529
+ at most 79 concurrent full-length sequences (2,612,765 tokens)
530
+ weights: fp8 weights (1 byte) with the embedding and LM head kept 16-bit
531
+
532
+ block TP 4 leaves 192 columns of the expert FFN width per rank, not a multiple of the checkpoint's 128-wide quant block
533
+ The checkpoint is block-quantized (weight_block_size [128, ...]); each rank's slice must hold whole blocks, and vLLM refuses at load ("... is not divisible by weight quantization block_n = 128").
534
+ fix: Use a TP size where 768 / TP is a multiple of 128 (1, 2), or enable expert parallelism so experts stay whole.
535
+ info MoE with 128 experts at TP 4 without expert parallelism
536
+ Every expert is split 4 ways, so each rank multiplies 192-wide expert slices and all-reduces after every MoE layer. Expert parallelism keeps experts whole and sends tokens to them instead.
537
+ fix: Try --enable-expert-parallel (EP = TP x DP) and compare throughput.
538
+ [...]
539
+
540
+ checked: gpu-count, tp-heads, tp-kv-heads, tp-ffn, expert-parallel, context, quant-support, memory, memory-fit, chat-template, sampler
541
+ ```
542
+
543
+ The same MoE at TP 8, past its 4 KV heads:
544
+
545
+ ```
546
+ $ npx neurarch serve-check Qwen/Qwen3-30B-A3B --gpu h100 --gpus 8 -- vllm serve Qwen/Qwen3-30B-A3B --tensor-parallel-size 8 --max-model-len 32768
547
+ Qwen/Qwen3-30B-A3B on vLLM
548
+ TP 8 x PP 1 x DP 1, 8 x h100-sxm (sm90), dtype bf16, weights unquantized, KV cache auto
549
+ served length 32768 (--max-model-len 32768); the model's derived maximum 40960
550
+
551
+ memory per GPU budget 72.0 GB, weights 7.63 GB, KV room 64.37 GB
552
+ 24,576 KV bytes per token; one full-length sequence 0.81 GB
553
+ at most 79 concurrent full-length sequences (2,619,097 tokens)
554
+ weights: 2 bytes per parameter (16-bit)
555
+
556
+ warn TP 8 is past 4 KV heads: each KV head is replicated 2x
557
+ It starts, but every GPU stores a full KV head, so the KV cache per GPU stops shrinking at TP 4: the extra ranks hold copies, not more sequences.
558
+ fix: TP 4 with DP 2 serves more sequences on the same GPUs, if the weights fit at TP 4.
559
+ info MoE with 128 experts at TP 8 without expert parallelism
560
+ Every expert is split 8 ways, so each rank multiplies 96-wide expert slices and all-reduces after every MoE layer. Expert parallelism keeps experts whole and sends tokens to them instead.
561
+ fix: Try --enable-expert-parallel (EP = TP x DP) and compare throughput.
562
+ [...]
563
+
564
+ checked: gpu-count, tp-heads, tp-kv-heads, tp-ffn, expert-parallel, context, quant-support, memory, memory-fit, chat-template, sampler
565
+ ```
566
+
567
+ FP8 on an A100 (sm80): it loads, as weight-only:
568
+
569
+ ```
570
+ $ npx neurarch serve-check Qwen/Qwen3-8B --gpu a100-40g -- vllm serve Qwen/Qwen3-8B --quantization fp8 --max-model-len 32768 --reasoning-parser qwen3
571
+ Qwen/Qwen3-8B on vLLM
572
+ TP 1 x PP 1 x DP 1, 1 x a100-40g (sm80), dtype bf16, weights fp8, KV cache auto
573
+ served length 32768 (--max-model-len 32768); the model's derived maximum 40960
574
+
575
+ memory per GPU budget 36.0 GB, weights 9.44 GB, KV room 26.56 GB
576
+ 147,456 KV bytes per token; one full-length sequence 4.83 GB
577
+ at most 5 concurrent full-length sequences (180,150 tokens)
578
+ weights: fp8 weights (1 byte) with the embedding and LM head kept 16-bit
579
+
580
+ warn fp8 on A100 (40 GB) (sm80) is not native: it runs on a fallback kernel
581
+ Native fp8 kernels need sm89+. On this card it runs as weight-only W8A16 through the FP8 Marlin kernel: weights are stored in fp8, the matmuls run in 16 bits, so the memory saving is there and the FP8 compute speedup is not.
582
+ fix: Expect the memory saving and not the speedup; for native fp8 use an sm89+ card.
583
+ source: vLLM docs, FP8 W8A8: "FP8 computation is supported on NVIDIA GPUs with compute capability >= 8.9"; "FP8 models will run on compute capability >= 7.5 (Turing) as weight-only W8A16, utilizing FP8 Marlin" (docs.vllm.ai/en/latest/features/quantization/llm_compressor/fp8/)
584
+ [...]
585
+
586
+ checked: gpu-count, tp-heads, tp-kv-heads, context, quant-support, memory, memory-fit, chat-template, sampler
587
+ ```
588
+
589
+ gpt-oss-20b (MXFP4 experts) on an A100. Current vLLM runs it there through the
590
+ Marlin MXFP4 kernel, so this is a warn and not a block; on a T4 it is a block:
591
+
592
+ ```
593
+ $ npx neurarch serve-check openai/gpt-oss-20b --gpu a100-80g -- vllm serve openai/gpt-oss-20b --max-num-seqs 64
594
+ openai/gpt-oss-20b on vLLM
595
+ TP 1 x PP 1 x DP 1, 1 x a100-80g (sm80), dtype bf16, weights mxfp4, KV cache auto
596
+ served length 131072 (not set: the engine derives it from the config); the model's derived maximum 131072
597
+
598
+ memory per GPU budget 72.0 GB, weights 13.74 GB, KV room 58.26 GB
599
+ 24,600 KV bytes per token; one full-length sequence 3.22 GB
600
+ at most 18 concurrent full-length sequences (2,368,099 tokens)
601
+ weights: MXFP4 experts at 4.25 bits (4-bit values plus a shared 8-bit scale per 32) and everything else 16-bit, as gpt-oss's modules_to_not_convert lists
602
+
603
+ warn mxfp4 on A100 (80 GB) (sm80) is not native: it runs on a fallback kernel
604
+ Native mxfp4 kernels need sm90+. On this card it runs on Ampere and Ada through the Marlin MXFP4 MoE kernel (weight-only), not the Hopper / Blackwell MXFP4 path.
605
+ fix: Expect the memory saving and not the speedup; for native mxfp4 use an sm90+ card.
606
+ source: vLLM gpt-oss recipe: "GPT-OSS works on Ampere devices by default, using the TRITON_ATTN attention backend and Marlin MXFP4 MoE"; the quantization table footnote: "Turing does not support Marlin MXFP4" (docs.vllm.ai/projects/recipes/en/latest/OpenAI/GPT-OSS.html)
607
+ warn --max-num-seqs 64, but at most 18 sequences fit at the full 131072 tokens
608
+ KV capacity is at most 2,368,099 tokens per replica (each GPU holds its share of every token; 58.3 GB at 24,600 bytes per token, 16-bit). Shorter requests pack more, but once long ones arrive the engine preempts or queues past ~18; the batch size the flag promises is not there.
609
+ fix: Set the flag to what fits (18), shorten the max length, use an fp8 KV cache, or add GPUs as DP replicas.
610
+ info gpt-oss: the Jinja chat template in the repo was reported to diverge from the harmony training format (not vLLM)
611
+ Same weights, same payload, same harness: 0.400 on vllm-mlx against 0.650 on Ollama on a 20-task agentic benchmark. The bundled template differs from harmony in developer-block order, tool-call header placement and tool-result wrapping. An engine that renders the Jinja template inherits that; vLLM renders gpt-oss through openai-harmony instead.
612
+ fix: No change needed on this engine; keep it in mind if the deployment moves.
613
+ source: github.com/waybarrios/vllm-mlx/issues/568; vLLM gpt-oss recipe (openai-harmony rendering)
614
+ [...]
615
+
616
+ checked: gpu-count, tp-heads, tp-kv-heads, expert-parallel, context, quant-support, memory, memory-fit, chat-template, known:gpt-oss-jinja-vs-harmony, sampler
617
+ ```
618
+
619
+ llama.cpp with `-c` past the model's context, and llama.cpp's own sampling
620
+ defaults against the model's:
621
+
622
+ ```
623
+ $ npx neurarch serve-check Qwen/Qwen3-8B --gpu l4 -- llama-server -m Qwen3-8B-Q4_K_M.gguf -c 65536 -ngl 99 -ctk q8_0 -ctv q8_0
624
+ Qwen/Qwen3-8B on llama.cpp
625
+ 1 x l4 (sm89), weights Q4_K_M, KV cache q8_0/q8_0
626
+ served length 65536 (-c 65536 (one unified KV buffer, so one sequence may use all of it)); the model's derived maximum 40960
627
+
628
+ memory per GPU card 24.0 GB, weights 5.01 GB, KV for 65,536 tokens 5.13 GB (allocated up front), total 10.15 GB
629
+ 78,336 KV bytes per token; one full-length sequence 5.13 GB
630
+ weights: Q4_K_M at 4.8944 bits per weight (llama.cpp tools/quantize/README.md, bits/weight measured on meta-llama/Llama-3.1-8B); mixed per-tensor types make this approximate
631
+
632
+ warn Served length 65536 is past the model's 40960-token context
633
+ llama.cpp runs past n_ctx_train with a warning; rotary positions keep computing, and quality past the trained length is not something the config vouches for.
634
+ fix: Serve at most 40960, or add rope scaling where the model card supports it, with the card's own original length (e.g. --rope-scaling yarn --rope-scale F --yarn-orig-ctx N, with N x F >= 65536; N is the native length the card states, which can be below max_position_embeddings).
635
+ warn Sampling defaults differ from the model's generation_config.json: temperature 0.8, top_k 40
636
+ temperature 0.8 (recommended 0.6, from llama.cpp default); top_k 40 (recommended 20, from llama.cpp default). Applies to every request that does not send its own value. Model makers have traced host-to-host quality gaps to exactly this (Moonshot: "a significant portion" of discrepancies came from decoding-parameter misuse).
637
+ fix: Pass --temp 0.6 --top-p 0.95 --top-k 20 (llama.cpp does not read generation_config.json).
638
+ source: kimi.com/blog/kimi-vendor-verifier
639
+ [...]
640
+
641
+ checked: context, memory, memory-fit, chat-template, sampler
642
+ not checked: parallel: llama.cpp splits whole layers (and their KV) across GPUs by default (--split-mode layer), so no head or width divisibility applies.
643
+ not checked: quant-support: llama.cpp's CUDA backend runs every GGUF type on these cards; support is not a per-architecture table.
644
+ ```
645
+
646
+ Swapping a model behind the same flags:
647
+
648
+ ```
649
+ $ npx neurarch serve-check Qwen/Qwen3-8B --gpu h100 --against Qwen/Qwen2.5-7B-Instruct -- vllm serve Qwen/Qwen3-8B --max-model-len 32768 --reasoning-parser qwen3
650
+ Qwen/Qwen3-8B on vLLM
651
+ TP 1 x PP 1 x DP 1, 1 x h100-sxm (sm90), dtype bf16, weights unquantized, KV cache auto
652
+ served length 32768 (--max-model-len 32768); the model's derived maximum 40960
653
+
654
+ memory per GPU budget 72.0 GB, weights 16.38 GB, KV room 55.62 GB
655
+ 147,456 KV bytes per token; one full-length sequence 4.83 GB
656
+ at most 11 concurrent full-length sequences (377,185 tokens)
657
+ weights: 2 bytes per parameter (16-bit)
658
+
659
+ [...]
660
+ info model_type: qwen2 -> qwen3
661
+ A different architecture family: the engine loads a different model class, and every family-specific flag (tool-call parser, reasoning parser, chat template) must be re-chosen.
662
+ info num_hidden_layers: 28 -> 36
663
+ Layer count changes weights and KV per token; PP stage splits must be redone.
664
+ [...]
665
+ info num_key_value_heads: 4 -> 8
666
+ KV heads change KV bytes per token and where TP starts replicating KV.
667
+ [...]
668
+ info vocab_size: 152064 -> 151936
669
+ Vocabulary changes the embedding and LM head; the tokenizer changes with it, so token budgets and stop ids measured on the old model no longer apply.
670
+ info max_position_embeddings: 32768 -> 40960
671
+ The longest servable length changes; --max-model-len / --context-length may now be past it or leave length unused.
672
+ [...]
673
+ info chat_template: hash 6aca5d55 -> hash 1bae85c9
674
+ Every chat request renders differently: re-render a reference conversation (with tool calls) and re-run the evals that depend on format.
675
+ info generation_config.temperature: 0.7 -> 0.6
676
+ The recommended sampling changes; a gateway that pins the old value now overrides the new model's recommendation.
677
+ [...]
678
+ info KV bytes per token per GPU: 57,344 -> 147,456
679
+ Same engine flags and card, computed for both models.
680
+ info concurrent full-length sequences (upper bound): 30 -> 11
681
+ Same engine flags and card, computed for both models.
682
+ [...]
683
+
684
+ checked: gpu-count, tp-heads, tp-kv-heads, context, quant-support, memory, memory-fit, chat-template, sampler, change
685
+ ```
686
+
687
+ (`[...]` marks findings left out here for length; the command prints them all.
688
+ Every run ends with the line: "Derived from config.json, the engine flags and
689
+ the card, not measured. ...")
690
+
691
+ The quant support table, and where each row comes from:
692
+
693
+ | method | native from | still runs from (how) | source |
694
+ | --- | --- | --- | --- |
695
+ | fp8 | sm89 (Ada, Hopper, Blackwell) | sm75, weight-only W8A16 via FP8 Marlin | [vLLM FP8 W8A8](https://docs.vllm.ai/en/latest/features/quantization/llm_compressor/fp8/) |
696
+ | mxfp4 (gpt-oss) | sm90 (Hopper, Blackwell) | sm80, Marlin MXFP4 MoE; not Turing | [vLLM gpt-oss recipe](https://docs.vllm.ai/projects/recipes/en/latest/OpenAI/GPT-OSS.html), [quantization table](https://docs.vllm.ai/en/latest/features/quantization/) |
697
+ | nvfp4 | sm100 (Blackwell FP4 tensor cores) | sm75, weight-only via Marlin FP4 | [quantization table](https://docs.vllm.ai/en/latest/features/quantization/) |
698
+ | awq | sm75 | | [quantization table](https://docs.vllm.ai/en/latest/features/quantization/) |
699
+ | gptq | sm70 | | same |
700
+ | awq_marlin / gptq_marlin | sm75 | | same |
701
+ | int8 (W8A8) | sm75 | | same |
702
+ | bitsandbytes | sm70 | | same |
703
+ | gguf (in vLLM) | sm70 | | same |
704
+ | bf16 dtype | sm80 | auto dtype casts to fp16 below it | vLLM's own error: "Bfloat16 is only supported on GPUs with compute capability of at least 8.0" |
705
+
706
+ GGUF bits per weight come from llama.cpp's
707
+ [quantize README](https://github.com/ggml-org/llama.cpp/blob/master/tools/quantize/README.md)
708
+ (measured on Llama-3.1-8B), and llama.cpp's sampler defaults from its
709
+ [server README](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md).
710
+ SGLang shares most kernels with vLLM but publishes no such table, so its quant
711
+ findings use vLLM's.
712
+
713
+ What it is not: a launch. Every number is derived from files; the engine's own
714
+ reserve (activation profiling, CUDA graphs, communication buffers) is not
715
+ counted, so every capacity is an upper bound. Template checks read files and
716
+ do not render a conversation, so "no template finding" does not prove two
717
+ stacks produce the same prompt. Not covered: attention-backend and kernel
718
+ numerics, fp8 KV cache support per backend, LoRA adapters, speculative
719
+ decoding, prefix caching, chunked prefill and disaggregated prefill / decode,
720
+ and anything about throughput or latency.
721
+
225
722
  ## What it refuses to do
226
723
 
227
724
  - **No safetensors index on the Hub** → it prints nothing and says so. A
@@ -243,6 +740,8 @@ npx neurarch <model-id> # bert-base-uncased, Qwen/Qwen3-8B, ...
243
740
  npx neurarch <model-id> --layers # every layer, not the first 12
244
741
  npx neurarch <model-id> --json # machine-readable
245
742
  npx neurarch rightsize jobs.csv # requested vs needed GPU over past jobs
743
+ npx neurarch layout <model-id> --tp 4 --pp 4 --dp 8 --global-batch 512 --seq-len 4096 # parallel split check
744
+ npx neurarch serve-check <model-id> --gpu h100 -- vllm serve <model-id> ... # serving launch check
246
745
  ```
247
746
 
248
747
  Exit code is `1` when the model cannot be read or a check blocks, `0`
@@ -253,9 +752,9 @@ Set `HF_TOKEN` to read a gated repo. The token is sent only to
253
752
 
254
753
  ## Related
255
754
 
256
- - <https://neurarch.com/compare> — the same comparison for two models, in a
755
+ - <https://neurarch.com/compare>: the same comparison for two models, in a
257
756
  browser, no account
258
- - `POST https://www.neurarch.com/api/v1/check` — run the checks on a graph of
757
+ - `POST https://www.neurarch.com/api/v1/check`: run the checks on a graph of
259
758
  your own
260
- - [`neurarch-lint`](https://www.npmjs.com/package/neurarch-lint) — the same
759
+ - [`neurarch-lint`](https://www.npmjs.com/package/neurarch-lint): the same
261
760
  checks against PyTorch source