Code Monkey home page Code Monkey logo

vlora's Introduction

Intro

Official repository for the paper Vertical LoRA: Dense Expectation-Maximization Interpretation of Transformers. VLoRA reduces the parameter count of Transformers by about 75% while preserving their performance.

Install

Run

pip install vlora

Out-of-box usage

VLoRA has some built-in models you can use directly. The following example imports, init a VLoRA-ViT model and performs a forward pass.

from vlora.models import VisionTransformerVLoRA

vit = VisionTransformerVLoRA()
x = torch.randn((1, 3, 224, 224))
y = vit(x)

Customized usage

You can apply VloRA to your own layer and use it as the building block of your model.

Assume

  • you have a model of class Model consisting of layers of class Layer.
  • Layer is instantialized by layer = Layer(a, b=b, c=c).
  • Layer has a 2D parameter L.mod.param, which you want to vlorafy.

You can create a VLoRA Compound from your layer:

from vlora.models import VLoRACompound

comp = VLoRACompound(
    a,
    b=b,
    c=c,
    vl_base_cls=Layer,
    vl_param_name='mod.param',
    vl_size=3, # compound size
    vl_rank=2, # low rank r
    vl_alpha=1,
)

Then replace the layer with the compound in your model. Note if your model has L layers, you should have L/vl_size compounds in the vlorofied model.

vlora's People

Contributors

neverusethisname avatar

Stargazers

 avatar

Watchers

 avatar

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.