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 the bug of output_type=np or latent. #996

Merged
merged 2 commits into from
May 28, 2024
Merged

Conversation

yuanwu2017
Copy link
Contributor

What does this PR do?

Fixes # (issue)

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?

@yuanwu2017 yuanwu2017 requested a review from regisss as a code owner May 21, 2024 00:54
@libinta libinta added run-test Run CI for PRs from external contributors synapse1.16 labels May 23, 2024
@regisss
Copy link
Collaborator

regisss commented May 24, 2024

@yuanwu2017 Please provide a command or a script to reproduce the bug

@yuanwu2017
Copy link
Contributor Author

yuanwu2017 commented May 27, 2024

@regisss
Please use the test script
Cuda:
python diffusers_test_output_type.py --device cuda
output log:

100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:05<00:00,  1.75s/it]
if output_type is np, the output image should be = <class 'numpy.ndarray'>
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00,  4.93it/s]
if output_type is latent, the output image should be = <class 'torch.Tensor'>
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00,  5.22it/s]
if output_type is pil, the output image should be = <class 'list'>
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00,  5.12it/s]
if output_type is pt, the output image should be = <class 'torch.Tensor'>

HPU
python diffusers_test_output_type.py --device hpu
output log:

[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:24:03,698 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:24:03,698 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:53<00:00, 26.68s/it]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:24:57,073 >> Speed metrics: {'generation_runtime': 53.3576, 'generation_samples_per_second': 0.037, 'generation_steps_per_second': 0.037}
if output_type is np, the output image should be = <class 'list'>
[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:24:57,154 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:24:57,154 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00,  7.38it/s]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:24:57,446 >> Speed metrics: {'generation_runtime': 0.2714, 'generation_samples_per_second': 7.37, 'generation_steps_per_second': 7.37}
if output_type is latent, the output image should be = <class 'list'>
[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:24:57,448 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:24:57,448 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00,  7.08it/s]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:24:57,744 >> Speed metrics: {'generation_runtime': 0.2827, 'generation_samples_per_second': 7.074, 'generation_steps_per_second': 7.074}
if output_type is pil, the output image should be = <class 'list'>
[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:24:57,797 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:24:57,797 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00,  7.19it/s]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:24:58,090 >> Speed metrics: {'generation_runtime': 0.2786, 'generation_samples_per_second': 7.178, 'generation_steps_per_second': 7.178}
if output_type is pt, the output image should be = <class 'list'>

You can see that our image type always is list, but it is list for pil, tensor for pt and latent, numpy.ndarray for np, when running with Cuda device. It will make some pytest failed. For example,
diffusers testcase
The following error will happen.
AttributeError: 'list' object has no attribute 'shape'

HPU After applying the patch.
Output log:

[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:38:06,543 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:38:06,544 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:55<00:00, 27.60s/it]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:39:01,765 >> Speed metrics: {'generation_runtime': 55.1951, 'generation_samples_per_second': 0.036, 'generation_steps_per_second': 0.036}
if output_type is np, the output image should be = <class 'numpy.ndarray'>
[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:39:01,902 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:39:01,902 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00,  6.00it/s]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:39:02,255 >> Speed metrics: {'generation_runtime': 0.3339, 'generation_samples_per_second': 5.99, 'generation_steps_per_second': 5.99}
if output_type is latent, the output image should be = <class 'torch.Tensor'>
[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:39:02,256 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:39:02,256 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:12<00:00,  6.34s/it]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:39:14,958 >> Speed metrics: {'generation_runtime': 12.6856, 'generation_samples_per_second': 0.158, 'generation_steps_per_second': 0.158}
if output_type is pil, the output image should be = <class 'list'>
[INFO|pipeline_stable_diffusion.py:410] 2024-05-27 02:39:14,999 >> 1 prompt(s) received, 2 generation(s) per prompt, 1 sample(s) per batch, 2 total batch(es).
[WARNING|pipeline_stable_diffusion.py:415] 2024-05-27 02:39:14,999 >> The first two iterations are slower so it is recommended to feed more batches.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00,  6.09it/s]
[INFO|pipeline_stable_diffusion.py:591] 2024-05-27 02:39:15,342 >> Speed metrics: {'generation_runtime': 0.3287, 'generation_samples_per_second': 6.085, 'generation_steps_per_second': 6.085}
if output_type is pt, the output image should be = <class 'torch.Tensor'>

@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.

Copy link
Collaborator

@regisss regisss left a comment

Choose a reason for hiding this comment

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

LGTM!
Can you also run

pip install -U ruff
make style

please?

@yuanwu2017
Copy link
Contributor Author

LGTM! Can you also run

pip install -U ruff
make style

please?

Done.

@regisss regisss added run-test Run CI for PRs from external contributors and removed run-test Run CI for PRs from external contributors labels May 28, 2024
@regisss regisss merged commit 8863f1c into huggingface:main May 28, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-test Run CI for PRs from external contributors synapse1.16
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants