Skip to content
Merged
Changes from 2 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
12 changes: 9 additions & 3 deletions vllm_omni/diffusion/offloader/module_residency.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ def __init__(
self.min_free_fraction = min_free_fraction

def _should_release(self) -> bool:
reserved = int(torch.accelerator.memory_reserved(self.device))
allocated = int(torch.accelerator.memory_allocated(self.device))
if self.device.type == "npu":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a CPU regression test for the NPU branch? The current allocator tests use a CPU device and only mock torch.accelerator, so they still pass if this fix is reverted. A fake registered device module could cover retention, threshold release and forced cleanup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in ac461aea1: seven CPU cases using the repository's mocker fixture and the existing core_model / cpu marks.

They cover retention, the exact 25% cached-memory / 5% free-memory boundaries, release above/below those thresholds, unavailable registered-device telemetry, and forced cleanup. The tests explicitly require torch.get_device_module(device) and the registered module's memory APIs, and assert that the generic torch.accelerator queries are not called. Forced cleanup must bypass all telemetry.

Validation:

  • Full allocator/staging test file: 15 passed.
  • Reverting only the NPU production branch, with the same tests: 6 failed, 9 passed. All six NPU telemetry cases detect the regression; forced cleanup remains valid.
  • All applicable pre-commit checks, including mypy, CI marks, import restrictions and sign-off, passed.

This follow-up changes only tests/diffusion/offloader/test_module_residency.py; production code is unchanged.

Reproduce in the repository test environment:

python -m pytest -q tests/diffusion/offloader/test_module_residency.py -m "core_model and cpu" --run-level core_model

# The NPU allocator does not implement the generic DeviceAllocator interface.
device_module = torch.get_device_module(self.device)
reserved = int(device_module.memory_reserved(self.device))
allocated = int(device_module.memory_allocated(self.device))
else:
reserved = int(torch.accelerator.memory_reserved(self.device))
allocated = int(torch.accelerator.memory_allocated(self.device))
free, total = current_omni_platform.get_device_memory(self.device)
cached = max(0, reserved - allocated)
return cached > int(total * self.max_cached_fraction) or free < int(total * self.min_free_fraction)
Expand All @@ -66,7 +72,7 @@ def release_if_needed(self, *, force: bool = False) -> bool:
return False
except Exception as exc:
# Preserve the pre-retention behavior on platforms that do not
# expose allocator telemetry through torch.accelerator.
# expose allocator telemetry.
logger.debug("Allocator cache telemetry unavailable; releasing cache: %s", exc)
current_omni_platform.empty_cache()
return True
Expand Down
Loading