multimodalart HF Staff commited on
Commit
ede5e57
·
verified ·
1 Parent(s): 8b422c9

fp8 fuse: fall back to CPU SR when Triton has no real device

Browse files
packages/ltx-core/src/ltx_core/quantization/fp8_cast.py CHANGED
@@ -241,8 +241,15 @@ def fuse_cast_fp8_weight(
241
  if delta_bf16.dtype != torch.bfloat16:
242
  raise ValueError(f"delta_bf16 must be bfloat16, got {delta_bf16.dtype}")
243
  if str(weight_fp8.device).startswith("cuda") and TRITON_AVAILABLE:
244
- fused_add_round_launch(delta_bf16, weight_fp8, seed=0)
245
- return delta_bf16.to(dtype=weight_fp8.dtype)
 
 
 
 
 
 
 
246
  if weight_fp8.dtype == torch.float8_e4m3fn:
247
  return _stochastic_round_add_fp8_e4m3_cpu(delta_bf16, weight_fp8).to(dtype=weight_fp8.dtype)
248
  # e5m2 / other: deterministic fallback.
 
241
  if delta_bf16.dtype != torch.bfloat16:
242
  raise ValueError(f"delta_bf16 must be bfloat16, got {delta_bf16.dtype}")
243
  if str(weight_fp8.device).startswith("cuda") and TRITON_AVAILABLE:
244
+ try:
245
+ fused_add_round_launch(delta_bf16, weight_fp8, seed=0)
246
+ return delta_bf16.to(dtype=weight_fp8.dtype)
247
+ except Exception:
248
+ # No REAL CUDA device (e.g. the ZeroGPU main process, where `spaces`
249
+ # fakes cuda availability). Fall through to the CPU path on dealiased
250
+ # real-CPU tensors so the Triton stream lookup can't crash us.
251
+ delta_bf16 = delta_bf16.detach().to("cpu")
252
+ weight_fp8 = weight_fp8.detach().to("cpu")
253
  if weight_fp8.dtype == torch.float8_e4m3fn:
254
  return _stochastic_round_add_fp8_e4m3_cpu(delta_bf16, weight_fp8).to(dtype=weight_fp8.dtype)
255
  # e5m2 / other: deterministic fallback.