Merge remote-tracking branch 'origin/main' into qwen-image-2.1
# Conflicts: # vllm_omni/diffusion/executor/multiproc_executor.py # vllm_omni/diffusion/offloader/sequential_backend.py
This commit is contained in:
commit
9174554e40
1332 files changed
+160051
-60504
No files matched your search
@@ -13,6 +13,7 @@ from diffusers.loaders.lora_conversion_utils import (
|
||||
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
|
||||
|
||||
@@ -48,6 +49,7 @@ def _prepare_lora_delta(
|
||||
lora_a_suffix: str = "lora_A.weight",
|
||||
lora_b_suffix: str = "lora_B.weight",
|
||||
lora_bias_suffix: str = "bias",
|
||||
compute_device: torch.device | None = None,
|
||||
):
|
||||
used_keys: set[str] = set()
|
||||
# stacked_params_mapping param_to_weight_names
|
||||
@@ -75,6 +77,8 @@ def _prepare_lora_delta(
|
||||
if lora_bias_key not in lora_state_dict:
|
||||
return None, used_keys
|
||||
delta = lora_state_dict[lora_bias_key]
|
||||
if compute_device is not None and compute_device.type != "cpu":
|
||||
delta = delta.to(compute_device)
|
||||
stacked_deltas.append(delta)
|
||||
used_keys.add(lora_bias_key)
|
||||
else:
|
||||
@@ -85,6 +89,9 @@ def _prepare_lora_delta(
|
||||
return None, used_keys
|
||||
a = lora_state_dict[lora_a_key]
|
||||
b = lora_state_dict[lora_b_key]
|
||||
if compute_device is not None and compute_device.type != "cpu":
|
||||
a = a.to(compute_device)
|
||||
b = b.to(compute_device)
|
||||
delta = torch.matmul(b, a)
|
||||
stacked_deltas.append(delta)
|
||||
used_keys.add(lora_a_key)
|
||||
@@ -99,7 +106,10 @@ def _prepare_lora_delta(
|
||||
if lora_bias_key not in lora_state_dict:
|
||||
return None, used_keys
|
||||
used_keys.add(lora_bias_key)
|
||||
return lora_state_dict[lora_bias_key], used_keys
|
||||
delta = lora_state_dict[lora_bias_key]
|
||||
if compute_device is not None and compute_device.type != "cpu":
|
||||
delta = delta.to(compute_device)
|
||||
return delta, used_keys
|
||||
|
||||
lora_a_key = f"{base_key}.{lora_a_suffix}"
|
||||
lora_b_key = f"{base_key}.{lora_b_suffix}"
|
||||
@@ -107,9 +117,29 @@ def _prepare_lora_delta(
|
||||
return None, used_keys
|
||||
a = lora_state_dict[lora_a_key]
|
||||
b = lora_state_dict[lora_b_key]
|
||||
if compute_device is not None and compute_device.type != "cpu":
|
||||
a = a.to(compute_device)
|
||||
b = b.to(compute_device)
|
||||
delta = torch.matmul(b, a)
|
||||
used_keys.add(lora_a_key)
|
||||
used_keys.add(lora_b_key)
|
||||
return torch.matmul(b, a), used_keys
|
||||
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(
|
||||
@@ -262,6 +292,9 @@ class LoraLoaderMixin:
|
||||
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"):
|
||||
@@ -272,6 +305,7 @@ class LoraLoaderMixin:
|
||||
else:
|
||||
continue
|
||||
|
||||
compute_dev = params.device if params.device.type != "cpu" else accel_dev
|
||||
delta, used_keys = _prepare_lora_delta(
|
||||
state_dict,
|
||||
base_key,
|
||||
@@ -280,6 +314,7 @@ class LoraLoaderMixin:
|
||||
lora_a_suffix,
|
||||
lora_b_suffix,
|
||||
lora_bias_suffix,
|
||||
compute_device=compute_dev,
|
||||
)
|
||||
if delta is None:
|
||||
continue
|
||||
@@ -314,6 +349,9 @@ class LoraLoaderMixin:
|
||||
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"):
|
||||
@@ -324,6 +362,7 @@ class LoraLoaderMixin:
|
||||
else:
|
||||
continue
|
||||
|
||||
compute_dev = param.device if param.device.type != "cpu" else accel_dev
|
||||
delta, used_keys = _prepare_lora_delta(
|
||||
state_dict,
|
||||
base_key,
|
||||
@@ -332,6 +371,7 @@ class LoraLoaderMixin:
|
||||
lora_a_suffix,
|
||||
lora_b_suffix,
|
||||
lora_bias_suffix,
|
||||
compute_device=compute_dev,
|
||||
)
|
||||
if delta is None:
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user