huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
25.14k stars 5.2k forks source link

Storage-Efficient Bulk Conversion of Single-File Model Layout to Diffusers-Multifolder #9260

Open wbclark opened 3 weeks ago

wbclark commented 3 weeks ago

Is your feature request related to a problem? Please describe. A major drawback of using single-file models is their inefficient use of disk storage, as a user who has downloaded several models in the single-file format is likely storing many redundant copies of individual model components that were re-used across models.

It's common for models to merge or fine-tune only the UNet, for example, leading to a situation where the user is potentially storing many redundant copies of identical VAEs and text encoders, eating up a non-trivial amount of their disk space.

However, currently even when converting single-file models to the diffusers-multifolder format using the scripts provided in this repository, each model’s components (e.g., UNet, VAE, text encoder) are stored separately, leading still to redundant storage if multiple models share identical components.

Describe the solution you'd like. I propose a feature that facilitates the conversion of downloaded single-file models to the diffusers-multifolder layout in a storage-efficient manner. The core idea is to identify and eliminate duplicate model components across multiple models by:

  1. Converting models to the diffusers-multifolder format.
  2. Computing cryptographic hashes for the weight files of each model component
  3. Storing each component, named by its hash, in a centralized directory
  4. Linking from each model’s directory to these centralized components instead of storing duplicates OR adding the name/hash/location to the config.json (may be preferable for Windows users since it doesn't require enabling developer mode)

This could be supported by providing additional operations such as:

Describe alternatives you've considered. If I understand correctly (please correct me if I'm wrong), the huggingface_hub caching system currently performs some de-duplication, but:

Additional context.

  1. I'd like to work on implementing this feature, and I'm proposing it here first to ensure it fits within the scope of this project, and to refine the proposal further if necessary.
  2. In my opinion, this feature would drive support for and adoption of the diffusers-multifolder layout across the ecosystem.

Thank you for your consideration and feedback!

wbclark commented 2 weeks ago

Hello, has anybody had an opportunity to look into this feature proposal?