Comments (1)
After some more investigation, not specifically creating dW
seems to work.
The LoRA forward pass is modified to accept low rank matrices directly. Then, dW
is not specifically created and the GPU memory utilization goes down to 2000MB.
def forward_lora(self, x, dWa, dWb):
B, S, E = x.shape
#calculate frozen model output
qkv = self.qkv(x).reshape(B, 3, S, E).permute(1, 0, 2, 3)
#calculate LoRA adaption
dqkv = (x@dWb.T @ dWa.T).reshape(B, 3, S, E).permute(1, 0, 2, 3)
#add as in equation (3) in paper
qkv = qkv + dqkv
q, k, v = qkv.unbind(0)
attn = q @ k.transpose(-2, -1)
x = attn @ v
return x
I tried to do this using pytorch parameterization. But this seems to copy the original weight tensor:
import torch.nn.utils.parametrize as parametrize
class LoRA_Layer_Mod(nn.Module):
def __init__(self, embed_dim, rank, device):
super().__init__()
self.embed_dim = embed_dim
self.dWa = nn.Parameter(torch.normal(0, 1, (3*embed_dim, rank))/sqrt(rank)).to(device)
self.dWb = nn.Parameter(torch.normal(0, 1, (rank, embed_dim))/sqrt(rank)).to(device)
def forward(self, qkv):
return qkv + self.dWa @ self.dWb
basemodel = BaseModel(embed).to('cuda:0')
basemodel.requires_grad_(False)
x = torch.ones((1, seq, embed)).to('cuda:0')
lora_layer = LoRA_Layer_Mod(embed_dim=embed, rank=2, device='cuda:0')
parametrize.register_parametrization(basemodel.qkv, "weight", lora_layer)
out = basemodel(x)
out = torch.sum(out)
out.backward()
input('check nvidia-smi for GPU utilization')
The conclusion seems to be to not create AB
matrix specifically and don't use pytorch parametrization.
from lora.
Related Issues (20)
- Code samples for "UNDERSTANDING THE LOW-RANK UPDATES" chapter (chapter 7). HOT 2
- why use alpha/r in stead of alpha? HOT 2
- Error in MergedLinear HOT 5
- RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)` HOT 4
- Pre-trained conv weight is not same as that self.conv.weight HOT 3
- matmul ordering in MergedLinear HOT 1
- How does this paper search the hyperparameters on GLUE datasets with Roberta? HOT 1
- gpt2_ft.py: error: unrecognized arguments: --local-rank=0 HOT 1
- M1 Pro 14 inch HOT 1
- Pershendetje HOT 1
- Code
- Is LoRA only applied to query and value matrices?
- Marvelous! Great work! HOT 1
- Bug after the latest commit #63 HOT 1
- MergedLinear bug? HOT 2
- Is it possible to fine-tuning model to extend token limit length? HOT 1
- Replicating Result on WebNLG HOT 1
- there's some bug in layer.py
- AB matrix initialization in layers.py does not conform to the description of the paper 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 lora.