Repository navigation
TensorFold 0.3.0: CUDA engines for DGX Spark - #8
Merged
Merged
Conversation
- `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.
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.
TensorFold on NVIDIA GPUs.
tensorfold servepicks 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": falsegives the serial reference.Validated on DGX Spark the way a user runs it:
pip installinto a freshnvcr.io/nvidia/pytorch:26.07-py3container,tensorfold serve, andtools/bench_openai.pyagainst vLLM with MTP=3 through the same client (decode tok/s, one stream, 64-token replies, median of seeds 1234-1238):Every configuration also passed the CUDA tests from the installed package, drafted replies equal to
"draft": falsereplies (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.