ComfyUI/comfy
codeflash-ai[bot] 72233ef320
️ Speed up function state_dict_prefix_replace by 127%
Here's an optimized version of your Python function. The primary changes are to minimize the creation of intermediate lists and to use dictionary comprehensions for more efficient data manipulation.



### Changes and Optimizations

1. **Avoid Unneeded List Creation:** 
   - Instead of mapping and filtering the keys in a separate step (`map` and `filter`), it is done directly in the list comprehension.
   
2. **Dictionary Comprehension**: 
   - By directly assigning `out` to `{}` or `state_dict`, it forgoes unnecessary intermediate steps in the conditional initialization.
   
3. **In-Loop Item Assignment**.
   - Keys to be replaced and corresponding operations are now handled directly within loops, reducing intermediate variable assignments.

This rewritten function should perform better, especially with large dictionaries, due to reduced overhead from list operations and more efficient key manipulation.
2025-04-16 10:21:07 +00:00
..
cldm Replace print with logging (#6138) 2024-12-20 16:24:55 -05:00
comfy_types Deprecate InputTypeOptions.defaultInput (#7551) 2025-04-10 06:57:06 -04:00
extra_samplers Uni pc sampler now works with audio and video models. 2025-01-18 05:27:58 -05:00
image_encoders Add support for giant dinov2 image encoder. 2025-03-17 05:53:54 -04:00
k_diffusion Add SEEDS (stage 2 & 3 DP) sampler (#7580) 2025-04-12 18:36:08 -04:00
ldm add RMSNorm to comfy.ops 2025-04-14 18:00:33 -04:00
sd1_tokenizer
t2i_adapter
taesd
text_encoders Add an image_interleave option to the Hunyuan image to video encode node. 2025-03-07 19:56:26 -05:00
checkpoint_pickle.py
cli_args.py Add CublasOps support (#7574) 2025-04-12 18:29:15 -04:00
clip_config_bigg.json
clip_model.py Support llava clip vision model. 2025-03-06 00:24:43 -05:00
clip_vision_config_g.json
clip_vision_config_h.json
clip_vision_config_vitl_336_llava.json Support llava clip vision model. 2025-03-06 00:24:43 -05:00
clip_vision_config_vitl_336.json
clip_vision_config_vitl.json
clip_vision_siglip_384.json
clip_vision_siglip_512.json Support 512 siglip model. 2025-04-05 07:01:01 -04:00
clip_vision.py Support 512 siglip model. 2025-04-05 07:01:01 -04:00
conds.py Remove unused function lcm in conds.py (#6572) 2025-01-23 05:54:09 -05:00
controlnet.py Use fp16 if checkpoint weights are fp16 and the model supports it. 2025-02-27 16:39:57 -05:00
diffusers_convert.py Remove useless code. 2025-01-24 06:15:54 -05:00
diffusers_load.py
float.py
gligen.py Lint and fix undefined names (1/N) (#6028) 2024-12-12 18:55:26 -05:00
hooks.py Hooks Part 2 - TransformerOptionsHook and AdditionalModelsHook (#6377) 2025-01-11 12:20:23 -05:00
latent_formats.py Initial Hunyuan3Dv2 implementation. 2025-03-19 16:52:58 -04:00
lora_convert.py Support the wan fun reward loras. 2025-04-07 05:01:47 -04:00
lora.py Only use stable cascade lora format with cascade model. 2025-02-01 06:35:22 -05:00
model_base.py Remove useless code. 2025-03-29 20:12:56 -04:00
model_detection.py Native LotusD Implementation (#7125) 2025-03-21 14:04:15 -04:00
model_management.py MLU memory optimization (#7470) 2025-04-02 19:24:04 -04:00
model_patcher.py Call unpatch_hooks at the start of ModelPatcher.partially_unload (#7253) 2025-03-16 06:02:45 -04:00
model_sampling.py Automatically set the right sampling type for lotus. 2025-03-21 14:19:37 -04:00
ops.py add RMSNorm to comfy.ops 2025-04-14 18:00:33 -04:00
options.py
patcher_extension.py Add prepare_sampling wrapper allowing custom nodes to more accurately report noise_shape (#7500) 2025-04-09 09:43:35 -04:00
rmsnorm.py add RMSNorm to comfy.ops 2025-04-14 18:00:33 -04:00
sample.py Auto reshape 2d to 3d latent for single image generation on video model. 2024-12-29 02:26:49 -05:00
sampler_helpers.py Add prepare_sampling wrapper allowing custom nodes to more accurately report noise_shape (#7500) 2025-04-09 09:43:35 -04:00
samplers.py Add SEEDS (stage 2 & 3 DP) sampler (#7580) 2025-04-12 18:36:08 -04:00
sd1_clip_config.json
sd1_clip.py Fix some things breaking when embeddings fail to apply. 2025-03-06 13:31:55 -05:00
sd.py Disable partial offloading of audio VAE. 2025-04-04 21:24:56 -04:00
sdxl_clip.py Make it easier to set a custom template for hunyuan video. 2025-03-04 09:26:05 -05:00
supported_models_base.py
supported_models.py Support the WAN 2.1 fun control models. 2025-03-26 19:54:54 -04:00
utils.py ️ Speed up function state_dict_prefix_replace by 127% 2025-04-16 10:21:07 +00:00