Skip to content

Conversation

@patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Oct 10, 2022

This PR adds from_config and from_pretrained dummy class methods to all dummy classes.

Running:

pytest -sv tests/test_pipelines.py::PipelineFastTests::test_stable_diffusion_k_lms

without scipy installed now yields:

E           ImportError: 
E           LMSDiscreteScheduler requires the scipy library but it was not found in your environment. You can install it with pip: `pip install
E           scipy`

as expected. Thanks for flagging @pcuenca

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 10, 2022

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten patrickvonplaten linked an issue Oct 10, 2022 that may be closed by this pull request
requires_backends(self, {1})
@classmethod
def from_config(cls, *args, **kwargs):
Copy link
Contributor Author

@patrickvonplaten patrickvonplaten Oct 10, 2022

Choose a reason for hiding this comment

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

Adding from_config and from_pretrained is quite simple here

@pcuenca
Copy link
Member

pcuenca commented Oct 10, 2022

Very cool!

Loading the scheduler shows the nice error, but loading the pretrained pipeline still gives the cryptic message to me:

        pipe = StableDiffusionPipeline.from_pretrained("hakurei/waifu-diffusion")

Fails with a cryptic message if scipy is not installed.
@pcuenca
Copy link
Member

pcuenca commented Oct 11, 2022

@patrickvonplaten I created a test to load a pipeline that uses the LMS Discrete scheduler. It currently fails with a cryptic error message if scipy is not installed. I'll try to debug it later.

@pcuenca
Copy link
Member

pcuenca commented Oct 11, 2022

If dummy_torch_and_scipy_objects.LMSDiscreteScheduler inherited from SchedulerMixin then it would be a load candidate and the nice error message would be presented. But I'm not sure how to achieve that with the current system.

Another option is to detect None here and show an error with the class name that we are attempting and failing to load.

What do you think?

@patrickvonplaten
Copy link
Contributor Author

@patrickvonplaten I created a test to load a pipeline that uses the LMS Discrete scheduler. It currently fails with a cryptic error message if scipy is not installed. I'll try to debug it later.

Thanks, checking it out now!

assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2

def test_from_pretrained_error_message_uninstalled_packages(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pcuenca - I can't think of a good way to test that we have a nice error message going forward. Suggest to just merge without a good test for now. Let me know if you have other ideas!

Copy link
Member

Choose a reason for hiding this comment

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

The test is not as important as the real use in the wild, like what happened with that Space that broke. If users see something reasonable instead of the previous cryptic message, then I'm all for it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think the test as it's now doesn't really help at all 😅 I was just wondering if there is a way to "pretend" scipy is not installed and then verify that the error message is nice

@patrickvonplaten patrickvonplaten merged commit db47b1e into main Oct 12, 2022
@patrickvonplaten patrickvonplaten deleted the better_error_message branch October 12, 2022 12:41
prathikr pushed a commit to prathikr/diffusers that referenced this pull request Oct 26, 2022
* [Dummy imports] Better error message

* Test: load pipeline with LMS scheduler.

Fails with a cryptic message if scipy is not installed.

* Correct

Co-authored-by: Pedro Cuenca <[email protected]>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* [Dummy imports] Better error message

* Test: load pipeline with LMS scheduler.

Fails with a cryptic message if scipy is not installed.

* Correct

Co-authored-by: Pedro Cuenca <[email protected]>
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.

Better error message for unsupported classes

4 participants