Skip to content

TensorFold 0.3.0: CUDA engines for DGX Spark - #8

Merged
ashhart merged 6 commits into
mainfrom
cuda-engine
Sep 26, 2026
Merged

ashhart merged 6 commits into
mainfrom
cuda-engine

Conversation

@ashhart

@ashhart ashhart commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

TensorFold on NVIDIA GPUs. tensorfold serve picks CUDA on Linux, reads the same MLX 4-bit checkpoints from Hugging Face, and runs one GPU or two (--tp 2 --rank R --master HOST, one rank per DGX Spark). Drafted output is byte-identical to serial decoding on the same engine; "draft": false gives the serial reference.

  • The shared OpenAI server for the CUDA engines and the CLI's CUDA backend (version 0.3.0).
  • Qwen3.8-27B with z-lab's DFlash2, one or two GPUs.
  • Qwen3.8 Flash Next with its MTP head, one or two GPUs.
  • GLM-5.3-Flash on two GPUs, a new CUDA-only family.
  • Docs: a DGX Spark section in the README and runbook, the CUDA recipe book, adding a CUDA family, and the GLM recipe. Third-party notices for transformers and mlx-vlm code, with the Apache-2.0 text.

Validated on DGX Spark the way a user runs it: pip install into a fresh nvcr.io/nvidia/pytorch:26.07-py3 container, tensorfold serve, and tools/bench_openai.py against vLLM with MTP=3 through the same client (decode tok/s, one stream, 64-token replies, median of seeds 1234-1238):

Model Sparks Code, sampled Chat, sampled Code, greedy Chat, greedy
Qwen3.8-27B + DFlash2 1 49.6 vs 17.7 45.8 vs 15.0 49.2 vs 17.7 45.9 vs 17.0
Qwen3.8-27B + DFlash2 2 82.4 vs 33.1 58.9 vs 30.4 76.2 vs 31.6 71.1 vs 30.5
Qwen3.8 Flash Next 1 68.3 vs 42.4 58.5 vs 33.2 73.1 vs 40.9 60.2 vs 37.6
Qwen3.8 Flash Next 2 103.8 vs 46.4 84.0 vs 41.4 96.2 vs 55.2 100.2 vs 50.7
GLM-5.3-Flash 2 49.4 vs 24.5 43.3 vs 24.3 66.3 vs 32.2 45.2 vs 24.7

Every configuration also passed the CUDA tests from the installed package, drafted replies equal to "draft": false replies (9 of 9 per configuration), and prefix reuse. GLM also passed a byte-for-byte check of its checkpoint reader and a live check of the 400 for requests past --context. Some runs on GB10 ran at half speed during bursts of page migration by the kernel; the recipes say where. The Mac test suite passes.

- `tensorfold serve` picks CUDA on Linux (`--backend auto|mlx|cuda`) and
  calls the family's `cuda_engine`; `--tp 2 --rank R --master HOST` splits a
  model over two machines, one GPU each, and rank 1 follows rank 0.
- `tensorfold.cuda.server`: the OpenAI routes for the CUDA engines, the
  model's chat template, streaming, tool calls, thinking, sampling defaults
  from generation_config.json, and `"draft": false` for the serial reference.
- `tools/bench_openai.py`: the single-stream client every speed in the docs
  was measured with.
- Linux installs skip MLX and ship the kernels' .cu and .cpp sources; the
  CUDA tests in tests/cuda run only where PyTorch sees a GPU.
- Version 0.3.0.
The CUDA engine for `qwen3_5` reads the same MLX 4-bit checkpoint and drafts
with z-lab's DFlash2, exact: every kernel on the verify path gives a row the
bits it gets alone, so drafted output equals serial decoding byte for byte.

- Kernels (families/qwen3_5/cuda/README.md lists them): a row-invariant 4-bit
  lane matmul in Triton over weights regrouped at load, tree attention and a
  gated-delta-rule tree in CUDA, fused glue, keyed sampling, and DFlash2 at 4
  bits with fused kernels.
