Comments (4)
Note that set_adapter
enables requires_grad
on the adapter whose name was passed and turns it off on all other adapters. However, since the PEFT model is a PyTorch nn.Module
, as always, you can just iterate through the modules and enable or disable gradient according to your wishes:
model.set_adapter("adapterA")
# now only adapter A's weights have gradients enabled
for name, param in model.named_parameters():
if ...: # do some check, e.g. `if "lora_" in name`
param.requires_grad = True
from peft.
Thank you for your answer.
However, this isn't quite what I had in mind.
How can I set the different adapters inside the forward path?
For example, does the following code work?
Because setting requires_grad = True
inside the forward path seems little bit weird.
# Inside the model
def forward(self, x, y):
model_a.set_adapter("adapter_x")
output_x = model_a(x)
model_a.set_adapter("adapter_y")
output_y = model_a(y)
final_output = model_b(output_x, output_y)
return final_output
output = model(x, y)
loss = loss_fn(output)
loss.backward()
from peft.
It's really hard to answer your question with this little context. The code you pasted should work. It means that for output_x
, only gradients for adapter_x
etc. If you try this, do you get an error or does the training work?
from peft.
I've tried it, and the code works :)
I misunderstood the set_adapter
function.
I thought the line model_a.set_adapter("adapter_y")
freezes the other adapters (such as model_a.set_adapter("adapter_x")
).
Thanks for your replies :)
from peft.
Related Issues (20)
- Initialization for LoRA weights A and B initialized HOT 1
- Trainer.train() giving me Key Error: [random number] HOT 3
- Delete certain layers from PEFT model. HOT 6
- DoRA training in distributed setting
- Reproducibility when using a model with batch norm
- FSDP Dora/QDora Broken HOT 4
- CUDA kernels from PEFT v0.11.0 breaks C++ compilation HOT 4
- Adapter Merge for Idefics2 HOT 2
- `AdaLoRA` is incompatible with `gradient checkpointing` when using `torchrun` HOT 2
- LoRA adaptation shape mismatch HOT 7
- cannot import name 'get_peft_config' from 'peft' (unknown location) HOT 1
- how to fine tune LoRA HQQ? HOT 1
- How to finetune embeddings and LM head as a single layer when they are tied? HOT 1
- Help with : LoRA issue in distributed setting HOT 2
- ImportError with pkg_resources and packaging in PEFT when using setuptools >= 70.0.0 HOT 2
- High loss when init with `AdaLora` HOT 3
- LoRA Adapter from local model are leading to error HOT 1
- AdaLora: rank remains constant (to init_r value) across training HOT 3
- Issues when switching between multiple adapters LoRAs HOT 7
- Add Special Optimizer for LoRA training HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peft.