LoRA CLIP
1.0.0
跨图像或文本编码器或两个编码器的动态Lora-Layer插入。
将预训练的OpenAI夹重负载安全地加入洛拉的模型中。
通过正确冻结positional_embedding , logit_scale和Project来加载微调现成的模型。
注意:我们目前仅在图像编码器的洛拉化学中支持视觉变压器模型。重新连接模型将很快添加。
重要的是:在安装loraclip之前,请确保您有剪辑。这可以通过
pip install regex ftfy
pip install git+https://github.com/openai/CLIP.git然后,您可以通过命令pip pip install loraclip直接安装此软件包。或者,您可以考虑通过
git clone https://github.com/jaisidhsingh/LoRA-CLIP.git
cd LoRA-CLIP
pip install -e . 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 )https://github.com/openai/clip
https://github.com/sivandoveh/tsvlc