Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom ops loading in diffusers #1655

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 0 additions & 4 deletions examples/stable-diffusion/text_to_image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,6 @@ def main():

kwargs_call["quant_mode"] = args.quant_mode

if args.quant_mode != "disable":
# Import htcore here to support model quantization
import habana_frameworks.torch.core as htcore # noqa: F401

# Instantiate a Stable Diffusion pipeline class
if sdxl:
# SDXL pipelines
Expand Down
13 changes: 11 additions & 2 deletions optimum/habana/diffusers/pipelines/pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ def __init__(
"`torch_dtype=torch.bfloat16` was given. Disabling mixed precision and continuing in bf16 only."
)
self.gaudi_config.use_torch_autocast = False
else:
self.gaudi_config.declare_autocast_bf16_fp32_ops()

dsocek marked this conversation as resolved.
Show resolved Hide resolved
# Workaround for Synapse 1.11 for full bf16 and Torch Autocast
if bf16_full_eval or self.gaudi_config.use_torch_autocast:
Expand Down Expand Up @@ -370,6 +368,17 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
bf16_full_eval = kwargs.get("torch_dtype", None) == torch.bfloat16
kwargs["bf16_full_eval"] = bf16_full_eval

# Need to load custom ops lists before instantiating htcore
if kwargs.get("gaudi_config", None) is not None:
if isinstance(kwargs["gaudi_config"], str):
gaudi_config = GaudiConfig.from_pretrained(kwargs["gaudi_config"])
else:
gaudi_config = kwargs["gaudi_config"]
gaudi_config.declare_autocast_bf16_fp32_ops()
kwargs["gaudi_config"] = gaudi_config

# Import htcore here to support model quantization
import habana_frameworks.torch.core as htcore # noqa: F401
return super().from_pretrained(
pretrained_model_name_or_path,
**kwargs,
Expand Down