# TensorFold

> Exact speculative LLM decoding on Apple Silicon (MLX) and NVIDIA GPUs behind an OpenAI-compatible API

- Category: Models & Inference / Local Runtimes
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/ashhart/TensorFold
- Canonical page: https://ai-tldr.dev/tools/tensorfold/
- Updated: 2026-10-03

## In short

TensorFold is Exact speculative LLM decoding on Apple Silicon (MLX) and NVIDIA GPUs behind an OpenAI-compatible API. It sits in the Local Runtimes category of the Models & Inference tools and is open-source, written in Python and licensed Apache-2.0. To get started: install on a Mac.

## Overview

TensorFold is a Python server that runs language models on Apple Silicon Macs through MLX and on NVIDIA GPUs through CUDA, and exposes them through an OpenAI-compatible API. Both backends serve chat completions, completions, the OpenAI Responses API (`/v1/responses`) and the Anthropic Messages API (`/v1/messages`) at `http://127.0.0.1:8080/v1` by default, so existing SDKs and agents only need a new base URL.

Rather than one generic engine, each supported model family supplies its own kernels and its own draft verification. The project supports a fixed list of checkpoints, among them Nemotron 3.5 Lightning, Qwen3.8-27B, Qwen3.8 Flash Next, GLM-5.3-Flash, Gemma 4 26B-A4B and DeepSeek-V4-Flash, with drafts coming from a model's own MTP head, a DFlash or DSpark draft model, or copies of the prompt context. `tensorfold models` lists the families and checkpoints.

Its defining rule is exact decoding: a drafted token is accepted only when it equals the token the same engine would produce serially, and concurrent streams on the MLX engine must match their solo output. The README is explicit that exactness holds against the same engine, weights, runtime and settings, not between MLX and CUDA or between quantizations. On NVIDIA the CUDA kernels need compute capability 8.9 or newer (Ada, Hopper, Blackwell, including the DGX Spark's GB10); RTX 30 cards are refused at startup. The project is Apache-2.0 from version 0.6.0 (earlier releases were MIT) and requires Python 3.11 or newer.

## What it does

- OpenAI chat completions, completions and Responses plus Anthropic Messages endpoints on both the MLX and CUDA backends
- Exact speculative decoding: MTP heads, DFlash/DSpark draft models and context copies, with drafts accepted only when they match serial output (`"draft": false` per request to compare)
- Per-family kernels for MLX affine quantized checkpoints, plus NVFP4, FP8 and experimental EXL3 checkpoints on CUDA
- Memory-aware admission, shared decode rounds across concurrent requests (`--parallel`), retained conversation prefixes and on-disk prefix snapshots on MLX
- Optional image input with the `vision` extra and `--vision` for supported GLM-5.3-Flash and Qwen checkpoints
- Two-rank CUDA execution (`--tp 2`), a macOS launchd service manager (`tensorfold service`) and a live dashboard (`tensorfold tui`)

## Getting started

TensorFold needs Python 3.11 or newer and either an Apple Silicon Mac (MLX 0.32.2 or newer, installed by pip) or an NVIDIA GPU with compute capability 8.9 or newer. These steps follow the project's README and installation runbook.

1. Install on a Mac

   Install from GitHub into a virtual environment, then list the supported model families. Homebrew also works: `brew install ashhart/tensorfold/tensorfold`.

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install git+https://github.com/ashhart/TensorFold.git
tensorfold --version
tensorfold models
```

2. Check, download and serve a model

   `info` reads the configuration without fetching weights, `pull` downloads ahead of time, and `serve` completes any missing download. This example uses Nemotron with its included MTP head.

```bash
tensorfold info TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit
tensorfold pull TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit
tensorfold serve TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit --name local-model --context 8192
```

3. Send a first request

   From another terminal, check health, list models and call chat completions. Use the ID from `/v1/models` if you started without `--name`.

```bash
curl -fsS http://127.0.0.1:8080/health
curl -fsS http://127.0.0.1:8080/v1/models
curl -fsS http://127.0.0.1:8080/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"local-model","messages":[{"role":"user","content":"Say hello in one sentence."}],"max_tokens":128}'
```

4. Serve on an NVIDIA GPU

   Use NVIDIA's PyTorch container for the CUDA toolchain; there is no `cuda` install extra. The first start compiles kernels. On CUDA, Qwen3.8-27B needs its DFlash2 drafter unless you pass `--no-drafts`.

```bash
docker run -it --gpus all --ipc=host --network host nvcr.io/nvidia/pytorch:26.07-py3
python -m pip install git+https://github.com/ashhart/TensorFold.git
tensorfold pull TensorFold/Qwen3.8-27B-MLX-4bit z-lab/Qwen3.8-27B-DFlash2
tensorfold serve TensorFold/Qwen3.8-27B-MLX-4bit --name local-model --host 0.0.0.0 --port 8080
```

5. Keep it updated

   `tensorfold update --check` looks for a release and `tensorfold update` installs it; restart the server afterwards. A Homebrew install upgrades with `brew upgrade tensorfold`.

```bash
tensorfold update --check
tensorfold update
```

## When to use it

- Serve a supported open-weight model such as Qwen3.8-27B or Nemotron 3.5 Lightning locally on an Apple Silicon Mac with drafted decoding that does not change the output
- Run the same models on a DGX Spark, RTX 40/50 series or Hopper/Blackwell GPU, or split one across two CUDA ranks
- Point OpenAI- or Anthropic-SDK clients and coding agents at a local backend by changing only the base URL
- Keep a model running as a login service on a Mac with `tensorfold service` and monitor it with `tensorfold tui`

## Version history

- 2026-10-03 v0.6.5: Qwen3.6-35B-A3B drafts with its own MTP layer on Macs, Nemotron on CUDA drafts as deep as measured per-GPU costs allow, and both servers accept API keys via `--api-key`.
