Files
DeepInfer/tests/engine/test_sm120_support.py
T
shunyadandClaude Opus 5.5 8898e97395 fix(sm120): refuse multi-host Engram groups right after rendezvous
Host-resident Engram tables are one /dev/shm mapping shared through
/proc/<pid>/fd, so every Engram group must sit on one host. The default
engram_parallel_size (0 = every rank) spans all nodes of a multi-node
deployment, which only failed on a bare assert in HostEngramBuffer after the
weights were loaded (and under python -O failed later with a misleading
"cannot open /proc/..." error).

- sm120_support.check_rank_placement (was check_distinct_devices) now also
  checks, from the hostnames it already gathers, that each Engram group
  (contiguous rank blocks) stays on one host, and names the offending ranks.
- HostEngramBuffer raises ValueError instead of asserting.
- README.sm120.md says multi-node deployments must set engram_parallel_size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:22:14 -08:00

121 lines
4.5 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
from types import SimpleNamespace
import pytest
from deepinfer import PLATFORM, sm120_support
@pytest.fixture
def sm120(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(type(PLATFORM), "is_sm120", property(lambda self: True), raising=False)
monkeypatch.setattr(sm120_support, "_device_violations", lambda parallel_config: [])
for name, value in {
"DEEPINFER_USE_NEXTN_DECODE": "0",
"DEEPINFER_ENABLE_MTP_VARLEN": "0",
"DEEPINFER_EXPERT_REARRANGEMENT_STEP_INTERVAL": "0",
"DEEPINFER_BATCH_INVARIANT": "0",
"DEEPINFER_YOCO_PREFILL_TRUNCATION_MODE": "off",
"DEEPINFER_ENGRAM_FORCE_GPU_STORAGE": "0",
}.items():
monkeypatch.setenv(name, value)
from deepinfer import environ
environ.rearm_all()
def _parallel(cp: int = 1) -> SimpleNamespace:
return SimpleNamespace(context_parallel_size=cp, data_parallel_size=8)
def test_minimal_config_passes(sm120: None) -> None:
sm120_support.check_engine_config(_parallel())
@pytest.mark.parametrize(
("name", "value"),
[
("DEEPINFER_USE_NEXTN_DECODE", "5"),
("DEEPINFER_EXPERT_REARRANGEMENT_STEP_INTERVAL", "100"),
("DEEPINFER_YOCO_PREFILL_TRUNCATION_MODE", "compact"),
("DEEPINFER_YOCO_PREFILL_TRUNCATION_MODE", "mask"),
],
)
def test_supported_setting_passes(sm120: None, monkeypatch: pytest.MonkeyPatch, name: str, value: str) -> None:
from deepinfer import environ
monkeypatch.setenv(name, value)
environ.rearm_all()
sm120_support.check_engine_config(_parallel())
@pytest.mark.parametrize(
("name", "value"),
[
("DEEPINFER_ENABLE_MTP_VARLEN", "1"),
("DEEPINFER_BATCH_INVARIANT", "1"),
("DEEPINFER_ENGRAM_FORCE_GPU_STORAGE", "1"),
],
)
def test_unsupported_setting_is_named(sm120: None, monkeypatch: pytest.MonkeyPatch, name: str, value: str) -> None:
from deepinfer import environ
monkeypatch.setenv(name, value)
environ.rearm_all()
with pytest.raises(ValueError, match=name):
sm120_support.check_engine_config(_parallel())
def test_context_parallel_is_named(sm120: None) -> None:
with pytest.raises(ValueError, match="context_parallel_size"):
sm120_support.check_engine_config(_parallel(cp=2))
def test_device_checks(monkeypatch: pytest.MonkeyPatch) -> None:
from deep_cluster import hardware
from deep_cluster.hardware import nvidia
monkeypatch.setattr(hardware, "visible_device_ids", lambda: ("0", "1", "2", "3"))
monkeypatch.setattr(nvidia, "compute_capability", lambda index=0: (10, 0) if index == "0" else (12, 0))
violations = sm120_support._device_violations(_parallel())
assert any("compute capabilities" in v for v in violations)
def test_shared_devices_are_per_host() -> None:
hosts = [("a", "GPU-0"), ("a", "GPU-1"), ("b", "GPU-0"), ("b", "GPU-1")]
assert sm120_support.shared_devices(hosts) == []
wrapped = [("a", "GPU-0"), ("a", "GPU-1"), ("a", "GPU-0"), ("a", "GPU-1")]
assert sm120_support.shared_devices(wrapped) == ["a/GPU-0: ranks [0, 2]", "a/GPU-1: ranks [1, 3]"]
def test_device_checks_ignore_invisible_gpus(monkeypatch: pytest.MonkeyPatch) -> None:
from deep_cluster import hardware
from deep_cluster.hardware import nvidia
monkeypatch.setattr(hardware, "visible_device_ids", lambda: ("2", "3"))
monkeypatch.setattr(nvidia, "compute_capability", lambda index=0: (12, 0) if index in ("2", "3") else (10, 0))
assert sm120_support._device_violations(_parallel()) == []
def test_non_sm120_is_untouched(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(type(PLATFORM), "is_sm120", property(lambda self: False), raising=False)
monkeypatch.setenv("DEEPINFER_USE_NEXTN_DECODE", "5")
from deepinfer import environ
environ.rearm_all()
sm120_support.check_engine_config(_parallel(cp=2))
def test_engram_groups_must_stay_on_one_host() -> None:
hosts = ["a"] * 8 + ["b"] * 8
assert sm120_support.engram_groups_across_hosts(hosts, 8) == []
assert sm120_support.engram_groups_across_hosts(hosts, 4) == []
assert sm120_support.engram_groups_across_hosts(hosts, 16) == ["ranks 0-15 on hosts ['a', 'b']"]
# Groups are contiguous rank blocks, so a block straddling the host boundary is refused.
uneven = ["a"] * 6 + ["b"] * 6
assert sm120_support.engram_groups_across_hosts(uneven, 4) == ["ranks 4-7 on hosts ['a', 'b']"]