Closed minmie closed 1 month ago
Hi @minmie , I also found this problem. If you try to run the code as following :
for name, params in model.named_parameters(): print('name ',name)
you will find that the torch.nn.Parameters module will not appear in name. modules_to_save will Use regular matching to find the
"model.vit.embeddings.position_embeddings" , as for here , obviously , modules_to_save will find nothing. My solution to this is to use nn.Embedding instead.
I don't understand where the nn.Parameter
is registered. Is it implicit because you pass image_size=SIZE
?
My solution to this is to use nn.Embedding instead.
This means you found a way to make it work? Great. It would be fantastic if you could share your code here in case other users encounter the same problem.
@BenjaminBossan yes, the position encoding will be reinitialized due to the new image size.
Hmm, this is still not quite clear to me. The modules_to_save
should match the name of the VitEmbeddings
module, not the nn.Parameter
directly. So this shouldn't really matter. But regardless, what was your exact solution?
hi, @dengchengxifrank , thank you for your solution.
My solution to this is to use nn.Embedding instead.
This maybe work for modules_to_save , but the model.vit.embeddings.position_embeddings is built-in , I don't known how to change it when fine tuning a pre-trained vit model.
Hi, @BenjaminBossan you are right, modules_to_save will match the VitEmbeddings, but if I add VitEmbeddings(model.vit.embeddings) in modules_to_save as follow:
lora_config = LoraConfig(
lora_alpha=16,
lora_dropout=0.3,
bias='none',
target_modules=['query', 'key', 'value'],
modules_to_save=[
'classifier',
"model.vit.embeddings"
]
)
an error will occur:
Thanks for giving more details -- though ideally in the future, you could copy the text instead of taking a photo :-)
This allowed me to trace down the issue and work on a PR to fix it, #2117.
The PR is merged, so using PEFT installed from source should resolve the issue.
System Info
transformers
version: 4.44.0Who can help?
@BenjaminBossan @sayakpaul
Information
Tasks
examples
folderReproduction
Expected behavior
I have increased the resolution of the image to 512, and I hope to retrain the position emb initialized by nn.parameters (as I have increased the image resolution) while fine-tuning the model using Lora.However, I found that the final saved Lora model did not include the position emb. How should I solve this problem?