Skip to content

Find modules recursively#362

Open
nelsonjr wants to merge 5 commits intoComfy-Org:mainfrom
nelsonjr:fix-issue-361
Open

Find modules recursively#362
nelsonjr wants to merge 5 commits intoComfy-Org:mainfrom
nelsonjr:fix-issue-361

Conversation

@nelsonjr
Copy link

Implements a fix for issue #361 and also looks for models/ subdirectories. Example output:

┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Type          ┃ Model Name                                                ┃ Size        ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ diffusion     │ Wan2.2_Remix_NSFW_i2v_14b_high_lighting_v2.0.safetensors  │ 13956320 KB │
│ diffusion     │ Wan2.2_Remix_NSFW_i2v_14b_low_lighting_v2.0.safetensors   │ 13956320 KB │
│ diffusion     │ wan2.2_i2v_low_noise_14B_fp8_scaled.safetensors           │ 13959709 KB │
│ diffusion     │ wan2.2_i2v_high_noise_14B_fp8_scaled.safetensors          │ 13959709 KB │
│ loras         │ wan2.2_i2v_lightx2v_4steps_lora_v1_low_noise.safetensors  │ 1198220 KB  │
│ loras         │ wan2.2_i2v_lightx2v_4steps_lora_v1_high_noise.safetensors │ 1198220 KB  │
│ text_encoders │ umt5_xxl_fp8_e4m3fn_scaled.safetensors                    │ 6578034 KB  │
│ vae           │ wan_2.1_vae.safetensors                                   │ 247866 KB   │
└───────────────┴───────────────────────────────────────────────────────────┴─────────────┘

It also honors the folders when removing modules.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jan 27, 2026
Copy link
Contributor

@bigcat88 bigcat88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From quick look:

  1. Can we use SUPPORTED_PT_EXTENSIONS variable?
  2. 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.
  3. Minor thing: rglob() finds files at arbitrary depth, not just immediate children. This might find models in nested subdirs like text_encoders/subfolder/model.safetensors/

@nelsonjr
Copy link
Author

nelsonjr commented Feb 3, 2026

From quick look:

  1. Can we use SUPPORTED_PT_EXTENSIONS variable?

I will make the change. I did not notice the variable. Thanks.

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

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)

  1. Minor thing: rglob() finds files at arbitrary depth, not just immediate children. This might find models in nested subdirs like text_encoders/subfolder/model.safetensors/

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 --max-levels variable to control how deep? (like find). We could default it to --max-depth=2 and user can change to any number.

@nelsonjr
Copy link
Author

nelsonjr commented Feb 3, 2026

I updated the delete to take into consideration multiple matching names:

(venv) root@comfy-playground:~/cli# comfy model list
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Type           ┃ Model Name         ┃ Size     ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ checkpoints    │ model1.safetensors │ 10240 KB │
│ loras          │ model1.safetensors │ 5120 KB  │
│ text_encoders  │ model1.safetensors │ 128 KB   │
│ upscale_models │ upme.pth           │ 2048 KB  │
│ vae            │ model1.safetensors │ 1024 KB  │
└────────────────┴────────────────────┴──────────┘

If picking from the menu:

(venv) root@comfy-playground:~/cli# comfy model remove
? Select models to delete: [model1.safetensors]
These models will be deleted:
  - /root/comfy/ComfyUI/models/checkpoints/model1.safetensors
  - /root/comfy/ComfyUI/models/loras/model1.safetensors
  - /root/comfy/ComfyUI/models/text_encoders/model1.safetensors
  - /root/comfy/ComfyUI/models/vae/model1.safetensors
Are you sure you want to delete the selected files? [y/N]: y
Deleted: /root/comfy/ComfyUI/models/checkpoints/model1.safetensors
Deleted: /root/comfy/ComfyUI/models/loras/model1.safetensors
Deleted: /root/comfy/ComfyUI/models/text_encoders/model1.safetensors
Deleted: /root/comfy/ComfyUI/models/vae/model1.safetensors

Or specifying in the command line:

# comfy model remove --model-names model1.safetensors
These models will be deleted:
  - /root/comfy/ComfyUI/models/checkpoints/model1.safetensors
  - /root/comfy/ComfyUI/models/loras/model1.safetensors
  - /root/comfy/ComfyUI/models/text_encoders/model1.safetensors
  - /root/comfy/ComfyUI/models/vae/model1.safetensors
Are you sure you want to delete the selected files? [y/N]: _

In case of multiple matches, you can specify which one more specifically:

# comfy model remove --model-names loras/model1.safetensors
These models will be deleted:
  - /root/comfy/ComfyUI/models/loras/model1.safetensors
Are you sure you want to delete the selected files? [y/N]: _

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Feb 4, 2026
@nelsonjr
Copy link
Author

nelsonjr commented Feb 4, 2026

Implemented --max-depth to control how deep the scan will go:

Default: --max-depth=2 to cover models/ and models/????/ only:

# comfy model list 
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Type           ┃ Model Name         ┃ Size     ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ checkpoints    │ model1.safetensors │ 10240 KB │
│ loras          │ model1.safetensors │ 5120 KB  │
│ text_encoders  │ model1.safetensors │ 128 KB   │
│ upscale_models │ upme.pth           │ 2048 KB  │
│ vae            │ model1.safetensors │ 1024 KB  │
│ <models>       │ local.safetensors  │ 50 KB    │
└────────────────┴────────────────────┴──────────┘

Restricting further:

# comfy model list --max-depth=1
┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓
┃ Type     ┃ Model Name        ┃ Size  ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━┩
│ <models> │ local.safetensors │ 50 KB │
└──────────┴───────────────────┴───────┘

@nelsonjr
Copy link
Author

nelsonjr commented Feb 4, 2026

From quick look:

  1. Can we use SUPPORTED_PT_EXTENSIONS variable?

I will make the change. I did not notice the variable. Thanks.

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

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)

  1. Minor thing: rglob() finds files at arbitrary depth, not just immediate children. This might find models in nested subdirs like text_encoders/subfolder/model.safetensors/

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 --max-levels variable to control how deep? (like find). We could default it to --max-depth=2 and user can change to any number.

Hi @bigcat88, I updated the code to address your feedback. PTAL at your convenience. Examples of the code in action as comments above.

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

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants