-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Fix BaseOutput initialization from dict #570
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
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
|
Now I see the need for this code 😅 . We need to adapt it though for But essentially, the code as is on this branch will currently break the following: from diffusers import DDIMPipeline
pipeline = DDIMPipeline.from_pretrained("google/ddpm-cifar10-32")
outputs = pipeline()
outputs["images"]@anton-l could you see how this can be fixed and then maybe also add a test here :-) |
| # check every way of getting the attribute | ||
| assert isinstance(outputs.images, np.ndarray) | ||
| assert outputs.images.shape == (1, 3, 4, 4) | ||
| assert isinstance(outputs["images"], np.ndarray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transformers version (initial commit from this PR) was failing on this line
cc @patrickvonplaten
| outputs = CustomOutput({"images": np.random.rand(1, 3, 4, 4)}) | ||
|
|
||
| # check every way of getting the attribute | ||
| assert isinstance(outputs.images, np.ndarray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the pre-PR diffusers version was failing on this line
|
@patrickvonplaten I've implemented a simpler version that works for your case as well. |
|
|
||
|
|
||
| class ConfigTester(unittest.TestCase): | ||
| def test_outputs_single_attribute(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
| outputs = CustomOutput(images=[PIL.Image.new("RGB", (4, 4))]) | ||
|
|
||
| # check every way of getting the attribute | ||
| assert isinstance(outputs.images, list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool that this is all tested now!
patrickvonplaten
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks a lot for fixing it!
* Fix BaseOutput initialization from dict * style * Simplify post-init, add tests * remove debug
This will allow
accelerateto reinitialize model outputs like so:output = UNet2DOutput({"sample": torch.randn(3, 4)})and avoid nesting attributes.Closes #560