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)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("MILVLG/imp-v1-3b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- 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
Delete test.py
Browse files
test.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
-
from PIL import Image
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
torch.set_default_device("cuda")
|
| 7 |
-
|
| 8 |
-
#Create model
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
-
"/data/ouyangxc/labs/hg/imp-v1-3b",
|
| 11 |
-
torch_dtype=torch.float16,
|
| 12 |
-
device_map="auto",
|
| 13 |
-
trust_remote_code=True)
|
| 14 |
-
tokenizer = AutoTokenizer.from_pretrained("/data/ouyangxc/labs/hg/imp-v1-3b", trust_remote_code=True)
|
| 15 |
-
|
| 16 |
-
#Set inputs
|
| 17 |
-
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. USER: <image>\nWhat's the color of the car? ASSISTANT:"
|
| 18 |
-
image = Image.open("images/car.jpg")
|
| 19 |
-
|
| 20 |
-
input_ids = tokenizer(text, return_tensors='pt').input_ids
|
| 21 |
-
image_tensor = model.image_preprocess(image)
|
| 22 |
-
|
| 23 |
-
#Generate the answer
|
| 24 |
-
output_ids = model.generate(
|
| 25 |
-
input_ids,
|
| 26 |
-
max_new_tokens=150,
|
| 27 |
-
images=image_tensor,
|
| 28 |
-
use_cache=True)[0]
|
| 29 |
-
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|