Giter Site home page Giter Site logo

How does MergedLinear work? about lora HOT 7 OPEN

tspeterkim avatar tspeterkim commented on May 22, 2024
How does MergedLinear work?

from lora.

Comments (7)

edwardjhu avatar edwardjhu commented on May 22, 2024

Hi Peter,

MergedLinear should do exactly what Linear does mathematically when multiple linear layers are "merged" into one like in the GPT codebase. It's here simply to make the GPT integration easier.

Hope this helps!

from lora.

Andrei-Aksionov avatar Andrei-Aksionov commented on May 22, 2024

Hello @peterkim95
I've added some annotation for LoRA code in lit-llama repo which you can find helpful.


Nevertheless I don't quite understand why there is a combination of Linear (for matrix A) and Conv1d (for B) layers. Why not both Linear or Conv1d. @edwardjhu could you briefly explain this or maybe link to an article to read. Because I have no idea 🤷‍♂️ .
I have couple of suspicions that were described in my repo, but have a feeling that I'm not even near.

And by the way, thanks for your work 👍 .

from lora.

shipengai avatar shipengai commented on May 22, 2024

good issue

from lora.

clalanliu avatar clalanliu commented on May 22, 2024

For instance, if you wish to incorporate an 8-rank LoRA into the attention layer's 3 matrices (Q, K, V) within a model, you can utilize the following code:

lora_A = nn.Linear(in_features, 8 * 3, bias=False)
lora_B = nn.Conv1d(8 * 3, out_features, kernel_size=1, groups=3, bias=False)

If you choose to utilize nn.Linear in both A and B, it would be necessary to handle Q, K, and V separately. However, by employing nn.Conv1d and the group parameter, it becomes possible to process these three components simultaneously without any interference.

from lora.

Andrei-Aksionov avatar Andrei-Aksionov commented on May 22, 2024

Hello @clalanliu
So as I understand with nn.Conv1d and groups parameter each part in the combined qkv matrix will be processed independently, while with nn.Linear lora_B matrix will "see" and process the whole combined matrix. Am I wrong?

And if so why this approach is not used for the lora_A?

from lora.

clalanliu avatar clalanliu commented on May 22, 2024

@Andrei-Aksionov Yes. You can check my note

And if so why this approach is not used for the lora_A?

There is no need to do so, because the input of QKV matrices are all the same (that is, x).

from lora.

Andrei-Aksionov avatar Andrei-Aksionov commented on May 22, 2024

There is no need to do so, because the input of QKV matrices are all the same (that is, x).

Oh boy, how did I miss that 🤣. Thanks

from lora.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.