Comments (6)
Thanks for bringing that up! I think reset_parameters()
will not make the weights 0 though but reinitialize them when I understand correctly. So I think this should be okay but I may be overlooking something. (Please correct me if I'm wrong or am missing the point).
So, only LoRA matrix B is zero, but LoRA matrix A should be initialized with small random weights, i.e.,
std_dev = 1 / torch.sqrt(torch.tensor(lora_r).float())
self.A = nn.Parameter(torch.randn(in_dim, rank) * std_dev)
However, I am just seeing that we used Kaiming He initialization for the linear layer with sqrt(5):
Line 135 in 449eb29
Maybe we should investigate some time if using the original initialization scaling based on the rank is actually better @awaelchli @carmocca ?
from litgpt.
Hi @rasbt! I think you are correct. reset_parameters()
do not make the weights 0, it initializes the lora_A
matrix with Kaiming He initizalization and the lora_B
matrix with zeros. What I'm saying is that the reset_parameters()
is called inside the __init__()
method, and when the GPT module is constructed under the fabric.init_module()
context manager, the reset_parameters()
is not actually serving its purpose (both matrices end up initialized with zeros). In order to correctly intialize the matrices, I had to call reset_parameters()
after calling __init__()
(outside the context manager).
from litgpt.
@LautaroEst Which Fabric strategy are you using?
from litgpt.
@awaelchli I'm using just one gpu, so I'm initializing the fabric object with
fabric = L.Fabric(accelerator="gpu", strategy="auto", devices=1, num_nodes=1, precision="bf16-true")
from litgpt.
@rasbt We follow the same initialization as Microsoft's: https://github.com/microsoft/LoRA/blob/main/loralib/layers.py#L266-L271 which itself matches what you propose: https://github.com/pytorch/pytorch/blob/main/torch/nn/modules/linear.py#L106-L109
from litgpt.
I'm using just one gpu, so I'm initializing the fabric object with
In this case, empty_init=False
is used: https://github.com/Lightning-AI/litgpt/blob/main/litgpt/finetune/lora.py#L170 so initialization should be happening normally
from litgpt.
Related Issues (20)
- Failed to load the finetuned model with `AutoModelForCausalLM.from_pretrained(name, state_dict=state_dict)` HOT 4
- litgpt download doesn't work HOT 7
- Add support for memory-efficient and faster optimizers HOT 1
- combine FSDP with selective activation checkpointing
- A potential bug for multi-GPU training HOT 5
- Why FSDPStrategy is so slow-down when I use multi-machine HOT 4
- After some iteration in pretraining a LLM, IndexError is raised related to dataset chunking
- Cannot copy out of meta tensor; no data! HOT 2
- How to specify which GPU to use? HOT 2
- How to use custom dataset for evaluate?
- fabric.print only works on sys.stderr, does not print inference result HOT 1
- LoRA multi-GPU no longer works if applying LoRA selectively HOT 3
- Will CycleIterator forward to dataset on resume for pretrain? HOT 1
- ValueError: Cannot attend to 3063, block size is only 2048 HOT 1
- Customizable loss function & inference step? HOT 2
- Address frozen parameter warning with FSDP on nightly torch HOT 1
- LR scheduler can result in a division by 0
- how to solve this debug
- LoRA matrices dropout
- test_tinyllama issue with LitData and `iterate_over_all` 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 litgpt.