[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

@@ -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)