mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2025-12-24 21:44:43 +08:00
Fix nan issue when quantizing fp16 tensor. (#11213)
This commit is contained in:
parent
e2a800e7ef
commit
791e30ff50
@ -399,7 +399,10 @@ class TensorCoreFP8Layout(QuantizedLayout):
|
||||
orig_dtype = tensor.dtype
|
||||
|
||||
if isinstance(scale, str) and scale == "recalculate":
|
||||
scale = torch.amax(tensor.abs()) / torch.finfo(dtype).max
|
||||
scale = torch.amax(tensor.abs()).to(dtype=torch.float32) / torch.finfo(dtype).max
|
||||
if tensor.dtype not in [torch.float32, torch.bfloat16]: # Prevent scale from being too small
|
||||
tensor_info = torch.finfo(tensor.dtype)
|
||||
scale = (1.0 / torch.clamp((1.0 / scale), min=tensor_info.min, max=tensor_info.max))
|
||||
|
||||
if scale is not None:
|
||||
if not isinstance(scale, torch.Tensor):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user