Skip to content

Fix Hub download filtering for FlashPack pipelines#14166

Open
rumutaydin wants to merge 2 commits into
huggingface:mainfrom
rumutaydin:fix-flashpack-download-filtering
Open

Fix Hub download filtering for FlashPack pipelines#14166
rumutaydin wants to merge 2 commits into
huggingface:mainfrom
rumutaydin:fix-flashpack-download-filtering

Conversation

@rumutaydin

Copy link
Copy Markdown

What does this PR do?

Pipelines saved with save_pretrained(use_flashpack=True) currently cannot be loaded
back through the Hub. Such a pipeline stores diffusers models as model.flashpack and
transformers components (text encoders) as safetensors but the download path breaks
on this layout three ways:

  1. _get_ignore_patterns takes the elif use_flashpack: branch and ignores all
    *.safetensors. Since use_flashpack is only forwarded to diffusers models, text
    encoders can only load safetensors which are now missing from the snapshot:

    from diffusers import AutoPipelineForText2Image
    
    pipe = AutoPipelineForText2Image.from_pretrained("hf-internal-testing/tiny-flux-pipe")
    pipe.save_pretrained("flashpack-repo", use_flashpack=True)   # + push to Hub
    AutoPipelineForText2Image.from_pretrained("<user>/flashpack-repo", use_flashpack=True)
    # OSError: Error no file named model.safetensors, or pytorch_model.bin,
    #          found in directory .../text_encoder

    With explicit use_safetensors=True it raises EnvironmentError instead, because
    the flashpack-only folders make is_safetensors_compatible fail.

  2. FlashPack files are missing from variant_compatible_siblings' weight names, so
    they never enter the download allow-patterns combined with (1), a FlashPack
    pipeline snapshot contains no weights at all.

  3. use_flashpack=False: the download docstring says FlashPack weights "will never
    be downloaded", but *.flashpack appears in no ignore pattern, so default users of
    dual-format repos download FlashPack blobs they never read.

Fixes (issue)

judge safetensors compatibility over non-flashpack folders only, keep just the
flashpack file inside flashpack-covered folders (per-folder ignore patterns), register
FLASHPACK_WEIGHTS_NAME as a weight name, ignore *.flashpack whenever
use_flashpack=False, and forward use_flashpack from from_pretrained to download
(it was popped but never passed on, so the flag had no effect on Hub downloads).

Repos with no FlashPack files behave exactly as before, with or without the flag.

Tests

an end-to-end regression test that saves a FlashPack pipeline, applies the real
allow/ignore download filter, and round-trips the filtered snapshot (fails on main),
plus direct _get_ignore_patterns cases for the mixed/dual/flashpack-only/no-flashpack
layouts and a test that from_pretrained forwards the flag.

Related:

#12564, #12700.

Before submitting

  • [x ] Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
  • [ x] Did you read the contributor guideline?
  • [x ] Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • [x ] Did you write any new necessary tests?
  • Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?

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