-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat(examples): Support S3 for all StableDiffusionPipeline
components
#76
feat(examples): Support S3 for all StableDiffusionPipeline
components
#76
Conversation
Previously, setting include_non_persistent_buffers=False would only include persistent buffers, and remove both non-persistent buffers and parameters. Parameters were not supposed to be affected by this flag, so this fix changes it to only remove non-persistent buffers.
fix(serialization): Don't drop parameters with non-persistent buffers
This additionally adds parameter weight validation for diffusers models, refactors `serialize_model` substantially, adds logging level command line arguments, and shifts more outputs to use a logger.
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.
Dramatically improved! LGTM. One or two questions on your thought process
serialize_pretrained( | ||
pipeline.tokenizer, output_prefix, "tokenizer", force=args.force | ||
) | ||
serialize_pretrained( | ||
pipeline.scheduler, output_prefix, "scheduler", force=args.force | ||
) |
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.
So the purpose of serialize_pretrained
is specifically to support saving artifacts like SD's scheduler
and tokenizer
? I assume this is cleaner as they're not configs nor modules.
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.
Yes, pretty much. The scheduler can actually be saved as a single JSON file (around 300 to 400 bytes), so it could have its own special code to avoid a zip file and temporary directory, but it seemed unnecessary at this time.
In summary:
text_encoder
/vae
/unet
— tensors &config.json
- We use
tensorizer
to save these - Potentially very, very large, so the optimizations in
tensorizer
are important
- We use
scheduler
—config.json
only- Supports
.save_pretrained(dir)
and.from_pretrained(dir)
- Roughly around 400 bytes, so downloader optimizations aren't a huge deal
- Supports
tokenizer
— entire directory of files- Supports
.save_pretrained(dir)
and.from_pretrained(dir)
- Roughly around 1.5 MB for SD 1.5, and compresses well, so zips work nicely
- For models that use "fast tokenizers," these can be saved as a single
tokenizer.json
file instead, but not all models support fast tokenizers
- Supports
184d7a6
into
sangstar/update-serialization-cl-script-for-container
Updated
diffusers
support inhf_serialization.py
More fixes and improvements for #73.
This change:
StableDiffusionPipeline
componentstext_encoder
,vae
(updated),unet
(updated),scheduler
(new),tokenizer
(new)scheduler
andtokenizer
are saved as.zip
files containing the directory written by their.save_pretrained()
methodstransformers
tokenizersinclude_non_persistent_buffers=False
main
to support usinginclude_non_persistent_buffers=False
correctlydiffusers
modelsserialize_model
substantially(Outdated): I left in the code to generate a test image through
diffusers
because it is good example code for this repository of how to re-assemble the components of an SD model and was good for testing that these changes work. It could be commented out or deleted later, or changed to be only enabled through a flag.(Update): The test image generation code for diffusers is now commented out.