Image-Text-to-Text
Transformers
Safetensors
perception_lm
quantized
int4
language-model
conversational
4-bit precision
bitsandbytes
Instructions to use Dhruvil03/Perception-LM-1B-Int4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Dhruvil03/Perception-LM-1B-Int4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Dhruvil03/Perception-LM-1B-Int4bit") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("Dhruvil03/Perception-LM-1B-Int4bit") model = AutoModelForImageTextToText.from_pretrained("Dhruvil03/Perception-LM-1B-Int4bit") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Dhruvil03/Perception-LM-1B-Int4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Dhruvil03/Perception-LM-1B-Int4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dhruvil03/Perception-LM-1B-Int4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Dhruvil03/Perception-LM-1B-Int4bit
- SGLang
How to use Dhruvil03/Perception-LM-1B-Int4bit 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 "Dhruvil03/Perception-LM-1B-Int4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dhruvil03/Perception-LM-1B-Int4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "Dhruvil03/Perception-LM-1B-Int4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dhruvil03/Perception-LM-1B-Int4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Dhruvil03/Perception-LM-1B-Int4bit with Docker Model Runner:
docker model run hf.co/Dhruvil03/Perception-LM-1B-Int4bit
# Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("Dhruvil03/Perception-LM-1B-Int4bit")
model = AutoModelForImageTextToText.from_pretrained("Dhruvil03/Perception-LM-1B-Int4bit")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))Quick Links
Perception-LM-1B Int4-bit Quantized
This repository contains a 4-bit quantized version of Perception-LM-1B β optimized for reduced memory usage and faster inference, while retaining most of the capabilities of the full-precision model.
βοΈ Model Description
- Base model:
facebook/Perception-LM-1B - Quantization: 4-bit integer quantization (INT4).
- Purpose: Provide a lighter, more resource-efficient variant for inference, deployment on resource-constrained hardware, or quick prototyping.
β Intended Use & Use Cases
This quantized model is suited for:
- Fast inference when GPU/CPU memory or VRAM is limited
- Prototyping or integrating into applications where resource efficiency matters
- Use in research or production pipelines where quantization is acceptable
β οΈ Limitations (Things to Watch Out For)
- Quantization can introduce slight degradation compared to full-precision: responses may be less accurate or fluent in edge cases.
- Not recommended for use-cases requiring maximum fidelity (e.g. very fine-grained reasoning, sensitive safety-critical tasks).
- Performance may depend on hardware: quantized weights may require specific inference settings (device map, memory constraints).
π How to Use
Here is an example of how you can load the quantized model using transformers:
import torch
from transformers import AutoProcessor, AutoModelForImageTextToText
model_id = "Dhruvil03/Perception-LM-1B-Int4bit"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id,
torch_dtype=torch.float16
).to("cuda").eval()
conversation = [{
"role": "user",
"content": [
{"type": "video", "url": "test.mp4"},
{"type": "text", "text": "Can you describe the video in detail?"},
],
}]
inputs = processor.apply_chat_template(
conversation,
num_frames=16, # change number of frames as per the CUDA memory availability
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
video_load_backend="pyav",
)
inputs = {k: (v.to("cuda") if hasattr(v, "to") else v) for k, v in inputs.items()}
with torch.inference_mode():
outputs = model.generate(**inputs, max_new_tokens=64)
ilen = inputs["input_ids"].shape[1]
decoded = processor.batch_decode(outputs[:, ilen:], skip_special_tokens=True)
print(decoded[0])
- Downloads last month
- 3
Model tree for Dhruvil03/Perception-LM-1B-Int4bit
Base model
facebook/Perception-LM-1B
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Dhruvil03/Perception-LM-1B-Int4bit") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)