In this repo, when loading lora, is there some code to remove the prefix basemodel.model…
- User
In this repo, when loading lora, is there some code to remove the prefix
base_model.modelfrom the key in the state dict? For example,base_model.model.layers.0.attention.out.lora_A.weightshould becomelayers.0.attention.out.lora_A.weight Assistant
I will search the codebase for the string
base_model.modelto see if there is any logic that handles or removes this prefix during LoRA loading.Assistant
I will examine the context around the matches in
comfy/lora.pyto understand how thebase_model.modelprefix is handled.Assistant
I will search
comfy/utils.pyfor any functions that perform state dict cleaning or prefix removal, as this might be where the logic the user is asking about resides.Assistant
I will check
comfy/weight_adapter.pyto see how it handles LoRA keys and if there is any logic for prefix removal or adaptation.Assistant
I will list the contents of the
comfy/directory to locate theweight_adaptermodule.Assistant
I will check
comfy/weight_adapter/__init__.pyto understand how weight adapters are loaded and if they involve any key prefix handling.Assistant
I will examine
comfy/weight_adapter/lora.pyto see how it handles LoRA weights and if it contains any logic for processing key prefixes likebase_model.model.Assistant
I will search for occurrences of
startswith("base_model.model.")or.replace("base_model.model.", "")to see if there is any logic that strips this prefix from keys.Assistant
I will search
nodes.pyfor theLoraLoaderclass and examine how it handles LoRA loading and if it performs any key prefix cleaning.Assistant
I will read the
LoraLoaderclass innodes.pyto see the logic used for loading LoRAs.Assistant
I will examine
comfy/sd.pyto find theload_lora_for_modelsfunction and see how it handles LoRA loading across different models.Assistant
I will read the
load_lora_for_modelsfunction incomfy/sd.pyto understand the LoRA loading process and any key mapping or prefix handling.Assistant
I will examine
comfy/lora_convert.pyto see if theconvert_lorafunction handles the removal of prefixes likebase_model.modelfrom LoRA state dict keys.Assistant
I will search for "base_model" in the entire project, excluding
lora.pyandmapper_utils.py, to find any other instances where this prefix might be handled.- User
Don't use grep because it's a large repo
Assistant
I searched for
base_model.modeland examined the LoRA loading logic. In ComfyUI, the prefixbase_model.modelis typically handled by mapping the model's internal keys to the expected LoRA keys, rather than stripping the prefix from the LoRA state dict.For example, in
comfy/lora.py, for certain model types (like SD3 or PixArt), the code explicitly adds thebase_model.modelprefix to the search keys:python# From comfy/lora.py (model_lora_keys_unet) if isinstance(model, comfy.model_base.SD3): # ... key_lora = "base_model.model.{}".format(k[:-len(".weight")]) key_map[key_lora] = toWhen
comfy/lora.py'sload_lorafunction runs, it uses these mapped keys to look up weights in the LoRA state dict. If a LoRA key isbase_model.model.layers.0.attention.out.lora_A.weight, thekey_mapentry forbase_model.model.layers.0.attention.outallows theLoRAAdapterto find and load the weight correctly.- User
When I load a lora for the Lumina2 model, the base model does not have
base_model.model.in the keys, but the lora does. How to implement the mapping? Assistant
I will read
comfy/lora.pyto inspect themodel_lora_keys_unetfunction, specifically focusing on theLumina2implementation, to identify where to add the key mapping forbase_model.model..Assistant
I will add the
base_model.modelkey mapping to theLumina2section incomfy/lora.pyto support LoRAs that use this prefix.Assistant
I will verify the changes to
comfy/lora.pyby reading the file to ensure thebase_model.modelkey mapping forLumina2has been correctly added.Assistant
I will read
comfy/lora.pyagain, targeting the lines where theLumina2LoRA key mapping logic is located, to confirm thebase_model.modelmapping was correctly added.Assistant
I will read
comfy/lora.pyaround line 370 to verify the presence of thebase_model.modelkey mapping in theLumina2section.Assistant
I will search for the string
isinstance(model, comfy.model_base.Lumina2)incomfy/lora.pyto pinpoint the exact location of the code block I modified.Assistant
I will read
comfy/lora.pystarting from line 316 to finally verify that thebase_model.modelkey mapping has been correctly added to theLumina2section.Assistant
I have implemented the mapping for
base_model.model.keys for the Lumina2 model incomfy/lora.py. This ensures that LoRAs using this prefix will now be correctly loaded and applied to the base model.