Skip to main content

A simple and efficient wrapper for LoRA-ifying CLIP.

Project description

LoRA-CLIP: Easy Wrapper for LoRA-ifying CLIP

Features

  1. Dynamic LoRA-layer insertion across image or text encoder, or both encoders.

  2. Loads pre-trained OpenAI CLIP weights safely into LoRA-ified model.

  3. Loads fine-tuning ready models by correctly un-freezing positional_embedding, logit_scale, and projections.

Note: We currently only support Vision Transformer models in the LoRA-ification of image encoders. ResNet models will be added soon.

Installation

IMPORTANT: make sure you have CLIP before you install loraclip. This can simply be done by

pip install regex ftfy
pip install git+https://github.com/openai/CLIP.git

You can then install this package directly using pip via the command pip install loraclip. Alternatively, you can consider buidling this from source by

git clone https://github.com/jaisidhsingh/LoRA-CLIP.git
cd LoRA-CLIP
pip install -e .

Usage

import loraclip
import argparse


def test_loraclip(args):
	# Easy-to-use with standard CLIP syntax.
	# 1. Dynamic LoRA rank specification
	# 2. Specify which encoder(s) to LoRA-ify
	model, preprocess = loraclip.load(args.clip_model_name, device=args.device, r=args.lora_rank, lora_mode=args.lora_mode)
	# Utility to preview no. of trainable params along with their % with total params.
	loraclip.print_trainable_parameters(model)


def setup_args():
	parser = argparse.ArgumentParser()
	parser.add_argument("--clip-model-name", type=str, default="ViT-B/16")
	parser.add_argument("--device", type=str, default="cuda")
	parser.add_argument("--lora-rank", type=int, default=4)
	parser.add_argument("--lora-mode", type=str, default="vision+text", choices=["vision", "text", "vision+text"])

	args = parser.parse_args()
	return args


if __name__ == "__main__":
    args = setup_args()
    test_loraclip(args)

References

  1. https://github.com/openai/CLIP

  2. https://github.com/SivanDoveh/TSVLC

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loraclip-0.1.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

loraclip-0.1.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file loraclip-0.1.0.tar.gz.

File metadata

  • Download URL: loraclip-0.1.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.5

File hashes

Hashes for loraclip-0.1.0.tar.gz
Algorithm Hash digest
SHA256 57c931039fffa6d9beaeded31a7dd86b003741fa9787af61d6c335e8ab22bc9a
MD5 b1fa421b6dea129d34db010e0c112fe4
BLAKE2b-256 73b10dd6e53018d669bf1fd043d1793f223ce291b57b6977ea101be1bfb03f4c

See more details on using hashes here.

File details

Details for the file loraclip-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: loraclip-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.5

File hashes

Hashes for loraclip-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c997ba70de468dfb312e600e72fe244d7109c3a20ee3f6d9ac969de72aa74213
MD5 89a34259f121510d842c86e42eeb91fd
BLAKE2b-256 d780e473569c04b81021c8ac3735cd325b8de21a2033262f56453a9df337758e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page