[XPU][Diffusion] Plain-torch scale-shift for inductor (#41885)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
6e7beace14
commit
5d8e98b7fd
@@ -37,7 +37,7 @@ class MulAdd(CustomOp):
|
||||
def forward_xpu(
|
||||
self, a: torch.Tensor, b: torch.Tensor, c: torch.Tensor, k: int = 0
|
||||
):
|
||||
return self.forward_cuda(a, b, c, k=k)
|
||||
return self.forward_native(a, b, c, k=k).to(a.dtype)
|
||||
|
||||
@torch.compile
|
||||
def forward_musa(
|
||||
|
||||
@@ -915,10 +915,21 @@ class _NormScaleShift(CustomOp):
|
||||
# so we fall back to the native PyTorch implementation.
|
||||
return self.forward_native(*args, **kwargs)
|
||||
|
||||
def forward_xpu(self, *args, **kwargs):
|
||||
# XPU does not support CUDA/CUTLASS-based fused kernels yet,
|
||||
# so we fall back to the native PyTorch implementation.
|
||||
return self.forward_native(*args, **kwargs)
|
||||
def forward_xpu(
|
||||
self, x: torch.Tensor, shift: torch.Tensor, scale: torch.Tensor
|
||||
) -> torch.Tensor:
|
||||
normalized = self.norm(x)
|
||||
if scale.dim() == 4:
|
||||
# scale/shift: [batch_size, num_frames, 1, inner_dim]
|
||||
num_frames = scale.shape[1]
|
||||
frame_seqlen = normalized.shape[1] // num_frames
|
||||
modulated = (
|
||||
normalized.unflatten(1, (num_frames, frame_seqlen)) * (1 + scale)
|
||||
+ shift
|
||||
).flatten(1, 2)
|
||||
else:
|
||||
modulated = normalized * (1 + scale) + shift
|
||||
return modulated.to(x.dtype)
|
||||
|
||||
@torch.compile(disable=current_platform.is_npu() or current_platform.is_rocm())
|
||||
def forward_native(
|
||||
|
||||
Reference in New Issue
Block a user