Instructions to use tiny-random/phi-3-vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/phi-3-vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/phi-3-vision", trust_remote_code=True) 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("tiny-random/phi-3-vision", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/phi-3-vision with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/phi-3-vision" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/phi-3-vision", "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/tiny-random/phi-3-vision
- SGLang
How to use tiny-random/phi-3-vision 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 "tiny-random/phi-3-vision" \ --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": "tiny-random/phi-3-vision", "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 "tiny-random/phi-3-vision" \ --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": "tiny-random/phi-3-vision", "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 tiny-random/phi-3-vision with Docker Model Runner:
docker model run hf.co/tiny-random/phi-3-vision
This is a randomly initialized tiny model based on microsoft/Phi-3-vision-128k-instruct for testing and debugging.
| Feature | Source | This repo |
|---|---|---|
| Checkpoint tensor elements | 4.15B BF16 | 10.04M BF16 |
| Safetensors weight files | 8.29 GB (2 files) | 20.09 MB (model.safetensors) |
| Text layers | 32 | 4 |
| Text hidden / MLP width | 3,072 / 8,192 | 128 / 352 |
| Text Q heads / KV heads / head_dim | 32 / 32 / 96 | 4 / 4 / 32 |
| Vision encoder | CLIP-ViT-L/14-336: 24 layers, width 1024 | 4 layers, width 128 |
| Vision input / patch grid | 336px / 24x24, 144 HD tokens | Same |
| HD feature width / projector | 4,096 / 2-layer MLP | 512 / 2-layer MLP |
| Vocabulary rows / embedding tying | 32,064 / untied | Same |
| Stored precision | BF16 | Same |
This Phi-3-Vision revision is not registered in the installed Transformers release, so the pinned upstream remote code is included (load with trust_remote_code=True) with targeted Transformers 5.x Cache API compatibility shims. The 336px/14-patch image contract and the HD 2x2 patch merge are preserved, including the 144 image-token placeholder per global crop; only the CLIP encoder width and depth shrink.
SGLang 0.5.10 registers no native implementation for Phi3VForCausalLM (no EntryClass in sglang/srt/models), so only the generic TransformersForCausalLM fallback exists, which does not shard the model across tensor-parallel ranks. Serving evidence for this repository is the Transformers example.
| File path | Size |
|---|---|
| model.safetensors | 20.1MB |
Example usage
Transformers (β verified)
Load the included pinned Phi-3-Vision implementation with trust_remote_code=True.
def run_transformers(model_id: str):
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
model_id = str(model_id)
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
model = (
AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=True, dtype=torch.bfloat16, attn_implementation="eager"
)
.eval()
.cuda()
)
image = Image.new("RGB", (336, 336), color=(200, 60, 60))
messages = [{"role": "user", "content": "<|image_1|>\nWhat is shown in this image?"}]
prompt = processor.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(prompt, images=[image], return_tensors="pt").to("cuda")
with torch.no_grad():
assert torch.isfinite(model(**inputs).logits).all()
output = model.generate(
**inputs, do_sample=False, max_new_tokens=8, eos_token_id=processor.tokenizer.eos_token_id
)
print(processor.batch_decode(output[:, inputs["input_ids"].shape[1] :], skip_special_tokens=True)[0])
if __name__ == "__main__":
run_transformers(model_id="tiny-random/phi-3-vision")
Creating this repo
- Code: .meta/create_model.py
- Model structure: .meta/model.log
- Environment: .meta/env.json
Change log
- 2026-11-07: Initial version rebuilt from the official microsoft/Phi-3-vision-128k-instruct source, shipping its pinned remote code with a four-layer text tower and a four-layer 128-wide CLIP vision encoder.
This repo is generated by GPT-6.1-Sol.
- Downloads last month
- 20
Model tree for tiny-random/phi-3-vision
Base model
microsoft/Phi-3-vision-128k-instruct