You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a model checkpoint checkpoint.pth which has the T5 weights plus a LoRA adapter and was saved in env1:
with open("checkpoint.pth"), "wb") as f:
torch.save(model.state_dict(), f)
From there I want to make sure I can load the model, run inference, and get the same outputs in env2. But the outputs are different. I run the following experiments:
Create a T5 model, add the empty LoRA adapter, run inference - env1 and env2 get to the same output
Create a T5 model, load the non-LoRA weights, run inference - env1 and env2 get to the same output
Create a T5 model, add the LoRA adapter, load all the weights, run inference - env1 has the right output but env2 is different.
Here is the code I use (in env1 I just remove import adapters, adapters.init(model), and use adapter_config = transformers.adapters.LoRAConfig(r=8, alpha=16):
Unfortunately I can't share the model weights. Any thoughts on what might be the reason I get different outputs only if I use LoRA and load my weights?
Expected behavior
Getting the same output in env1 and env2.
The text was updated successfully, but these errors were encountered:
After diving into the codebase, I think I understand the difference. This looks like a bug in the LoRALinear class, but I might be missing something.
In adapter-transformers, the linear output and the delta are combined with result = lora.com(result, delta_w, scaling=gate). In particular, if lora.use_gating == False then gate is None which means the scaling used is 16/8=2 in my case.
In adapters, they are combined with scaling=1.0. There is a comment saying "scaling already applied in compose" but I don't think it is? compose will run compose_stack which will run LoRALinear's compose_single which will run LoRA's forward which does not involve any scaling.
Am I missing something?
jblamare
changed the title
Different outputs when upgrading from adapter-transformers with T5, LoRA, and loaded weights
Different outputs when upgrading from adapter-transformers with LoRA
Nov 19, 2024
Environment info
adapters
version: 1.0.1transformers
version: 4.45.2Information
Model I am using (Bert, XLNet ...):
google/flan-t5-small
Language I am using the model on (English, Chinese ...): English
Adapter setup I am using (if any): LoRA
The problem arises when using:
The tasks I am working on is:
To reproduce
I have two environments:
I have some input_ids
I have a model checkpoint
checkpoint.pth
which has the T5 weights plus a LoRA adapter and was saved in env1:From there I want to make sure I can load the model, run inference, and get the same outputs in env2. But the outputs are different. I run the following experiments:
Here is the code I use (in env1 I just remove
import adapters
,adapters.init(model)
, and useadapter_config = transformers.adapters.LoRAConfig(r=8, alpha=16)
:Unfortunately I can't share the model weights. Any thoughts on what might be the reason I get different outputs only if I use LoRA and load my weights?
Expected behavior
Getting the same output in env1 and env2.
The text was updated successfully, but these errors were encountered: