[BugFix][Diffusion] Add CPU LAPACK fallback for FlowUniPC (#5329)

Signed-off-by: akshatvishu <akshatnayak197@gmail.com>
This commit is contained in:
akshatvishu authored and GitHub committed 2026-07-30 15:09:48 +00:00
1 parent 86d7864588
commit 4563999ec0
4 files changed
+84 -7

No files matched your search

@@ -23,6 +23,7 @@ from diffusers.schedulers.scheduling_utils import KarrasDiffusionSchedulers, Sch
from diffusers.utils import deprecate
from vllm_omni.diffusion.models.schedulers.base import BaseScheduler
from vllm_omni.diffusion.utils.flow_matching import safe_linalg_solve
class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin, BaseScheduler):
@@ -431,7 +432,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin, BaseScheduler):
rhos_p = torch.tensor([0.5], dtype=x.dtype, device=device)
else:
assert isinstance(R, torch.Tensor)
rhos_p = torch.linalg.solve(R[:-1, :-1], b[:-1]).to(device).to(x.dtype)
rhos_p = safe_linalg_solve(R[:-1, :-1], b[:-1]).to(device).to(x.dtype)
else:
D1s = None
@@ -565,7 +566,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin, BaseScheduler):
if order == 1:
rhos_c = torch.tensor([0.5], dtype=x.dtype, device=device)
else:
rhos_c = torch.linalg.solve(R, b).to(device).to(x.dtype)
rhos_c = safe_linalg_solve(R, b).to(device).to(x.dtype)
if self.predict_x0:
x_t_ = sigma_t / sigma_s0 * x - alpha_t * h_phi_1 * m0
@@ -3,10 +3,22 @@
import math
import numpy as np
import torch
from torch import nn
def safe_linalg_solve(matrix: torch.Tensor, rhs: torch.Tensor) -> torch.Tensor:
try:
return torch.linalg.solve(matrix, rhs)
except RuntimeError as exc:
if matrix.device.type != "cpu" or "requires compiling PyTorch with LAPACK" not in str(exc):
raise
# Some ROCm wheels still fail here at runtime even when the LAPACK probe reports support.
solved = np.linalg.solve(matrix.detach().cpu().numpy(), rhs.detach().cpu().numpy())
return torch.from_numpy(solved).to(device=matrix.device, dtype=matrix.dtype)
def swish(x: torch.Tensor) -> torch.Tensor:
return x * torch.sigmoid(x)