- Two GPUs: tensor parallel with fp32 partial sums gathered and added in rank
  order, the head split by vocabulary, the drafter split over both ranks;
  the ranks refuse to start with different settings.
- 12-row verify windows, in-place commits with one launch for every DeltaNet
  layer, prefix reuse, `"draft": false`, and an optional per-round trace.
- Measured through `tensorfold serve` on DGX Spark: 49.6 / 45.8 tok/s on one
  Spark and 82.4 / 58.9 on two (code / chat, sampled), 2.8-3.1x and 1.9-2.5x
  vLLM with MTP=3 through the same client.
The CUDA engine for `qwen4_exp` reads the MLX 4-bit MTP checkpoint and drafts
with its MTP head: chains of up to 6 drafts that stop under 30% confidence,
the verify forward and the draft chain captured as CUDA graphs (with the
NCCL all-gathers inside on two GPUs). Drafted output equals serial decoding
byte for byte.

- Kernels in families/qwen4_exp/cuda: row-invariant 4-bit matmuls and grouped
  expert kernels, gated DeltaNet in CUDA, hyper-connection glue, sparse
  attention, keyed sampling on the GPU.
- The draft head reads 79,591 token ids (draft_vocab.txt), chosen from public
  text only: ids below 65,536, the added tokens, and ids common in public
  source code and docs.
- Prefix reuse, `"draft": false`, and a start-up check that both ranks were
  given the same settings.
- Measured through `tensorfold serve` on DGX Spark: 68.3 / 58.5 tok/s on one
  Spark and 103.8 / 84.0 on two (code / chat, sampled), 1.6-1.8x and 1.7-2.2x
  vLLM with MTP=3 through the same client.
A new family, `glm5_next`, CUDA only: the 182 GB MLX 4-bit checkpoint split
over two DGX Sparks, each rank reading its half straight from the pulled
checkpoint. Drafted output equals serial decoding byte for byte.

- Kernels in families/glm5_next/cuda: row-invariant 4-bit matmuls and grouped
  expert kernels, Kimi delta attention in CUDA, DeepSeek sparse attention with
  its indexer, hyper-connection glue, CUDA graphs on both ranks.
- One default draft policy: sampled requests draft with the MTP head; each
  greedy request measures the MTP head against DFlash2 and keeps whichever
  commits more tokens per millisecond. A request can name another policy.
- Prefix reuse, `"draft": false`, and a 400 before streaming for a request
  longer than the server's context (`--context`, 2,051 tokens by default).
- Measured through `tensorfold serve` on two DGX Sparks: 49.4 / 43.3 tok/s
  sampled and 66.3 / 45.2 greedy (code / chat), 1.78-2.06x the Mia-AiLab
  vLLM recipe with MTP=3 through the same client.
- THIRD_PARTY_NOTICES.md: Qwen3.8 Flash Next's n-gram id helpers (in the MLX
  model since 0.2.0 and now in its CUDA engine) are translated from
  transformers' modeling_qwen4_exp.py (Apache-2.0) and match mlx-vlm's
  (MIT); what the CUDA engines follow; the licenses of the GLM checkpoint and
  of its optional DFlash2 draft model (CC BY-NC-ND 4.0, non-commercial).
- LICENSES/Apache-2.0.txt, and the license files in the wheel's metadata.
- README: a DGX Spark section (install in NVIDIA's container, one or two
  Sparks, the numbers against vLLM with MTP), the new serve flags, and the
  layout; RUNBOOK: DGX Spark steps.
- docs/recipes/cuda.md: the method and the traps on CUDA;
  adding-a-cuda-family.md: the engine interface, the exactness tests and how
  to measure; glm-5.3-flash.md: the new recipe; DGX Spark sections for the 27B
  and Flash Next.
- assets/tensorfold-cuda-banner.png.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant