Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions src/diffusers/quantizers/torchao/torchao_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,7 @@ def _update_torch_safe_globals():
(torch.uint6, "torch.uint6"),
(torch.uint7, "torch.uint7"),
]
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should then pin the minimum version of torchao in here. Otherwise, this seems like a breaking change to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, i'll defer this change to a time when diffusers upgrades minimum torchao version. The try-catch already handles the deletion I am mentioning gracefully. Thanks!

from torchao.dtypes import NF4Tensor
from torchao.dtypes.uintx.uintx_layout import UintxAQTTensorImpl, UintxTensor

safe_globals.extend([UintxTensor, UintxAQTTensorImpl, NF4Tensor])

# note: is_torchao_version(">=", "0.16.0") does not work correctly
# with torchao nightly, so using a ">" check which does work correctly
if is_torchao_version(">", "0.15.0"):
pass
else:
from torchao.dtypes.floatx.float8_layout import Float8AQTTensorImpl
from torchao.dtypes.uintx.uint4_layout import UInt4Tensor

safe_globals.extend([UInt4Tensor, Float8AQTTensorImpl])

except (ImportError, ModuleNotFoundError) as e:
logger.warning(
"Unable to import `torchao` Tensor objects. This may affect loading checkpoints serialized with `torchao`"
)
logger.debug(e)

finally:
torch.serialization.add_safe_globals(safe_globals=safe_globals)
torch.serialization.add_safe_globals(safe_globals=safe_globals)


if (
Expand Down
Loading