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 infer task for stable diffusion #1793

Merged

Conversation

JingyaHuang
Copy link
Collaborator

@JingyaHuang JingyaHuang commented Apr 3, 2024

What does this PR do?

The current task inference is not working for stable diffusion checkpoints, eg. runwayml/stable-diffusion-v1-5

p.s. I did not see checkpoints using class_name instead of _class_name, if there is not we shall remove it (keep it for now).

from optimum.exporters import TasksManager

task = TasksManager.infer_task_from_model("runwayml/stable-diffusion-v1-5")

# KeyError: 'class_name'

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@JingyaHuang JingyaHuang changed the title Fix infer task fo stable diffusion Fix infer task for stable diffusion Apr 3, 2024
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment on lines 1563 to 1565
class_name = model_info.config["diffusers"].get("class_name", None) or model_info.config[
"diffusers"
].get("_class_name", None)
Copy link
Collaborator

@fxmarty fxmarty Apr 3, 2024

Choose a reason for hiding this comment

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

Suggested change
class_name = model_info.config["diffusers"].get("class_name", None) or model_info.config[
"diffusers"
].get("_class_name", None)
if hasattr(model_info.config["diffusers"], "class_name"):
class_name = model_info.config["diffusers"]["class_name"]
elif hasattr(model_info.config["diffusers"], "_class_name"):
class_name = model_info.config["diffusers"]["_class_name"]
else:
raise ValueError(f"Could not automatically infer the class name for {model_name_or_path}. Please open an issue at https://github.com/huggingface/optimum/issues.")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@fxmarty model_info.config["diffusers"] is a dictionary and class_name or _class_name are keys instead of attributes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

feel free to edit accordingly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Copy link
Collaborator

Choose a reason for hiding this comment

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

@JingyaHuang Is the suggestion fine as is in the end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's good.

@JingyaHuang JingyaHuang requested a review from fxmarty April 3, 2024 14:01
Copy link
Collaborator

@fxmarty fxmarty left a comment

Choose a reason for hiding this comment

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

Thank you

@JingyaHuang JingyaHuang merged commit 5584eb8 into huggingface:main Apr 5, 2024
55 of 61 checks passed
JingyaHuang added a commit that referenced this pull request Apr 9, 2024
young-developer pushed a commit to young-developer/optimum that referenced this pull request May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants