Skip to main content

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

Metadata

Release files for loraclip 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loraclip 0.1.0
File Size Uploaded
loraclip-0.1.0.tar.gz 20.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loraclip 0.1.0
File Interpreter ABI Platform
loraclip-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.8 kB

Release files / loraclip-0.1.0.tar.gz

Download URL loraclip-0.1.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
57c931039fffa6d9beaeded31a7dd86b003741fa9787af61d6c335e8ab22bc9a
BLAKE2b-256 checksum
How to use checksums
73b10dd6e53018d669bf1fd043d1793f223ce291b57b6977ea101be1bfb03f4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.5

Release files / loraclip-0.1.0-py3-none-any.whl

Download URL loraclip-0.1.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c997ba70de468dfb312e600e72fe244d7109c3a20ee3f6d9ac969de72aa74213
BLAKE2b-256 checksum
How to use checksums
d780e473569c04b81021c8ac3735cd325b8de21a2033262f56453a9df337758e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page