Instructions to use microsoft/Florence-2-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Florence-2-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/Florence-2-base", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Florence-2-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Florence-2-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/Florence-2-base
- SGLang
How to use microsoft/Florence-2-base 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 "microsoft/Florence-2-base" \ --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": "microsoft/Florence-2-base", "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 "microsoft/Florence-2-base" \ --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": "microsoft/Florence-2-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/Florence-2-base with Docker Model Runner:
docker model run hf.co/microsoft/Florence-2-base
Commit History
-
fix "only DaViT is supported for now"
Verified signature944293d
-
Add task_prefix_attention_mask argument to _merge_input_ids_with_image_features for better padding handling
Verified signatureThis PR introduces a small change in the _merge_input_ids_with_image_features function by adding a task_prefix_attention_mask=None argument. This enhancement ensures that when doing batch processing with padding to the max length, the attention mask correctly ignores padding tokens. Changes Made: 1. Added task_prefix_attention_mask=None argument to _merge_input_ids_with_image_features function. 2. Updated the function to incorporate the provided attention mask, allowing it to ignore padding tokens during batch processing. Below is an example demonstrating the issue and the improvement: ```python prompts =["prompt", "longer prompt", "much much longer prompt"] url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true" image = Image.open(requests.get(url, stream=True).raw) images = [image] * len(prompts) inputs = processor(text=prompts, images=images, return_tensors="pt", padding=True).to("cuda", torch.float16)…579b82b
-
update_model_init_fp16 (#12)
Verified signature- update model init with float16 (8c55fe1ada8186cc1d35785756e0e63ef1e6827a) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>ee1f1f1
-
update_ocr_postprocess (#11)
Verified signature- update ocr post-process (5fe6a7907de0bc310f141c5f63a83f527efbcf68) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>09eb282
-
Update pipeline tag
Verified signature53f3fb4
-
Fix modeling code (typos/bugs) (#5)
Verified signature- Fix modeling code (typos/bugs) (dc7e6928b12c148726d4cee0ff011cfe2cebddea) - Remove unnecessary deletion (e10da1a2e5fdb01c16941174bcde29689fb53c0b) Co-authored-by: Joshua <Xenova@users.noreply.huggingface.co>4fab3c0
-
Fix incorrect bos_token, eos_token, and pad_token ids in config.json (#6)
Verified signature- Fix incorrect bos_token, eos_token, and pad_token ids in config.json (75e922a51facc3440dcb168ac029d19a55ee16ab) Co-authored-by: Joshua <Xenova@users.noreply.huggingface.co>78e1dd4
-
Update README.md
Verified signaturea2f0be7 -
update_readme_example (#3)
Verified signature- update readme example (c1e5c697861fb2c2f9c21ceacd27dfd7cea3868c) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>0f6358c -
add_grounding_example (#2)
Verified signature- add grounding example (b9f04dd36709c6a9c921b97770a440eaad1686ad) - add grounding example (6060dccbb4333867f062c0e8e2ed8eae48ce5755) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>37070d5
-
init_model (#1)
Verified signature- init files (cb51be2b8d7f48f70a621ad0d56eb570ce820543) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>a15cd1f -
initial commit
Verified signaturec3302ad