[Diffusion] Register HWR mmap for direct DLO H2D (#6591)

Signed-off-by: Hongsheng Liu <liuhongsheng4@huawei.com>
Signed-off-by: hsliuustc0106 <hsliuustc0106@users.noreply.github.com>
Co-authored-by: hsliuustc0106 <hsliuustc0106@users.noreply.github.com>
This commit is contained in:
Hongsheng Liuandhsliuustc0106 authored and GitHub committed 2026-08-25 23:30:11 +08:00
1 parent 5a8b81ebeb
commit c608910d20
28 files changed
+1869 -153

No files matched your search

@@ -57,7 +57,9 @@ from vllm_omni.host_weight_runtime.filesystem import (
detect_storage_class,
)
from vllm_omni.host_weight_runtime.filesystem import store as filesystem_store_module
from vllm_omni.host_weight_runtime.filesystem import writer as filesystem_writer_module
from vllm_omni.host_weight_runtime.filesystem.locks import FileLock
from vllm_omni.host_weight_runtime.filesystem.writer import ArtifactWriterError, FilesystemArtifactWriter
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
@@ -110,6 +112,150 @@ def _open_fd_targets() -> tuple[str, ...]:
return tuple(targets)
def _direct_writer(tmp_path: Path) -> FilesystemArtifactWriter:
staging = tmp_path / "staging"
staging.mkdir()
return FilesystemArtifactWriter(staging, capacity_check=lambda _projected, _additional: None)
def test_ordered_writer_hashes_payload_during_writes(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
writer = _direct_writer(tmp_path)
weight = _weight()
scale = torch.tensor([1.0, 2.0])
def fail_rescan(_path: Path, _specs: tuple[TensorWriteSpec, ...]) -> object:
raise AssertionError("ordered payload must not be rescanned")
monkeypatch.setattr(filesystem_writer_module, "_scan_payload", fail_rescan)
with writer.open_tensor_file("weights.safetensors", _specs(), ordered=True) as output:
# The writer's ordered contract follows canonical storage-key order.
output.write_tensor("layer.scale", scale)
output.write_rows("layer.weight", 0, weight[:2])
output.write_rows("layer.weight", 2, weight[2:])
manifest, _ = writer.finalize(_identity(), ProductionMetadata("test-producer-v1", "test-restorer-v1"))
payload = writer.staging_dir / "weights.safetensors"
assert manifest.files[0].sha256 == hashlib.sha256(payload.read_bytes()).hexdigest()
expected_tensor_digests = {
"layer.scale": hashlib.sha256(memoryview(scale.view(torch.uint8).numpy())).hexdigest(),
"layer.weight": hashlib.sha256(memoryview(weight.contiguous().view(torch.uint8).numpy())).hexdigest(),
}
assert {entry.name: entry.sha256 for entry in manifest.tensors} == expected_tensor_digests
def test_ordered_writer_rejects_out_of_order_payload(tmp_path: Path) -> None:
writer = _direct_writer(tmp_path)
output = writer.open_tensor_file("weights.safetensors", _specs(), ordered=True)
with pytest.raises(ArtifactWriterError, match="ordered tensor payload expected offset"):
output.write_tensor("layer.weight", _weight())
output.abort()
assert not list(writer.staging_dir.iterdir())
def test_payload_fsync_overlaps_producer_work(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
writer = _direct_writer(tmp_path)
started = threading.Event()
release = threading.Event()
closed = threading.Event()
original_fsync = filesystem_writer_module._fsync_payload
def blocking_fsync(fd: int) -> None:
started.set()
if not release.wait(timeout=5):
raise TimeoutError("test did not release payload fsync")
original_fsync(fd)
monkeypatch.setattr(filesystem_writer_module, "_fsync_payload", blocking_fsync)
output = writer.open_tensor_file("weights.safetensors", _specs(), ordered=True)
output.write_tensor("layer.scale", torch.tensor([1.0, 2.0]))
output.write_tensor("layer.weight", _weight())
close_errors: list[BaseException] = []
def close_output() -> None:
try:
output.close()
except BaseException as exc:
close_errors.append(exc)
finally:
closed.set()
close_thread = threading.Thread(target=close_output)
close_thread.start()
try:
assert started.wait(timeout=2)
assert closed.wait(timeout=1), "payload close waited for fsync instead of overlapping it"
finally:
release.set()
close_thread.join(timeout=5)
assert not close_errors
writer.finalize(_identity(), ProductionMetadata("test-producer-v1", "test-restorer-v1"))
def test_payload_fsync_failure_prevents_publication(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
writer = _direct_writer(tmp_path)
def failing_fsync(fd: int) -> None:
try:
raise OSError(errno.EIO, "injected fsync failure")
finally:
os.close(fd)
monkeypatch.setattr(filesystem_writer_module, "_fsync_payload", failing_fsync)
with writer.open_tensor_file("weights.safetensors", _specs(), ordered=True) as output:
output.write_tensor("layer.scale", torch.tensor([1.0, 2.0]))
output.write_tensor("layer.weight", _weight())
with pytest.raises(OSError, match="injected fsync failure"):
writer.finalize(_identity(), ProductionMetadata("test-producer-v1", "test-restorer-v1"))
assert not (writer.staging_dir / "manifest.json").exists()
assert not (writer.staging_dir / "READY.json").exists()
def test_unordered_payload_fallback_hashes_files_in_parallel(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
writer = _direct_writer(tmp_path)
specs = (
TensorWriteSpec("a", (2,), torch.float32),
TensorWriteSpec("b", (2,), torch.float32),
)
for name, spec in zip(("a.safetensors", "b.safetensors"), specs, strict=True):
with writer.open_tensor_file(name, (spec,)) as output:
output.write_tensor(spec.name, torch.tensor([1.0, 2.0]))
original_scan = filesystem_writer_module._scan_payload
barrier = threading.Barrier(2)
thread_ids: set[int] = set()
thread_ids_lock = threading.Lock()
def synchronized_scan(path: Path, file_specs: tuple[TensorWriteSpec, ...]) -> object:
with thread_ids_lock:
thread_ids.add(threading.get_ident())
barrier.wait(timeout=5)
return original_scan(path, file_specs)
monkeypatch.setattr(filesystem_writer_module, "_scan_payload", synchronized_scan)
manifest, _ = writer.finalize(_identity(), ProductionMetadata("test-producer-v1", "test-restorer-v1"))
assert len(manifest.files) == 2
assert len(thread_ids) == 2
class FakeProducer:
def __init__(
self,
@@ -1026,7 +1172,9 @@ def test_store_and_free_space_capacity_limits_fail_before_publication(tmp_path:
free_root = tmp_path / "free-limit"
free_root.mkdir(mode=0o700)
unavailable_reserve = shutil.disk_usage(free_root).free + 1
# Leave enough margin for filesystem accounting to move between the
# preflight measurement and the capacity check.
unavailable_reserve = shutil.disk_usage(free_root).free + (1 << 30)
free_limited = _make_store(free_root, capacity=CapacityPolicy(min_free_bytes=unavailable_reserve))
free_result = free_limited.get_or_build(
BuildRequest(identity),