Skip to content

FlashPack support for transformers pipeline components#14167

Open
rumutaydin wants to merge 3 commits into
huggingface:mainfrom
rumutaydin:feat-flashpack-transformers-components
Open

FlashPack support for transformers pipeline components#14167
rumutaydin wants to merge 3 commits into
huggingface:mainfrom
rumutaydin:feat-flashpack-transformers-components

Conversation

@rumutaydin

@rumutaydin rumutaydin commented Jul 10, 2026

Copy link
Copy Markdown

What does this PR do?

Follow-up to #14166 (stacked on it). use_flashpack=True currently applies
only to diffusers models; transformers components (text encoders) silently keep
safetensors, so a "FlashPack pipeline" never actually is one end to end the gap
noted when FlashPack+DDUF support was discussed in
huggingface/huggingface_hub#3716.

  • Save: transformers' save_pretrained has no FlashPack support, so
    DiffusionPipeline.save_pretrained(use_flashpack=True) now saves a transformers
    component's config as usual and packs its weights to model.flashpack the same
    call ModelMixin.save_pretrained(use_flashpack=True) makes for diffusers models.
  • Load: when use_flashpack=True and a transformers component's folder ships
    model.flashpack, initialize the model from its config on empty weights and assign
    the packed weights onto it, mirroring the existing diffusers-model FlashPack path
    (same device_map handling and warnings). Folders without a flashpack file load
    exactly as before, so existing mixed-format repos are unaffected.

With this, saving tiny-flux-pipe with use_flashpack=True produces zero safetensors
(CLIP, T5, transformer, VAE all packed), the filtered Hub snapshot round-trips
bitwise-equal, and the reloaded pipeline runs inference on CPU.

One difference from the diffusers-model FlashPack path: loaded transformers
components are returned in eval mode, matching what transformers.from_pretrained
does. (The diffusers-model FlashPack path currently returns models in train mode,
happy to fix that separately if wanted.)

Tests

a new test saves tiny-flux-pipe with use_flashpack=True and asserts the transformers components (CLIP and T5 text encoders) produce model.flashpack and no safetensors, then applies the real Hub download filter to the saved folder and reloads it checking the restored weights are bitwise-equal to the originals and the components are in eval mode. The existing round-trip test now builds the mixed layout explicitly (diffusers models as FlashPack, text encoders as safetensors, i.e. what save_pretrained(use_flashpack=True) produced before this PR), so repos saved with the old behavior are covered and keep loading.

Related: #12564.

Before submitting

Who can review?

@DN6 @yiyixuxu

Pipelines saved with use_flashpack=True could not be loaded through the
Hub download path: _get_ignore_patterns excluded all *.safetensors, so
transformers components (text encoders) had no weights in the snapshot,
and FlashPack files were missing from variant_compatible_siblings'
weight names, so they never entered the allow patterns either. With
use_flashpack=False, *.flashpack files were still downloaded despite
the documented behavior.

Judge safetensors compatibility over non-flashpack folders only, keep
just the flashpack file inside flashpack-covered folders, register
FlashPack files as weight names, and never download flashpack weights
when use_flashpack is disabled.
from_pretrained popped use_flashpack but never passed it to download,
so Hub-mediated loading never fetched FlashPack weights regardless of
the flag.
use_flashpack=True previously applied only to diffusers models;
transformers components (text encoders) silently kept safetensors, so
pipelines were never FlashPack end to end.

On save, pack transformers components' weights to model.flashpack the
same way ModelMixin.save_pretrained(use_flashpack=True) does. On load,
when a transformers component folder ships a flashpack file, initialize
the model from its config on empty weights and assign the packed
weights onto it, mirroring the existing diffusers-model FlashPack path.
Folders without a flashpack file keep loading exactly as before, so
existing mixed-format repos are unaffected.
@github-actions

Copy link
Copy Markdown
Contributor

Hi @rumutaydin, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant