Conversation
bigcat88
left a comment
There was a problem hiding this comment.
From quick look:
- Can we use
SUPPORTED_PT_EXTENSIONSvariable? - If two subdirectories have files with the same name (e.g., vae/config.json and text_encoders/config.json), only one will be in the dict. When deleting by name, the wrong file could be deleted.
- Minor thing:
rglob()finds files at arbitrary depth, not just immediate children. This might find models in nested subdirs liketext_encoders/subfolder/model.safetensors/
I will make the change. I did not notice the variable. Thanks.
Thanks for the catch. Let me make sure that does not happen (and if that case happens, to offer them an option to pick which one to delete, or qualify the folder)
Good point. Given the risk of finding things not desired (and the reason I started this was to find the usual first-level children of models, where most things go), maybe a different (better?) approach would be to use a |
|
I updated the delete to take into consideration multiple matching names: If picking from the menu: Or specifying in the command line: In case of multiple matches, you can specify which one more specifically: |
|
Implemented Default: Restricting further: |
Hi @bigcat88, I updated the code to address your feedback. PTAL at your convenience. Examples of the code in action as comments above. |
bigcat88
left a comment
There was a problem hiding this comment.
Having some tests for this will be good. At minimum we should test:
- Flat files in root
- Files in subdirectories
- max_depth behavior
- Filtering by SUPPORTED_PT_EXTENSIONS
| """List all models in the specified directory and its subdirectories. | ||
|
|
||
| Returns a list of tuples (model_type, file_path) where model_type is the | ||
| subdirectory name with '_models' suffix stripped if present. |
There was a problem hiding this comment.
Can you explain where the strip of "models" prefix occurs?
| if not path.exists(): | ||
| return models | ||
| if max_depth == 0: | ||
| print("max_depth must be 1 or greather") |
There was a problem hiding this comment.
This just prints a message and returns empty, causing the caller to show "No models found" - which is a little bit misleading.
This should be a typer.BadParameter or a min=1 constraint on the typer Option.
| - Model remove | ||
|
|
||
| `comfy model remove ?[--relative-path <PATH>] --model-names <model names>` | ||
| `comfy model remove ?[--relative-path <PATH>] ?[--max-depth <LEVELS] --model-names <model names>` |
|
|
||
| # Print a list of models to delete: | ||
| if to_delete: | ||
| print("These models will be deleted:") |
There was a problem hiding this comment.
Can we use typer.echo instead of print ?
|
|
||
| # Build a mapping from display name to path for selection | ||
| sorted_models = sorted(available_models, key=lambda x: x[1].name) | ||
| #model_path_by_name = {model.name: model for _model_type, model in available_models} |
There was a problem hiding this comment.
please, remove the line with commented code
| # Scenario #2: User did not provide model names, prompt for selection | ||
| else: | ||
| selections = ui.prompt_multi_select("Select models to delete:", [model.name for model in available_models]) | ||
| selections = ui.prompt_multi_select("Select models to delete:", list(model_path_by_name.keys())) |
There was a problem hiding this comment.
Did you try this code when model1.safetensors file exists in two different sub-directories?
Does the interactive usage displays correct prompt which one will be deleted?
Implements a fix for issue #361 and also looks for
models/subdirectories. Example output:It also honors the folders when removing modules.