Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
populated large vision graphs. Canonical vision comparisons cover at most
256 live patches.

[ ] Compare Inkling 2 output across four DGX Sparks, where cross-host hidden
reductions round partial sums to BF16, against single-host FP32 reductions.
Also run the unverified Inkling 2 combinations: effort-zero cases of
tests/server/test_inkling2.py on Sparks, single-host SM120 preparation
after the multi-host changes and at 32 concurrent requests, and --roce-ring
and --roce-chain routing. Planning at 32 requests and 8192-token chunks
predicts 22.9 GiB of KV pages per rank where native loading allocates
12.4 GiB; correct the declared rank costs from a measured GB10 memory
report.

[ ] Fix native TP4 shutdown reporting "free(): double free detected in tcache 2"
after server drain with Inkling 2 cores. Reproduces with compiled and
uncompiled graphs; preserve the successful request drain and GPU release.
Expand Down
81 changes: 75 additions & 6 deletions docs/model-preparation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1412,18 +1412,21 @@ flare-cli/target/release/flare run /data/flare-runtime/minimax-m3.1-flash-tp4.sa
## Inkling 2 Small NVFP4

The `inkling-2-small-nvfp4` alias selects the local checkpoint
`/data/models/Inkling-2-Small-NVFP4`. Preparation requires four SM120 GPUs and
the bundled DSpark weights in `mtp.safetensors`. Target experts retain the
`/data/models/Inkling-2-Small-NVFP4`. Preparation requires four SM120 GPUs on
one host, or four SM121 GPUs with one rank per host, and the bundled DSpark
weights in `mtp.safetensors`. Target experts retain the
checkpoint's static NVFP4 scales, with A4 activations for prefill and A16
activations for decoding and speculative verification. DSpark uses MXFP8
feed-forward projections and BF16 attention and recurrent state. Target and
draft attention use b12x. The pinned FlashInfer dependency provides relative
bias, private paged-attention tails, and explicit expert activation selection.

