Skip to content

feat(model_manager): Add scan and delete of orphaned models#8826

Open
lstein wants to merge 5 commits intoinvoke-ai:mainfrom
lstein:lstein/utility/remove-orphaned-models
Open

feat(model_manager): Add scan and delete of orphaned models#8826
lstein wants to merge 5 commits intoinvoke-ai:mainfrom
lstein:lstein/utility/remove-orphaned-models

Conversation

@lstein
Copy link
Collaborator

@lstein lstein commented Feb 1, 2026

Summary

This PR addresses the situation in which there are "orphaned" models in the INVOKEAI_ROOT/models directory that are not registered in the database. The PR offers two ways of dealing with them:

  1. A command line tool named scripts/remove_orphaned_models.py that lists the orphans and prompts the user to delete the orphan model directories.
  2. A new "Sync Models" button in the frontend's Model Manager tab that does the same thing interactively.

This functionality complements the recently-added PR #8801 , which implemented a filter to show models in the database that are missing or incomplete, and offers to remove them from the database.

Related Issues / Discussions

None

QA Instructions

Because this functionality has the potential to delete models on disk, you might want to set up a testing invoke root.

Testing the command-line script:

Note that this is intended to be a developer-facing utility and is not particularly polished.

  1. Run python3 scripts/remove_orphaned_models.py --root /path/to/INVOKEAI_ROOT
  2. Verify that it shows zero orphaned models (assuming you have a clean root)
  3. Add some dummy models to INVOKEAI_ROOT:
    cd INVOKEAI_ROOT/models
    mkdir -p orphan1 orphan2/encoder orphan3
    touch orphan1/test.safetensors orphan2/encoder/test.bin orphan3/pytorch.safetensors
  4. Run the script again. Now it should report the 3 orphaned models and ask if you wish to remove them.
  5. Type 'Y' to delete and verify that the directories are gone.

Testing the UI:

  1. Add some dummy models to INVOKEAI_ROOT as described in the previous section.
  2. Navigate to the Model Manager; note a new button at the top labeled "Sync Models"
  3. Verify that the tooltip is sufficiently informative for a typical user.
  4. Press the button and verify that it open a dialogue that correctly lists the orphan models.
  5. Toggle open the model names and verify that each shows at least one model file
  6. Press the "Delete" button and verify that the model directories are gone.
  7. Run "Sync Models" again and verify that it reports no orphans found.

Merge Plan

Simple merge.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • X] Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • [] Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Copilot AI and others added 4 commits February 1, 2026 15:45
- This commit adds command-line and Web GUI functionality for
  identifying and optionally removing models in the models directory
  that are not referenced in the database.

Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>

Add expandable file list to orphaned models dialog

Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
@github-actions github-actions bot added api python PRs that change python files Root services PRs that change app services frontend PRs that change frontend files labels Feb 1, 2026
@github-actions github-actions bot added the docs PRs that change docs label Feb 1, 2026
@lstein lstein added the v6.12.0 Intended for 6.12.0 release label Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api docs PRs that change docs frontend PRs that change frontend files python PRs that change python files Root services PRs that change app services v6.12.0 Intended for 6.12.0 release

Projects

Status: 6.12.x

Development

Successfully merging this pull request may close these issues.

3 participants