Repository navigation
[Perf][Diffusion] Activate NPU/GPU matmul for LoRA delta computation when weights are on CPU #7590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| from safetensors.torch import load_file | ||
| from vllm.logger import init_logger | ||
|
|
||
| from vllm_omni.diffusion.distributed.utils import get_local_device | ||
| from vllm_omni.diffusion.utils.tf_utils import get_transformer_from_pipeline | ||
| from vllm_omni.transformers_utils.repo_utils import hf_api | ||
|
|
||
|
|
@@ -120,6 +121,22 @@ def _prepare_lora_delta( | |
| return delta, used_keys | ||
|
|
||
|
|
||
| def _resolve_lora_compute_device() -> torch.device | None: | ||
| """Return the local accelerator device if actually usable, else None. | ||
|
|
||
| get_local_device() may return cuda:N/npu:N even when no physical device is | ||
| present, so probe with a tiny allocation before trusting the lookup. | ||
| """ | ||
| try: | ||
| dev = get_local_device() | ||
| if dev.type != "cpu": | ||
| torch.empty(1, device=dev) | ||
| return dev | ||
| except Exception: | ||
| pass | ||
| return None | ||
|
|
||
|
|
||
| def _load_lora_state_dict( | ||
| pretrained_model_name_or_path: str, | ||
| weights_name: str | None = None, | ||
|
|
@@ -270,6 +287,9 @@ def load_lora_into_module( | |
| for param_name, weight_name, _ in module.stacked_params_mapping: | ||
| param_to_weight_names[param_name].append(weight_name) | ||
|
|
||
| # Resolve the accelerator fallback once, outside the parameter loop. | ||
| accel_dev = _resolve_lora_compute_device() | ||
|
|
||
| for name, params in module.named_parameters(prefix): | ||
| is_bias = False | ||
| if name.endswith(".bias"): | ||
|
|
@@ -280,7 +300,7 @@ def load_lora_into_module( | |
| else: | ||
| continue | ||
|
|
||
| compute_dev = params.device if params.device.type != "cpu" else None | ||
| compute_dev = params.device if params.device.type != "cpu" else accel_dev | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the line that actually activates NPU/GPU matmul for CPU weights, and nothing in the new tests observes it. A regression that restores
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed: Added test_load_lora_into_module_forwards_usable_accel_device : |
||
| delta, used_keys = _prepare_lora_delta( | ||
| state_dict, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No regression test covers the bug this PR describes:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed: |
||
| base_key, | ||
|
|
@@ -324,6 +344,9 @@ def unload_module_lora( | |
| for param_name, weight_name, _ in module.stacked_params_mapping: | ||
| param_to_weight_names[param_name].append(weight_name) | ||
|
|
||
| # Resolve the accelerator fallback once, outside the parameter loop. | ||
| accel_dev = _resolve_lora_compute_device() | ||
|
|
||
| for name, param in module.named_parameters(prefix): | ||
| is_bias = False | ||
| if name.endswith(".bias"): | ||
|
|
@@ -334,7 +357,7 @@ def unload_module_lora( | |
| else: | ||
| continue | ||
|
|
||
| compute_dev = param.device if param.device.type != "cpu" else None | ||
| compute_dev = param.device if param.device.type != "cpu" else accel_dev | ||
| delta, used_keys = _prepare_lora_delta( | ||
| state_dict, | ||
| base_key, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patches
get_local_devicetocuda:999, so_resolve_lora_compute_device()returnsNoneandload_lora_into_modulenever takes the #7005 accelerator path. The assertion only checks CPUbase + B @ Aafter fallback — the same result as the pre-fixcompute_dev = Nonebehavior. Add a second test that patches_resolve_lora_compute_deviceto a non-CPU device, spies_prepare_lora_delta, assertscompute_deviceis that device for CPU params, and setscompute_device=Noneinside the spy so the numerical check can stay on CPU.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: Added
test_load_lora_into_module_forwards_usable_accel_device:_resolve_lora_compute_deviceto return a non-CPU device, bypassing the probe to simulate a usable accelerator._prepare_lora_deltaand asserts every CPU param receives that device ascompute_device— this fails if the assignment regresses back toelse None.compute_device=Nonefor the actual math, so the numerical check still runs on CPU without a physical device.21 tests pass on a no-GPU/NPU container.