The recipe declares a 1048576-token context, eight concurrent requests,
4096-token prefill chunks, and seven draft tokens per round. Adaptive packed
verification has 64 target rows and a 64-graph budget, plus width-one graphs
that preserve DSpark context. The vision encoder accepts padded 20-pixel
The recipe declares a 1048576-token context, a default of eight concurrent
requests (maximum 32), 4096-token prefill chunks, and seven draft tokens per
round. Adaptive packed verification defaults to a 128-token capacity (at most
64 packed target rows at the default eight-request concurrency) and a 64-graph
budget, plus width-one graphs that preserve DSpark context. The vision encoder
accepts padded 20-pixel
patches, merges each 2-by-2 group, and supports four images per request and
four concurrent image requests. Native TMLv0 encoding and parsing provide
reasoning, tool calls, and structured responses. Sampling defaults are
Expand Down Expand Up @@ -1464,6 +1467,72 @@ FLARE_RUN_CUDA_TESTS=1 FLARE_INKLING2_TEST_URL=http://127.0.0.1:8000 \
.venv/bin/python -m pytest tests/server/test_inkling2.py -k default-effort -q
```

Each rank holds a quarter of the 344 GB checkpoint, so four-host DGX Spark
serving runs one rank on each of four GB10 (SM121) hosts, reducing through
RoCEnante over their ConnectX-7 ports. Ranks on one host reduce FP32 partial
sums; ranks on separate hosts round each partial sum to BF16 before the
reduction, because RoCEnante reduces BF16. One runtime carries the hidden
reductions, the vocabulary gathers of FP32 logits as BF16 column pairs, the
sampling and log-probability gathers, and the sampling broadcasts. Multi-host
export requires the checkpoint directory on rank zero only; peers read their
tensor ranges from it.

The 32-request, 8192-token configuration was qualified on four DGX Sparks
(the recipe defaults `--speculative-token-capacity` to 128, matching this
export). On rank zero, whose preparation address is `10.200.0.13`, with
`[memory] reserve = "4G"`:

```sh
ulimit -Sn 65536
.venv/bin/ignition export /data/models/Inkling-2-Small-NVFP4 \
--ranks 4 --rendezvous 10.200.0.13:29630 --gpus 0 \
--max-concurrency 32 --image-concurrency 4 \
--prefill-chunk-size 8192 --mtp-draft-tokens 7 \
--speculative-token-capacity 128 --speculative-graph-budget 64 \
--autotune-effort default
```

On each peer, with its rank from 1 through 3:

```sh
.venv/bin/ignition join 10.200.0.13:29630 --rank 1 --ranks 4
```

Serve with `flare run CACHE_ENTRY --rank 0 --rendezvous 10.200.0.13:29800
--gpus 0 --mtp-draft-tokens 7 --no-history-drafts --memory-limit=-0G` on rank
zero and `flare run --rank R --rendezvous 10.200.0.13:29800 --gpus 0` with the
same serving options on each peer. `--memory-limit=-0G` replaces the exported
4 GiB reserve, so the cache takes everything outside the integrated-memory
allowances, which leave about 8 GiB available on each host. Follow the
[multi-host guide](multi-host.md) for preparation authentication, rank
placement, and publisher acceptance. Hosts that share a switch need neither
`--roce-ring` nor `--roce-chain`.

Disk: rank zero holds the complete core, 351 GB for this configuration. Each
peer needs about 87 GB for the payloads it prepares and another 87 GB for the
rank core it receives when serving; the prepared payloads can be removed after
export. Drop the page cache on every host before export and before serving so
cached checkpoint and peer rank-core files do not exhaust unified memory.

On four DGX Sparks (GB10, SM121, 121 GiB each) joined by a switch, with one
pair also cabled directly, this configuration compiled and captured all 152
graphs in 1 h 26 min. The lowest available memory during export was 11.5 GiB on
rank zero and 12.5 to 13.1 GiB on the peers; the captured graph pool uses
2840 MiB per rank. Native loading used 90.1 to 90.2 GiB per rank and, with
`--memory-limit=-0G`, allocated a 16.5 GiB cache: 3,252,224 KV-token slots and
106 shared snapshot slots, limited by memory, leaving 7.8 to 8.3 GiB available
per host after loading and at least 7.6 GiB during 32 concurrent requests. With
the exported 4 GiB reserve the cache is 12.4 GiB, 2,392,064 KV-token slots and
78 snapshot slots, with 12.0 to 12.5 GiB available. The service passed the
seven default-effort tests of `tests/server/test_inkling2.py`, 32 concurrent
requests, streaming, and an 18,832-token prompt with a 2048-token output limit,
with no change in the RoCE loss counters. A core without drafting and vision,
prepared for one request with 512-token chunks, loaded 82.9 GiB per rank and
passed text, streaming, and a 7,150-token prompt. Not run: single-host SM120
preparation after the multi-host changes or at 32 concurrent requests,
effort-zero tests on Sparks, `--roce-ring`, `--roce-chain`, and a numerical
comparison of BF16 cross-host reductions against single-host FP32 output.

## Muse Spark Open

The `muse-spark-open-nvfp4` alias selects
Expand Down
3 changes: 2 additions & 1 deletion docs/roce-ring.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ its neighbors in rank order. A native CPU proxy forwards transfers addressed to
other ranks through those neighbors. The transport supports 2 through 16 ranks;
each model recipe determines which tensor-parallel sizes it can prepare,
and the multi-host preparation rendezvous admits two, three, or four ranks.
GLM-5.3 Flash, MiMo V2.6, DeepSeek V4 Flash, and Qwen3.8 Flash prepare multi-host TP2 and TP4 cores.
GLM-5.3 Flash, MiMo V2.6, DeepSeek V4 Flash, and Qwen3.8 Flash prepare multi-host TP2 and TP4 cores;
Inkling 2 Small NVFP4 prepares multi-host TP4 cores.

Ring routing applies to RoCEnante's one-shot reductions, two-shot reductions,
and variable-length gathers. The collective algorithms and arithmetic belong
Expand Down
88 changes: 67 additions & 21 deletions ignition/recipes/inkling2/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributors
# SPDX-License-Identifier: Apache-2.0

"""Prepare Inkling 2 text, vision and complete DSpark generation graphs on four local GPUs."""
"""Prepare Inkling 2 text, vision and complete DSpark generation graphs on four GPUs, on one host or across four hosts."""

import contextlib
import hashlib
Expand All @@ -23,7 +23,8 @@
from ignition.components.state_transfer import StateCommands
from ignition.preparation.capture import capture_forwards
from ignition.preparation.checkpoint import inspect_indexed_checkpoint
from ignition.preparation.collectives import CollectivePreparation, create_all_reduce_runtime, create_all_gather_runtime
from ignition.preparation.collectives import (CollectivePreparation, create_all_reduce_runtime, create_all_gather_runtime,
create_roce_runtime)
from ignition.preparation.execution import GraphSignature
from ignition.preparation.fixtures.recurrent import register_benchmark_state
from ignition.preparation.host_memory import release_unused
Expand All @@ -40,7 +41,7 @@
from .decoder import PreparedDecoder, Scratch
from .weights import ModelWeights
from .pool import PAGE_TOKENS, ContinuationPool, RankGeometry, continuation_layout, page_specs
from ignition.preparation.bootstrap import BasePreparationConfig
from ignition.preparation.bootstrap import BasePreparationConfig, validate_host_topology


@dataclass(frozen=True)
Expand All @@ -49,23 +50,32 @@ class PreparationConfig(BasePreparationConfig):
image_concurrency: int | None = None
autotune_effort: str = "off"
devices: tuple[int, ...] = (0, 1, 2, 3)
# Device ordinals are host-local when each rank runs on its own host.
hosts: tuple[str, ...] | None = None
roce_ring: bool = False
roce_chain: bool = False
context: int = 1048576
max_active: int = 8
compile_decoder: bool = False
decoder_layers: int | None = None
drafting: bool = True
vision: bool = True
speculative_widths: tuple[int, ...] = tuple(range(1, 9))
speculative_token_capacity: int | None = 64
speculative_token_capacity: int | None = 128
speculative_graph_budget: int = 64
benchmark_selection: object | None = None

def __post_init__(self):
if len(self.devices) != WORLD_SIZE or len(set(self.devices)) != WORLD_SIZE or min(self.devices) < 0:
raise ValueError("Inkling 2 preparation requires four distinct GPUs on one host")
placements = tuple(zip(self.hosts or ("",) * len(self.devices), self.devices))
if (not isinstance(self.devices, tuple) or len(self.devices) != WORLD_SIZE
or len(set(placements)) != WORLD_SIZE
or self.hosts is not None and (not isinstance(self.hosts, tuple) or len(self.hosts) != WORLD_SIZE)
or any(type(d) is not int or d < 0 for d in self.devices)):
raise ValueError("Inkling 2 preparation requires four distinct GPUs")
validate_host_topology(self.roce_ring, self.roce_chain, self.hosts)
request_capacity(self.max_active)
if not 1 <= self.max_active <= 8:
raise ValueError("Inkling 2 request capacity must be in [1, 8]")
if not 1 <= self.max_active <= 32:
raise ValueError("Inkling 2 request capacity must be in [1, 32]")
if not PAGE_TOKENS <= self.context <= 1048576 or self.context % PAGE_TOKENS:
raise ValueError("Inkling 2 context must be 128-aligned in [128, 1048576]")
if not PAGE_TOKENS <= self.prefill_chunk_size <= self.context or self.prefill_chunk_size % PAGE_TOKENS:
Expand Down Expand Up @@ -112,6 +122,41 @@ def _logit_gather_bytes(rows, width):
return rows * width * 4


def _collective_runtimes(config, group, device, *, coordinator, core_storage, hidden, local_vocabulary, draft_block):
"""Allocate the hidden reduction and the vocabulary, sampling and log-probability gather channels.

`hidden` is the model width, `local_vocabulary` one rank's padded vocabulary columns and `draft_block`
the positions the drafter reduces per request. Ranks on separate hosts run every collective in
rank-serial order over one RoCEnante runtime, which all four roles share; the sampling and
log-probability channels are None without drafting.
"""
slots, world = request_capacity(config.max_active), len(config.devices)
tokens = max(config.prefill_chunk_size, config.decode_tokens)
vocabulary_rows = max(config.decode_samples, slots)
if coordinator.spans_hosts:
# One-shot reductions cover decode and verification rows and the drafter's block of every request;
# prefill chunks reduce through the pipelined two-shot path. The largest gather is each rank's FP32
# vocabulary partition of every sampled row, carried as BF16 column pairs: 4 * local_vocabulary
# bytes per row. A row of the other gathers is at most 1024 bytes (the FP32 log-probability summary),
# and the packed sampling results of all rows fit in one vocabulary row.
runtime = create_roce_runtime(group, device,
max_tokens=max(config.decode_tokens, slots * draft_block if config.drafting else 0), pipe_tokens=tokens,
hidden_size=hidden, gather_bytes=vocabulary_rows * local_vocabulary * 4,
ring=config.roce_ring, ring_open=config.roce_chain, core_storage=core_storage)
drafting = runtime if config.drafting else None
return runtime, runtime, drafting, drafting
ipc = core_storage.peer_storage
runtime = create_all_reduce_runtime(group, device, max_tokens=min(tokens, 1024),
hidden_size=hidden, element_bytes=4, ipc=ipc, collective_tuning=config.collective_tuning)
vocabulary = create_all_gather_runtime(group, device, max_rows=vocabulary_rows,
columns=2 * local_vocabulary * world, ipc=ipc)
sampling = (create_all_gather_runtime(group, device, max_rows=config.decode_samples,
columns=64 * world, ipc=ipc) if config.drafting else None)
logprob = (create_all_gather_runtime(group, device, max_rows=config.decode_samples,
columns=512 * world, ipc=ipc) if config.drafting else None)
return runtime, vocabulary, sampling, logprob


class _Softcapped:
def __init__(self, projection, softcap):
self.projection, self.softcap = projection, softcap
Expand Down Expand Up @@ -143,8 +188,8 @@ def prepare_rank(snapshot, config, *, rank, group, progress=None, core_storage):
shard = TensorParallelShard(rank, world)
device = torch.device("cuda", config.devices[rank])
torch.cuda.set_device(device)
if torch.cuda.get_device_capability(device) != (12, 0):
raise ValueError("Inkling 2 preparation requires SM120 GPUs")
if torch.cuda.get_device_capability(device) not in ((12, 0), (12, 1)):
raise ValueError("Inkling 2 preparation requires SM120 or SM121 GPUs")
with phase(progress, "Inspect checkpoint"):
manifest = inspect_indexed_checkpoint(snapshot)
headers = [entry.header_sha256 for entry in manifest.shards]
Expand All @@ -158,6 +203,11 @@ def prepare_rank(snapshot, config, *, rank, group, progress=None, core_storage):
weights = ModelWeights.load(manifest, device, shard=shard, layers=config.decoder_layers,
progress=progress, drafting=config.drafting, vision=config.vision)
weights_bytes = torch.cuda.memory_allocated(device)
if torch.cuda.get_device_properties(device).is_integrated:
from ignition.preparation.host_memory import release_page_cache

# Unified memory counts cached checkpoint pages against the GPU; drop them after loading.
release_page_cache(manifest.shard_paths)
del manifest
release_unused()
transient = contextlib.ExitStack()
Expand Down Expand Up @@ -188,16 +238,10 @@ def prepare_rank(snapshot, config, *, rank, group, progress=None, core_storage):
width = max((w for _, w, _ in config.speculative_round_shapes), default=1)
completion = CompletionOutputs.allocate((2, slots, VECTOR_TOKENS_FIELD + width), device=device)
coordinator = CollectivePreparation(group)
runtime = create_all_reduce_runtime(group, device, max_tokens=min(tokens, 1024),
hidden_size=text.hidden, element_bytes=4, ipc=core_storage.peer_storage,
collective_tuning=config.collective_tuning)
vocabulary_runtime = create_all_gather_runtime(group, device,
max_rows=max(config.decode_samples, slots), columns=2 * weights.head.shape[0] * world,
ipc=core_storage.peer_storage)
sampling_runtime = (create_all_gather_runtime(group, device, max_rows=config.decode_samples,
columns=64 * world, ipc=core_storage.peer_storage) if config.drafting else None)
logprob_runtime = (create_all_gather_runtime(group, device, max_rows=config.decode_samples,
columns=512 * world, ipc=core_storage.peer_storage) if config.drafting else None)
runtime, vocabulary_runtime, sampling_runtime, logprob_runtime = _collective_runtimes(
config, group, device, coordinator=coordinator, core_storage=core_storage,
hidden=text.hidden, local_vocabulary=weights.head.shape[0],
draft_block=model.draft.block)
identity = hashlib.sha256(json.dumps({"text": model.text.__dict__ | {"local_layers": sorted(model.text.local_layers)},
"quantization": model.quantization, "headers": headers, "world_size": world,
"decoder_layers": len(weights.layers), "contract": "inkling2.paged-text.v1"},
Expand Down Expand Up @@ -357,4 +401,6 @@ def add(name, forward, kind, rows, tokens, fields, enabled=None, packed=0):
export_zero_ranges=completion.zero_ranges(),
resources=(weights, pool, requests, inputs, admission, commands, completion, forwards, arena, session,
compiled, stream, graph_pool, coordinator, runtime, vocabulary_runtime, sampling_runtime, logprob_runtime, speculation, vision_state),
close_resources=tuple(r for r in (runtime, vocabulary_runtime, sampling_runtime, logprob_runtime) if r is not None))
# Ranks on separate hosts share one runtime across these roles; close it once.
close_resources=tuple(dict.fromkeys(
r for r in (runtime, vocabulary_runtime, sampling_runtime, logprob_runtime) if r is not None)))
Loading