diff --git a/docs/TODO.txt b/docs/TODO.txt index d03031093..fab2560af 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -11,8 +11,9 @@ [ ] Compare Inkling 2 output across four DGX Sparks, where cross-host hidden reductions round partial sums to BF16, with the single-host FP32 reductions, and run the effort-zero cases of tests/server/test_inkling2.py - there. Complete an export of the declared eight-request configuration on - DGX Sparks and run the default-effort cases against it. + there. 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 diff --git a/docs/model-preparation.md b/docs/model-preparation.md index a490b21ef..1771ce7a2 100644 --- a/docs/model-preparation.md +++ b/docs/model-preparation.md @@ -1366,17 +1366,17 @@ 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. On rank -zero, whose preparation address is `10.200.0.13`, with -`[memory] reserve = "4G"`: +directory on rank zero only; peers read their tensor ranges from it. The recipe +accepts up to 32 concurrent requests. 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 8 --image-concurrency 4 \ - --prefill-chunk-size 4096 --mtp-draft-tokens 7 \ - --speculative-token-capacity 64 --speculative-graph-budget 64 \ + --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 ``` @@ -1387,31 +1387,36 @@ On each peer, with its rank from 1 through 3: ``` Serve with `flare run CACHE_ENTRY --rank 0 --rendezvous 10.200.0.13:29800 ---gpus 0 --mtp-draft-tokens 7 --no-history-drafts` on rank zero and -`flare run --rank R --rendezvous 10.200.0.13:29800 --gpus 0` with the same -serving options on each peer. Follow the [multi-host guide](multi-host.md) for +--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. Each peer holds the payloads it -prepares, about a quarter of the core, and for serving the rank core it -receives, of the same size; the prepared payloads can be removed after export. -Drop the page cache on every host before export and before serving. - -Qualification on four DGX Sparks (GB10, SM121, 121 GiB each) joined by a -switch, with one pair also cabled directly, covers a reduced core: no drafting -and no vision, one request, 512-token chunks, no kernel tuning and uncompiled -forwards (`--no-mtp --language-model-only --max-concurrency 1 ---prefill-chunk-size 512 --autotune-effort off --no-compile`, with no memory -reserve). It exported 8 graphs in 18 min 43 s. Native loading used 82.9 GiB -per rank and allocated a 24.5 GiB cache with 6414336 KV-token slots. The -service answered a chat completion, a streamed completion, two requests -against its one slot, and a 7150-token prompt prefilled in fourteen chunks, -with no change in the RoCE loss counters. The eight-request configuration -above has not completed an export on DGX Sparks. Also not run there: the -default-effort and effort-zero cases of `tests/server/test_inkling2.py`, -`--roce-ring`, `--roce-chain`, and a comparison of BF16 cross-host reductions -with single-host FP32 output. +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. + +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: 3252224 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, 2392064 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 18832-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 7150-token prompt. Not run on Sparks: the +effort-zero tests, `--roce-ring`, `--roce-chain`, and a comparison of BF16 +cross-host reductions with single-host FP32 output. ## Muse Spark Open diff --git a/ignition/recipes/inkling2/bootstrap.py b/ignition/recipes/inkling2/bootstrap.py index 886f9c8bd..8210ca87e 100644 --- a/ignition/recipes/inkling2/bootstrap.py +++ b/ignition/recipes/inkling2/bootstrap.py @@ -90,8 +90,8 @@ def __post_init__(self): if error: raise ValueError(error) 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: diff --git a/ignition/recipes/inkling2/recipe.py b/ignition/recipes/inkling2/recipe.py index ec4fd292d..192907937 100644 --- a/ignition/recipes/inkling2/recipe.py +++ b/ignition/recipes/inkling2/recipe.py @@ -57,7 +57,7 @@ def usage(prepared): checkpoints=(Checkpoint(alias="inkling-2-small-nvfp4", repository="/data/models/Inkling-2-Small-NVFP4", revision="local", architecture="Inkling2ForConditionalGeneration", stored_bytes=344_366_116_864, device_bytes=344_366_116_864, expansion_bytes=5_673_717_760, draft_bytes=2_684_203_392),), - context=1048576, page_tokens=128, concurrency=8, max_concurrency=8, prefill_chunk=4096, + context=1048576, page_tokens=128, concurrency=8, max_concurrency=32, prefill_chunk=4096, speculation=Speculation(draft_tokens=7, token_capacity=64, packed_verification=True, graph_budget=64), max_draft_tokens=7, max_images=4, image_bytes=32 << 20, verification_rows=0, language_model_only=True, ranks=MappingProxyType({4: RankCosts(31_293_440, 655_360, 5 << 30)}), diff --git a/tests/cli/test_inkling2.py b/tests/cli/test_inkling2.py index 44ebdc706..c614160f0 100644 --- a/tests/cli/test_inkling2.py +++ b/tests/cli/test_inkling2.py @@ -16,6 +16,7 @@ def test_inkling_defaults_cover_tp4_seven_drafts_and_vision(): assert RECIPE.tensor_parallel == (4,) assert (RECIPE.context, RECIPE.concurrency, RECIPE.prefill_chunk) == (1048576, 8, 4096) + assert RECIPE.max_concurrency == 32 assert (RECIPE.max_images, RECIPE.image_bytes) == (4, 32 << 20) model = ResolvedModel(RECIPE, RECIPE.checkpoints[0]) args = _parser().parse_args(["export", model.checkpoint.alias]) diff --git a/tests/recipes/test_inkling2_hosts.py b/tests/recipes/test_inkling2_hosts.py index cbb438e1b..42895f13f 100644 --- a/tests/recipes/test_inkling2_hosts.py +++ b/tests/recipes/test_inkling2_hosts.py @@ -43,8 +43,8 @@ def _gb10(count): return tuple(planning.Gpu(i, "GB10", f"GPU-{i}", 121 << 30, 115 << 30, (12, 1)) for i in range(count)) -@pytest.mark.parametrize("concurrency, chunk, capacity", [(8, 4096, 64)]) -def test_four_gb10_hosts_fit_the_declared_configuration(concurrency, chunk, capacity): +@pytest.mark.parametrize("concurrency, chunk, capacity", [(8, 4096, 64), (32, 8192, 128)]) +def test_four_gb10_hosts_fit_the_declared_and_the_largest_configuration(concurrency, chunk, capacity): speculation = replace(recipe.RECIPE.speculation, token_capacity=capacity) plan = planning.plan(recipe.RECIPE, recipe.RECIPE.checkpoints[0], _gb10(4), selected=(0, 1, 2, 3), concurrency=concurrency, reserve_bytes=4 << 30, speculation=speculation, @@ -56,6 +56,29 @@ def test_four_gb10_hosts_fit_the_declared_configuration(concurrency, chunk, capa assert plan.page_bytes >= 16 << 30 +def test_request_capacity_is_bounded_by_thirty_two(): + from ignition.errors import UsageError + + assert bootstrap.PreparationConfig(max_active=32, prefill_chunk_size=8192, + speculative_token_capacity=128).max_active == 32 + with pytest.raises(ValueError, match=r"\[1, 32\]"): + bootstrap.PreparationConfig(max_active=33) + with pytest.raises(UsageError, match="must be 1 through 32"): + planning.plan(recipe.RECIPE, recipe.RECIPE.checkpoints[0], _gb10(4), selected=(0, 1, 2, 3), + concurrency=33, reserve_bytes=4 << 30, speculation=recipe.RECIPE.speculation) + + +def test_thirty_two_requests_size_rounds_scratch_rows_and_prefill_graphs(): + config = bootstrap.PreparationConfig(max_active=32, prefill_chunk_size=8192, speculative_token_capacity=128) + shapes = config.speculative_round_shapes + assert {batch for batch, _, _ in shapes} == {1, 2, 4, 8, 16, 32} + assert all(packed <= 128 for _, _, packed in shapes) and (32, 8, 128) in shapes and (32, 1, 32) in shapes + # Packed verification bounds target rows; every request still samples each of its eight positions. + assert (config.decode_tokens, config.decode_samples) == (128, 256) + assert config.image_concurrency == 4 + assert bootstrap.prefill_capacities(8192)[-1] == 8192 + + @pytest.mark.parametrize("remote", [False, True]) @pytest.mark.parametrize("ring", [False, True]) def test_recipe_dispatches_the_complete_plan_to_the_rank_group(monkeypatch, remote, ring): @@ -79,6 +102,19 @@ def test_recipe_dispatches_the_complete_plan_to_the_rank_group(monkeypatch, remo assert kwargs["core_storage"] is storage +def test_remote_capacities_follow_thirty_two_requests_and_8192_token_chunks(monkeypatch): + config = bootstrap.PreparationConfig(devices=(0,) * 4, hosts=HOSTS, max_active=32, prefill_chunk_size=8192, + speculative_token_capacity=128) + calls = [] + monkeypatch.setattr(bootstrap, "create_roce_runtime", lambda group, device, **kwargs: calls.append(kwargs)) + bootstrap._collective_runtimes(config, None, None, coordinator=SimpleNamespace(spans_hosts=True), + core_storage=None, **GEOMETRY) + (call,) = calls + # The drafter reduces an eight-position block of each of 32 requests in one shot. + assert call["max_tokens"] == 32 * DRAFT_BLOCK == 256 and call["pipe_tokens"] == 8192 + assert call["gather_bytes"] == 256 * LOCAL_VOCABULARY * 4 + + @pytest.mark.parametrize("drafting", [False, True]) @pytest.mark.parametrize("chain", [False, True]) def test_remote_channels_share_one_roce_runtime_without_pcie(monkeypatch, drafting, chain): diff --git a/tests/server/test_inkling2.py b/tests/server/test_inkling2.py index 509e3476b..c7231b69c 100644 --- a/tests/server/test_inkling2.py +++ b/tests/server/test_inkling2.py @@ -4,7 +4,9 @@ """Inkling 2 text, TML tools, images and cached continuations through native TP4 serving. Set FLARE_RUN_CUDA_TESTS=1 and FLARE_INKLING2_TEST_URL to an exported core -running with flare run, concurrency eight, 4096-token prefill and vision. +running with flare run, concurrency of at least eight, 4096- or 8192-token +prefill and vision. Prompts that cross a prefill chunk scale with the chunk +size the service reports. """ from concurrent.futures import ThreadPoolExecutor @@ -30,8 +32,9 @@ def service(request): with urllib.request.urlopen(url + "/v1/models", timeout=10) as response: model = json.load(response)["data"][0] assert "inkling" in model["id"].lower(), model - assert model["flare"]["max_concurrency"] == 8 - assert model["flare"]["prefill_chunk_size"] == 4096 + assert model["flare"]["max_concurrency"] >= 8 + chunk = model["flare"]["prefill_chunk_size"] + assert chunk in (4096, 8192) assert "image" in model["flare"]["input_modalities"] def ask(content, **options): @@ -61,6 +64,7 @@ def ask(content, **options): assert result["usage"]["completion_tokens"] == len(choice["token_ids"]) return result + ask.chunk = chunk return ask @@ -87,14 +91,15 @@ def test_streamed_reasoning_and_answer(service): def test_chunked_prefix_reuse_and_branching(service): - prefix = " ".join(f"Item {i} records code {i * 17 % 997}." for i in range(700)) + chunk = service.chunk + prefix = " ".join(f"Item {i} records code {i * 17 % 997}." for i in range(700 * chunk // 4096)) history = [dict(role="user", content=prefix), dict(role="assistant", content="I have the item records.")] for index in (211, 677, 211): messages = history + [dict(role="user", content=f"What code does item {index} record? Reply with only the integer.")] first, second = service("", messages=messages), service("", messages=messages) - assert first["usage"]["prompt_tokens"] > 4096 - assert second["usage"]["prompt_tokens_details"]["cached_tokens"] > 4096 + assert first["usage"]["prompt_tokens"] > chunk + assert second["usage"]["prompt_tokens_details"]["cached_tokens"] > chunk assert answer(first) == answer(second) == str(index * 17 % 997) @@ -122,11 +127,11 @@ def test_structured_response(service): def test_images_across_a_prefill_chunk(service): - content = [dict(type="text", text="filler " * 4100), + content = [dict(type="text", text="filler " * (service.chunk + 4)), image("red", "FIRST 128"), image("blue", "SECOND 256"), dict(type="text", text="Read both image labels in their original order. Only output the labels.")] response = service(content) - assert response["usage"]["prompt_tokens"] > 4096 + assert response["usage"]["prompt_tokens"] > service.chunk result = answer(response) assert "FIRST 128" in result and "SECOND 256" in result assert result.index("FIRST 128") < result.index("SECOND 256")