linting and debugs

This commit is contained in:
Kohaku-Blueleaf 2024-01-09 22:53:58 +08:00
parent 42e6df723c
commit c2c05fcca8
1 changed files with 6 additions and 6 deletions

View File

@ -140,20 +140,20 @@ def manual_cast_forward(target_dtype):
): ):
args = [arg.to(target_dtype) if isinstance(arg, torch.Tensor) else arg for arg in args] args = [arg.to(target_dtype) if isinstance(arg, torch.Tensor) else arg for arg in args]
kwargs = {k: v.to(target_dtype) if isinstance(v, torch.Tensor) else v for k, v in kwargs.items()} kwargs = {k: v.to(target_dtype) if isinstance(v, torch.Tensor) else v for k, v in kwargs.items()}
org_dtype = torch_utils.get_param(self).dtype org_dtype = torch_utils.get_param(self).dtype
if org_dtype != target_dtype: if org_dtype != target_dtype:
self.to(target_dtype) self.to(target_dtype)
result = self.org_forward(*args, **kwargs) result = self.org_forward(*args, **kwargs)
if org_dtype != target_dtype: if org_dtype != target_dtype:
self.to(org_dtype) self.to(org_dtype)
if target_dtype != dtype_inference: if target_dtype != dtype_inference:
if isinstance(result, tuple): if isinstance(result, tuple):
result = tuple( result = tuple(
i.to(dtype_inference) i.to(dtype_inference)
if isinstance(i, torch.Tensor) if isinstance(i, torch.Tensor)
else i else i
for i in result for i in result
) )
elif isinstance(result, torch.Tensor): elif isinstance(result, torch.Tensor):
@ -185,7 +185,7 @@ def autocast(disable=False):
if fp8 and device==cpu: if fp8 and device==cpu:
return torch.autocast("cpu", dtype=torch.bfloat16, enabled=True) return torch.autocast("cpu", dtype=torch.bfloat16, enabled=True)
if dtype == torch.float32 and shared.cmd_opts.precision == "full": if dtype == torch.float32:
return contextlib.nullcontext() return contextlib.nullcontext()
if has_xpu() or has_mps() or cuda_no_autocast(): if has_xpu() or has_mps() or cuda_no_autocast():