Instructions to use MILVLG/imp-v1-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MILVLG/imp-v1-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="MILVLG/imp-v1-3b", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("MILVLG/imp-v1-3b", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use MILVLG/imp-v1-3b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MILVLG/imp-v1-3b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MILVLG/imp-v1-3b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/MILVLG/imp-v1-3b
- SGLang
How to use MILVLG/imp-v1-3b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "MILVLG/imp-v1-3b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MILVLG/imp-v1-3b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "MILVLG/imp-v1-3b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MILVLG/imp-v1-3b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use MILVLG/imp-v1-3b with Docker Model Runner:
docker model run hf.co/MILVLG/imp-v1-3b
Issue with fine tuning Imp using transformers trainer and peft lora
I am trying to fine tune Imp using hugging face transformers trainer and peft lora.
I have created the below transformation function:
def generate_prompt(data_point):
process = model.get_vision_tower().to(dtype=torch.bfloat16)
image_processor = process.image_processor
images = [image.convert('RGB') for image in data_point["image"]]
image_tensors = [image_processor(image, return_tensors='pt')['pixel_values'][0] for image in images]
prefix_text = """A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nUSER: <image>\n"""
output = data_point['text']
text = f"{prefix_text} Describe the images, give me names. ASSISTANT: {output}"
encoding = tokenizer(text, truncation=True, return_tensors="pt")
encoding = {k: v.squeeze(0) for k, v in encoding.items()}
output_encoding = tokenizer(output, truncation=True, return_tensors="pt")
nb_toks_answer = len(output_encoding.input_ids[0])
return {
'images': image_tensors,
'input_ids': encoding['input_ids'],
'attention_mask': encoding['attention_mask'],
'labels': encoding['input_ids'],
'nb_toks_answer': [nb_toks_answer]
}
Then using
dataset.set_transform(generate_prompt)
to transform the dataset.
Lora config:
lora_config = LoraConfig(
r=64,
lora_alpha=32,
target_modules=["Wqkv","out_proj", "k_proj","v_proj","q_proj","out_proj", ],
lora_dropout=0.04,
bias="none",
task_type="CAUSAL_LM"
)
model = get_peft_model(model, lora_config)
Trainer config:
tokenizer.pad_token = tokenizer.eos_token
trainer = transformers.Trainer(
model=model,
train_dataset=dataset,
args=transformers.TrainingArguments(
per_device_train_batch_size=1,
gradient_accumulation_steps=1,
warmup_steps=0.03,
max_steps=5,
learning_rate=1e-4,
bf16=True,
logging_steps=1,
output_dir="outputs_imp_finetuned_test",
optim="adamw_torch",
save_strategy="steps",
remove_unused_columns=False,
use_cpu=False
),
data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False),
)
But I keep encountering issues like:
TypeError: ImpForCausalLM.forward() got an unexpected keyword argument 'nb_toks_answer'
IndexError: tuple index out of range
I am not sure what I need to change but any help will be appreciated
Hi, thanks for your interest to imp. Perhaps you can try to fine tune Imp in your custom dataset by the script we provided in imp github. Hope it will be help.