Skip to content

Clarify reuse and deletion of image-model companion assets #8116

Closed

Description

@Imagineer99

Image GGUFs can require a small checkpoint plus much larger companion assets. For example, FLUX.2 Klein 4B Q4_K_M uses an approximately 2.6 GB GGUF and 8.2 GB of text-encoder, VAE, tokenizer, and configuration files.

The companion assets can be shared by multiple quants, but their lifecycle is unclear. Deleting a model through the picker may leave the larger companion cache behind without explaining it or offering a cleanup path. Automatically deleting it could instead break another installed quant.

We should decide whether Studio retains or removes unused companion assets and make that behavior visible to users.

Expected behavior

  • Compatible quants reuse one cached copy of companion assets.
  • Deletion shows how much space will actually be reclaimed and what will remain.
  • Shared assets are not removed while another installed model needs them.
  • Users can remove orphaned companion assets without manually editing the Hugging Face cache.

Related download and model-footprint UX: #8036.

Activity

  1. added
    feature request
    on Aug 7, 2026
  2. self-assigned this
    on Aug 9, 2026
  3. danielhanchen commented on Aug 9, 2026

    @danielhanchen
    Member

    Reproduced this properly before touching anything, with your exact example. Built a scratch cache holding unsloth/FLUX.2-klein-4B-GGUF at Q2_K and Q4_K_M plus the companion base, and your numbers are right on the nose:

    8,229,026,136  models--black-forest-labs--FLUX.2-klein-4B     text encoder, VAE, tokenizer, configs
    4,432,118,952  models--unsloth--FLUX.2-klein-4B-GGUF          Q2_K 1.8 GB + Q4_K_M 2.6 GB
    

    8.23 GB of companions against 2.6 GB of Q4_K_M. Three of your four expectations were genuinely unmet. One was already satisfied, so I want to correct that part rather than build something for it.

    Reuse already works, and I scoped that part out

    Both quants resolve their base through the same detect_family_for_pick plus resolve_base_repo pair, so they land on one cached copy, not two. The ungated mirror indirection does not split it either: the load path takes a single prefer_ungated_mirror decision with the staged file list in hand and carries it through, so the plan and the load cannot stage one repo and assemble from the other.

    There is one latent inconsistency I found while checking. A fallback in load_pipeline re-decides the mirror without the file list, and against a partially cached upstream the two answers differ:

    prefer_ungated_mirror(base, files=[...])  ->  unsloth/FLUX.1-dev
    prefer_ungated_mirror(base)               ->  black-forest-labs/FLUX.1-dev
    

    That branch is only reachable from a direct call, not from the product, so it is not a duplicate anyone has on disk today. I have left it alone rather than churn the load path, but the new guards treat the two ids as one repo so a cache that ends up holding both still behaves.

    The other three were real, and the third one was worse than "unclear"

    Delete is scoped to a single repo id in a single cache root and never looked at companions, and the response carried no size at all, so the dialog could only say "You can re-download it later". Deleting the last quant left 8.2 GB behind, 65% of the footprint, invisible.

    The part that concerned me most was your third point. There was no notion anywhere of one repo needing another, so with both quants installed this simply worked:

    DELETE OF SHARED BASE -> {'status': 'deleted', 'repo_id': 'black-forest-labs/FLUX.2-klein-4B'}
    after: 4,432,118,952  models--unsloth--FLUX.2-klein-4B-GGUF     both quants now unloadable
    

    Two clicks from the picker, no warning, and the models look fine in the list afterwards.

    What I shipped

    The important design call is that nothing is counted. A refcount that drifts is worse than none, so "what still needs this base" is derived at delete time from what is installed, using the same resolvers the loader uses to choose a base. If family detection fails for a cached repo then the loader cannot load it either, so there is no dependant to protect: the derivation and the thing it protects fail together.

    The one thing an offline scan cannot reconstruct is a card base_model tag, since a GGUF pick caches only the .gguf and never the card. That is recorded as a link at the moment the resolver makes the choice. A link, not a count: it can only ever add a dependant, it is filtered by whether that checkpoint is still installed, and losing it degrades to the family default rather than to a wrong answer.

    Then, against your four points:

    1. Reuse: already correct, verified, unchanged.
    2. The dialog now separates the two numbers. "Frees 1.8 GB of disk space. 8.2 GB of shared assets stay on disk: black-forest-labs/FLUX.2-klein-4B is still needed by unsloth/FLUX.2-klein-4B-GGUF." On the last quant it says the 8.2 GB becomes removable and where to remove it. Sizes are real on-disk blob bytes from the cache scan, not Hub metadata.
    3. Deleting a shared base while a quant needs it now returns 400 and the Delete button is disabled: "These are shared assets that unsloth/FLUX.2-klein-4B-GGUF still needs, so they cannot be removed yet. Delete those models first." The check fails closed if the cache cannot be read, because being unable to enumerate dependants is not the same as having none.
    4. A Free up space button on the On Device tab lists companion assets nothing needs, with sizes, each row opt-in. Nothing automatic. Deleting user data stays a deliberate act, and removal goes through the same guarded delete, so the cleanup path cannot bypass point 3.

    One subtlety worth stating: several of these bases run perfectly well on their own, so the cleanup has to tell "the user installed this" from "a GGUF pulled this in". A companion fetch takes everything except the denoiser folder and a pipeline pick takes it, so the denoiser's presence answers that without guessing.

    Verified end to end in a browser on that real cache, 12,661,145,088 bytes down to 40, with the dangerous delete refused in the middle. The adversarial test fails on main, which is the point of it, and a mutation run breaks each guarantee in turn to confirm the assertions are load bearing: 15 mutations, 15 killed.

    Scope stayed image-only. No video delete behaviour changes, and the chat GGUF path has no separate companion repo, since mmproj and drafters live in the same repo and are already reclaimed with the last variant.

    PR: #8223. Good catch, and thanks for framing it as a lifecycle question rather than a bug report, that is what made the shared-delete hole obvious once I went looking.

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

Metadata

Metadata

Assignees

Labels

Studiofeature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions