[Edge][WP4] Add hardware adaptation: probe, derived overrides, auto profile, calibration
* vllm_omni/edge/hardware_probe.py: HardwareProfile from /proc, /sys and torch (ISA flags incl. AVX-512/AMX and NEON/dotprod/i8mm/SVE, physical cores, big.LITTLE clusters, NUMA, RAM, CUDA discrete vs Tegra unified memory, NPU via override), hardware classes jetson / cuda_discrete / arm64_cpu / x86_cpu / npu_phone; VLLM_OMNI_HW_PROFILE=<json> overrides the probe (emulation, tests). * vllm_omni/edge/adapt.py: derive_overrides -> dtype, absolute KV budgets from available memory minus weights, max_num_seqs, per-stage disjoint CPU thread ranges on the big cluster, eager/graph switches for small or unified memory, adaptive-chunk parameters, timeouts from a load cost model. * vllm_omni/edge/calibrate.py: chunk-schedule calibration from measured chunk arrivals with a per-hardware-fingerprint cache under VLLM_CACHE_ROOT. * vllm_omni/edge/auto_profile.py + deploy_profile="auto": edge/<model>.yaml -> edge/hardware/<class>.yaml -> derived overrides -> cached calibration, materialized as a temp deploy YAML (platform overlays are superseded). * benchmarks/tts/hw_emulation.py: emulated classes (ATEN_CPU_CAPABILITY, taskset, profile overrides) driving stream_latency_bench with auto profiles. * CPU-only tests for probe snapshots, derivation rules, calibration and auto. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
073d31b9cd
commit
55192de984
18 files changed
+1581
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"""Tests for benchmarks/tts/hw_emulation.py case construction (CPU)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "benchmarks" / "tts"))
|
||||
import hw_emulation as hw # noqa: E402
|
||||
|
||||
from vllm_omni.edge.hardware_probe import hardware_class # noqa: E402
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def test_cases_map_to_expected_classes():
|
||||
expected = {
|
||||
"x86_cpu_avx2": "x86_cpu",
|
||||
"x86_cpu_avx512": "x86_cpu",
|
||||
"x86_cpu_amx": "x86_cpu",
|
||||
"arm64_cpu_logic": "arm64_cpu",
|
||||
"jetson_orin_8g": "jetson",
|
||||
"jetson_orin_32g": "jetson",
|
||||
"cuda_discrete_8g": "cuda_discrete",
|
||||
}
|
||||
for name, cls in expected.items():
|
||||
prof = hw.build_profile(hw.CASES[name])
|
||||
assert hardware_class(prof) == cls, name
|
||||
assert prof.source == "emulation"
|
||||
|
||||
|
||||
def test_avx2_case_disables_bf16_and_pins_cores():
|
||||
case = hw.CASES["x86_cpu_avx2"]
|
||||
prof = hw.build_profile(case)
|
||||
assert prof.supports_bf16 is False and prof.n_logical == 4
|
||||
assert case.env["ATEN_CPU_CAPABILITY"] == "avx2" and case.cpus == [0, 1, 2, 3]
|
||||
|
||||
|
||||
def test_table_render_handles_missing_metrics():
|
||||
table = hw.render_table([{"case": "x", "returncode": -1, "note": "timeout"}])
|
||||
assert "| x | -1 |" in table and "timeout" in table
|
||||
Whitespace-only changes.
@@ -0,0 +1,109 @@
|
||||
"""Tests for vllm_omni.edge.adapt (CPU)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.edge import adapt
|
||||
from vllm_omni.edge.hardware_probe import HardwareProfile
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
GiB = 2**30
|
||||
|
||||
|
||||
def _x86(ram=32 * GiB, flags=("avx2", "avx512", "avx512_bf16", "amx_bf16"), n=16):
|
||||
return HardwareProfile(
|
||||
arch="x86_64",
|
||||
cpu_flags=list(flags),
|
||||
n_logical=n,
|
||||
n_physical=n,
|
||||
clusters=[{"max_khz": 3000000, "cpus": list(range(n))}],
|
||||
ram_total_bytes=ram,
|
||||
ram_available_bytes=ram - 2 * GiB,
|
||||
supports_bf16="avx512_bf16" in flags,
|
||||
)
|
||||
|
||||
|
||||
def test_dtype_rules():
|
||||
assert adapt.choose_dtype(_x86()) == "bfloat16"
|
||||
assert adapt.choose_dtype(_x86(flags=("avx2",))) == "float32"
|
||||
gpu = HardwareProfile(arch="x86_64", accelerator="cuda_discrete", gpu_mem_bytes=24 * GiB, supports_bf16=False)
|
||||
assert adapt.choose_dtype(gpu) == "float16"
|
||||
arm = HardwareProfile(arch="aarch64", cpu_flags=["neon", "fp16_arith"], supports_bf16=False)
|
||||
assert adapt.choose_dtype(arm) == "float32"
|
||||
|
||||
|
||||
def test_cpu_class_binds_disjoint_ranges_and_absolute_kv_budget():
|
||||
prof = _x86(ram=16 * GiB, n=8)
|
||||
ov = adapt.derive_overrides(prof, weights_bytes=2 * GiB)
|
||||
assert ov["hardware_class"] == "x86_cpu"
|
||||
s0, s1 = ov["stages"][0], ov["stages"][1]
|
||||
assert s0["devices"] == "cpu" and s1["devices"] == "cpu"
|
||||
assert s0["env"]["VLLM_CPU_OMP_THREADS_BIND"] == "0-4"
|
||||
assert s1["env"]["VLLM_CPU_OMP_THREADS_BIND"] == "5-7"
|
||||
assert s0["enforce_eager"] is True and s1["enforce_eager"] is True
|
||||
kv0, kv1 = s0["engine_args"]["kv_cache_memory_bytes"], s1["engine_args"]["kv_cache_memory_bytes"]
|
||||
assert kv0 > 0 and kv1 > 0 and kv0 + kv1 == ov["memory_budget_bytes"]
|
||||
assert kv0 + kv1 <= prof.ram_available_bytes
|
||||
assert ov["connector_extra"]["codec_chunk_adaptive"] is True
|
||||
assert ov["timeouts"]["stage_init_timeout"] >= 300
|
||||
|
||||
|
||||
def test_small_vram_gpu_forces_eager_and_tight_budgets():
|
||||
prof = HardwareProfile(
|
||||
arch="x86_64",
|
||||
accelerator="cuda_discrete",
|
||||
gpu_name="small",
|
||||
gpu_mem_bytes=6 * GiB,
|
||||
supports_bf16=True,
|
||||
ram_total_bytes=16 * GiB,
|
||||
)
|
||||
ov = adapt.derive_overrides(prof, weights_bytes=3 * GiB)
|
||||
assert ov["hardware_class"] == "cuda_discrete"
|
||||
assert ov["stages"][0]["enforce_eager"] is True and ov["stages"][1]["enforce_eager"] is True
|
||||
assert ov["stages"][0]["gpu_memory_utilization"] is None
|
||||
total_kv = sum(ov["stages"][i]["engine_args"]["kv_cache_memory_bytes"] for i in (0, 1))
|
||||
assert total_kv <= 6 * GiB - 3 * GiB
|
||||
assert "compilation_config" not in ov["stages"][0]
|
||||
|
||||
|
||||
def test_jetson_unified_memory_uses_ram_and_graphs_off_stage1():
|
||||
prof = HardwareProfile(
|
||||
arch="aarch64", accelerator="cuda_unified", gpu_mem_bytes=32 * GiB, ram_total_bytes=32 * GiB, supports_bf16=True
|
||||
)
|
||||
ov = adapt.derive_overrides(prof, weights_bytes=4 * GiB)
|
||||
assert ov["hardware_class"] == "jetson"
|
||||
assert ov["stages"][1]["enforce_eager"] is True
|
||||
assert ov["stages"][0]["enforce_eager"] is False
|
||||
assert ov["stages"][0]["compilation_config"]["cudagraph_capture_sizes"] == [1, 2]
|
||||
assert ov["stages"][0]["max_num_seqs"] == 2
|
||||
assert ov["timeouts"]["init_timeout"] >= ov["timeouts"]["stage_init_timeout"]
|
||||
|
||||
|
||||
def test_budget_never_exceeds_pool_and_seqs_shrink():
|
||||
prof = _x86(ram=3 * GiB, n=4)
|
||||
prof.ram_available_bytes = 3 * GiB
|
||||
ov = adapt.derive_overrides(prof, weights_bytes=1 * GiB)
|
||||
assert ov["memory_budget_bytes"] >= 0
|
||||
assert ov["stages"][0]["max_num_seqs"] >= 1
|
||||
|
||||
|
||||
def test_split_cpu_ranges_and_cli_flatten():
|
||||
assert adapt.split_cpu_ranges([0, 1, 2, 3, 4, 5]) == ("0-3", "4-5")
|
||||
assert adapt.split_cpu_ranges([7]) == ("7", "7")
|
||||
assert adapt.split_cpu_ranges([0, 2, 3, 4]) == ("0,2-3", "4")
|
||||
assert adapt._ranges([0, 1, 2, 5, 7, 8]) == "0-2,5,7-8"
|
||||
ov = adapt.derive_overrides(_x86(), weights_bytes=GiB)
|
||||
flat = adapt.overrides_to_cli(ov)
|
||||
assert flat["async_chunk"] is True and "0" in flat["stage_overrides"] and "stage_init_timeout" in flat
|
||||
|
||||
|
||||
def test_estimate_weights_bytes(tmp_path):
|
||||
(tmp_path / "a.safetensors").write_bytes(b"x" * 10)
|
||||
(tmp_path / "sub").mkdir()
|
||||
(tmp_path / "sub" / "b.safetensors").write_bytes(b"y" * 5)
|
||||
(tmp_path / "c.bin").write_bytes(b"z" * 100)
|
||||
assert adapt.estimate_weights_bytes(tmp_path) == 15
|
||||
assert adapt.estimate_weights_bytes(None) == 0
|
||||
assert adapt.estimate_weights_bytes(tmp_path / "missing") == 0
|
||||
@@ -0,0 +1,105 @@
|
||||
"""Tests for deploy_profile='auto' materialization (CPU, no engine)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from vllm_omni.config.stage_config import _DEPLOY_DIR, load_deploy_config
|
||||
from vllm_omni.edge import auto_profile, calibrate
|
||||
from vllm_omni.edge.hardware_probe import HardwareProfile
|
||||
from vllm_omni.entrypoints import utils as entry_utils
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
GiB = 2**30
|
||||
EDGE = _DEPLOY_DIR / "edge" / "qwen3_tts.yaml"
|
||||
|
||||
|
||||
def _arm_profile():
|
||||
return HardwareProfile(
|
||||
arch="aarch64",
|
||||
cpu_model="RK3588",
|
||||
cpu_flags=["neon", "dotprod", "fp16_arith"],
|
||||
n_logical=8,
|
||||
n_physical=8,
|
||||
clusters=[{"max_khz": 2400000, "cpus": [4, 5, 6, 7]}, {"max_khz": 1800000, "cpus": [0, 1, 2, 3]}],
|
||||
ram_total_bytes=16 * GiB,
|
||||
ram_available_bytes=12 * GiB,
|
||||
supports_bf16=False,
|
||||
)
|
||||
|
||||
|
||||
def test_materialize_arm64_cpu(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("VLLM_CACHE_ROOT", str(tmp_path / "cache"))
|
||||
path, report = auto_profile.materialize_auto_deploy(
|
||||
"Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice", EDGE, profile=_arm_profile(), out_dir=tmp_path
|
||||
)
|
||||
assert report["hardware_class"] == "arm64_cpu"
|
||||
doc = yaml.safe_load(open(path))
|
||||
assert "base_config" not in doc
|
||||
s0, s1 = doc["stages"]
|
||||
# class overlay pins eager + max_num_seqs 1; derivation adds cpu binding on the big cluster only
|
||||
assert s0["enforce_eager"] is True and s1["enforce_eager"] is True
|
||||
assert s0["max_num_seqs"] == 1
|
||||
assert s0["devices"] == "cpu" and s1["devices"] == "cpu"
|
||||
assert s0["env"]["VLLM_CPU_OMP_THREADS_BIND"] == "4-6"
|
||||
assert s1["env"]["VLLM_CPU_OMP_THREADS_BIND"] == "7"
|
||||
assert s0["engine_args"]["dtype"] == "float32"
|
||||
assert s0["engine_args"]["kv_cache_memory_bytes"] > 0
|
||||
extra = doc["connectors"]["connector_of_shared_memory"]["extra"]
|
||||
assert extra["codec_chunk_adaptive"] is True and extra["codec_chunk_ramp"] == [2, 4, 8, 16, 25]
|
||||
# The result is a valid deploy config.
|
||||
cfg = load_deploy_config(path)
|
||||
assert len(cfg.stages) == 2 and cfg.stages[0].engine_extras["dtype"] == "float32"
|
||||
|
||||
|
||||
def test_calibration_cache_is_applied(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("VLLM_CACHE_ROOT", str(tmp_path / "cache"))
|
||||
prof = _arm_profile()
|
||||
fp = calibrate.hardware_fingerprint(prof, "m")
|
||||
calibrate.save_calibration(
|
||||
fp,
|
||||
{
|
||||
"codec_chunk_ramp": [3, 6, 12, 25],
|
||||
"codec_chunk_min_frames": 3,
|
||||
"codec_chunk_safety_margin_ms": 90.0,
|
||||
"codec_chunk_adaptive": True,
|
||||
},
|
||||
)
|
||||
path, report = auto_profile.materialize_auto_deploy("m", EDGE, profile=prof, out_dir=tmp_path)
|
||||
doc = yaml.safe_load(open(path))
|
||||
extra = doc["connectors"]["connector_of_shared_memory"]["extra"]
|
||||
assert extra["codec_chunk_ramp"] == [3, 6, 12, 25] and extra["codec_chunk_min_frames"] == 3
|
||||
assert report["calibration"]["codec_chunk_ramp"] == [3, 6, 12, 25]
|
||||
|
||||
|
||||
def test_apply_deploy_profile_auto_uses_edge_base(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("VLLM_OMNI_HW_PROFILE", str(tmp_path / "hw.json"))
|
||||
(tmp_path / "hw.json").write_text(_arm_profile().to_json())
|
||||
with mock.patch.object(entry_utils, "resolve_model_config_path", return_value=str(_DEPLOY_DIR / "qwen3_tts.yaml")):
|
||||
args = entry_utils.apply_deploy_profile("Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice", {"deploy_profile": "auto"})
|
||||
assert args["deploy_config"].endswith(".yaml")
|
||||
doc = yaml.safe_load(open(args["deploy_config"]))
|
||||
assert doc["stages"][0]["devices"] == "cpu"
|
||||
assert doc["stages"][0]["max_num_batched_tokens"] == 512 # inherited from edge/qwen3_tts.yaml
|
||||
|
||||
|
||||
def test_hardware_overlay_merge_semantics():
|
||||
doc = {
|
||||
"stages": [{"stage_id": 0, "a": 1, "d": {"x": 1}}, {"stage_id": 1}],
|
||||
"connectors": {"c": {"extra": {"k": 1}}},
|
||||
}
|
||||
out = auto_profile.apply_derived_overrides(
|
||||
doc,
|
||||
{
|
||||
"stages": {0: {"a": 2, "d": {"y": 2}, "gpu_memory_utilization": None}},
|
||||
"top": {"async_chunk": True},
|
||||
"connector_extra": {"z": 3},
|
||||
},
|
||||
)
|
||||
assert out["stages"][0] == {"stage_id": 0, "a": 2, "d": {"x": 1, "y": 2}}
|
||||
assert out["async_chunk"] is True and out["connectors"]["c"]["extra"] == {"k": 1, "z": 3}
|
||||
assert doc["stages"][0]["a"] == 1 # input untouched
|
||||
@@ -0,0 +1,75 @@
|
||||
"""Tests for vllm_omni.edge.calibrate (CPU)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.edge import calibrate as cal
|
||||
from vllm_omni.edge.hardware_probe import HardwareProfile
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
SR = 24000
|
||||
FRAME = 1920
|
||||
|
||||
|
||||
def _chunks(rate_frames_per_s: float, sizes: list[int], ttfa_ms: float = 30.0):
|
||||
"""Synthesize arrivals for a generator producing ``rate`` frames/s."""
|
||||
chunks = []
|
||||
t = ttfa_ms
|
||||
for i, n in enumerate(sizes):
|
||||
if i > 0:
|
||||
t += n * 1000.0 / rate_frames_per_s
|
||||
chunks.append({"t_ms": t, "samples": n * FRAME})
|
||||
return chunks
|
||||
|
||||
|
||||
def test_rate_estimate_from_measured_shape():
|
||||
# measured on L20X: 25 frames every ~160 ms -> ~156 frames/s
|
||||
chunks = [
|
||||
{"t_ms": 30.0, "samples": FRAME},
|
||||
{"t_ms": 190.0, "samples": 25 * FRAME},
|
||||
{"t_ms": 350.0, "samples": 25 * FRAME},
|
||||
]
|
||||
rate = cal.frames_per_second_from_chunks(chunks, SR)
|
||||
assert rate == pytest.approx(50 / 0.32, rel=1e-3)
|
||||
assert cal.frames_per_second_from_chunks(chunks[:1], SR) is None
|
||||
|
||||
|
||||
def test_fast_generator_keeps_small_first_chunk_and_no_adaptive():
|
||||
sched = cal.derive_chunk_schedule(_chunks(150.0, [1, 25, 25, 25]), SR)
|
||||
assert sched["measured"] is True
|
||||
assert sched["rtf"] < 0.2
|
||||
assert sched["codec_chunk_adaptive"] is False
|
||||
assert sched["codec_chunk_min_frames"] == 1
|
||||
assert sched["codec_chunk_ramp"][-1] == 25 and sched["codec_chunk_ramp"][0] == 1
|
||||
|
||||
|
||||
def test_slow_generator_needs_lead_and_adaptive():
|
||||
# 10 frames/s < 12.5 real time: each 25-frame chunk takes 2.5 s to make but plays 2.0 s
|
||||
sched = cal.derive_chunk_schedule(_chunks(10.0, [2, 4, 8, 16, 25, 25]), SR)
|
||||
assert sched["rtf"] > 1.0
|
||||
assert sched["codec_chunk_adaptive"] is True
|
||||
assert sched["codec_chunk_min_frames"] >= 7 # (40 + 20*25) / 80 -> 6.75 -> 7
|
||||
assert sched["codec_chunk_ramp"][-1] == 25
|
||||
assert all(a < b for a, b in zip(sched["codec_chunk_ramp"], sched["codec_chunk_ramp"][1:]))
|
||||
extra = cal.connector_extra_from_calibration(sched)
|
||||
assert extra["codec_chunk_adaptive"] is True and extra["codec_chunk_ramp"][-1] == 25
|
||||
|
||||
|
||||
def test_unmeasurable_falls_back_to_defaults():
|
||||
sched = cal.derive_chunk_schedule([{"t_ms": 30.0, "samples": FRAME}], SR)
|
||||
assert sched["measured"] is False and sched["codec_chunk_ramp"] == [2, 4, 8, 16, 25]
|
||||
|
||||
|
||||
def test_cache_roundtrip(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("VLLM_CACHE_ROOT", str(tmp_path))
|
||||
prof = HardwareProfile(arch="x86_64", cpu_model="x", n_physical=8, gpu_name="", gpu_mem_bytes=0)
|
||||
fp = cal.hardware_fingerprint(prof, "Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice")
|
||||
assert len(fp) == 16
|
||||
assert cal.load_calibration(fp) is None
|
||||
p = cal.save_calibration(fp, {"codec_chunk_ramp": [1, 25]})
|
||||
assert p.parent == tmp_path / "omni_edge"
|
||||
assert cal.load_calibration(fp) == {"codec_chunk_ramp": [1, 25]}
|
||||
# different model -> different fingerprint
|
||||
assert cal.hardware_fingerprint(prof, "other") != fp
|
||||
@@ -0,0 +1,117 @@
|
||||
"""Tests for vllm_omni.edge.hardware_probe using synthetic /proc and /sys snapshots (CPU)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.edge import hardware_probe as hp
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
X86_CPUINFO = """processor\t: 0
|
||||
model name\t: Intel(R) Xeon(R) Platinum 8480C
|
||||
flags\t\t: fpu sse avx2 avx512f avx512_bf16 amx_bf16 amx_tile fma f16c
|
||||
processor\t: 1
|
||||
model name\t: Intel(R) Xeon(R) Platinum 8480C
|
||||
flags\t\t: fpu sse avx2 avx512f avx512_bf16 amx_bf16 amx_tile fma f16c
|
||||
"""
|
||||
|
||||
ARM_CPUINFO = """processor\t: 0
|
||||
Features\t: fp asimd evtstrm aes asimdhp asimddp
|
||||
processor\t: 1
|
||||
Features\t: fp asimd evtstrm aes asimdhp asimddp
|
||||
processor\t: 2
|
||||
Features\t: fp asimd evtstrm aes asimdhp asimddp i8mm bf16
|
||||
processor\t: 3
|
||||
Features\t: fp asimd evtstrm aes asimdhp asimddp i8mm bf16
|
||||
Hardware\t: Rockchip RK3588
|
||||
"""
|
||||
|
||||
MEMINFO = "MemTotal: 16000000 kB\nMemFree: 1000000 kB\nMemAvailable: 12000000 kB\n"
|
||||
|
||||
|
||||
def _write_sysfs(root: Path, cpus: dict[int, tuple[int, int]], numa: int = 1, thermal: int = 2, tegra: bool = False):
|
||||
for cpu, (max_khz, core_id) in cpus.items():
|
||||
d = root / "sys" / "devices" / "system" / "cpu" / f"cpu{cpu}"
|
||||
(d / "cpufreq").mkdir(parents=True, exist_ok=True)
|
||||
(d / "topology").mkdir(parents=True, exist_ok=True)
|
||||
(d / "cpufreq" / "cpuinfo_max_freq").write_text(str(max_khz))
|
||||
(d / "topology" / "core_id").write_text(str(core_id))
|
||||
(d / "topology" / "physical_package_id").write_text("0")
|
||||
for n in range(numa):
|
||||
(root / "sys" / "devices" / "system" / "node" / f"node{n}").mkdir(parents=True, exist_ok=True)
|
||||
for t in range(thermal):
|
||||
(root / "sys" / "class" / "thermal" / f"thermal_zone{t}").mkdir(parents=True, exist_ok=True)
|
||||
if tegra:
|
||||
(root / "etc").mkdir(parents=True, exist_ok=True)
|
||||
(root / "etc" / "nv_tegra_release").write_text("# R36 (release), REVISION: 4.0")
|
||||
|
||||
|
||||
def _snapshot(tmp_path: Path, cpuinfo: str, meminfo: str = MEMINFO, **kw) -> Path:
|
||||
root = tmp_path / "root"
|
||||
(root / "proc").mkdir(parents=True)
|
||||
(root / "proc" / "cpuinfo").write_text(cpuinfo)
|
||||
(root / "proc" / "meminfo").write_text(meminfo)
|
||||
_write_sysfs(root, **kw)
|
||||
return root
|
||||
|
||||
|
||||
def test_x86_amx_snapshot(tmp_path):
|
||||
root = _snapshot(tmp_path, X86_CPUINFO, cpus={0: (3800000, 0), 1: (3800000, 0)}, numa=2)
|
||||
p = hp.probe(root, use_torch=False)
|
||||
assert p.arch == "x86_64"
|
||||
assert p.has("avx2", "avx512", "avx512_bf16", "amx_bf16", "amx_tile")
|
||||
assert p.n_logical == 2 and p.n_physical == 1 # two hyper-threads of one core
|
||||
assert p.numa_nodes == 2 and p.thermal_zones == 2
|
||||
assert p.ram_total_bytes == 16000000 * 1024 and p.ram_available_bytes == 12000000 * 1024
|
||||
assert p.accelerator == "none" and p.supports_bf16 is True
|
||||
assert hp.hardware_class(p) == hp.HW_CLASS_X86_CPU
|
||||
assert p.clusters == [{"max_khz": 3800000, "cpus": [0, 1]}]
|
||||
|
||||
|
||||
def test_arm_big_little_snapshot(tmp_path):
|
||||
root = _snapshot(tmp_path, ARM_CPUINFO, cpus={0: (1800000, 0), 1: (1800000, 1), 2: (2400000, 2), 3: (2400000, 3)})
|
||||
p = hp.probe(root, use_torch=False)
|
||||
assert p.arch == "aarch64"
|
||||
assert p.has("neon", "fp16_arith", "dotprod", "i8mm", "bf16")
|
||||
assert p.cpu_model == "Rockchip RK3588"
|
||||
assert p.clusters[0] == {"max_khz": 2400000, "cpus": [2, 3]} # big cluster first
|
||||
assert p.big_cpus == [2, 3]
|
||||
assert p.n_physical == 4
|
||||
assert hp.hardware_class(p) == hp.HW_CLASS_ARM64_CPU
|
||||
assert p.supports_bf16 is True and p.supports_fp16 is True
|
||||
|
||||
|
||||
def test_tegra_snapshot_is_jetson_with_unified_memory(tmp_path):
|
||||
root = _snapshot(tmp_path, ARM_CPUINFO, cpus={0: (2200000, 0)}, tegra=True)
|
||||
p = hp.probe(root, use_torch=False)
|
||||
assert p.accelerator == "cuda_unified"
|
||||
assert p.gpu_mem_bytes == p.ram_total_bytes
|
||||
assert hp.hardware_class(p) == hp.HW_CLASS_JETSON
|
||||
|
||||
|
||||
def test_override_env_and_roundtrip(tmp_path, monkeypatch):
|
||||
prof = hp.HardwareProfile(
|
||||
arch="aarch64", cpu_flags=["neon"], n_logical=8, accelerator="npu:qualcomm", ram_total_bytes=8 * 2**30
|
||||
)
|
||||
path = tmp_path / "hw.json"
|
||||
path.write_text(prof.to_json())
|
||||
monkeypatch.setenv(hp.ENV_OVERRIDE, str(path))
|
||||
loaded = hp.load_profile(use_torch=False)
|
||||
assert loaded.source.startswith("override:")
|
||||
assert loaded.accelerator == "npu:qualcomm"
|
||||
assert hp.hardware_class(loaded) == hp.HW_CLASS_NPU_PHONE
|
||||
# unknown keys are ignored on load
|
||||
d = json.loads(prof.to_json())
|
||||
d["future_field"] = 1
|
||||
assert hp.HardwareProfile.from_dict(d).n_logical == 8
|
||||
assert "class=npu_phone" in hp.describe(loaded)
|
||||
|
||||
|
||||
def test_live_probe_runs_on_this_host():
|
||||
p = hp.probe(use_torch=False)
|
||||
assert p.n_logical >= 1 and p.ram_total_bytes > 0
|
||||
assert hp.hardware_class(p) in hp.HW_CLASSES
|
||||
Reference in new issue
Block a user