Instructions to use microsoft/Florence-2-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Florence-2-large with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/Florence-2-large", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Florence-2-large with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Florence-2-large" # 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-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/Florence-2-large
- SGLang
How to use microsoft/Florence-2-large 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-large" \ --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-large", "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-large" \ --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-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/Florence-2-large with Docker Model Runner:
docker model run hf.co/microsoft/Florence-2-large
Commit History
-
Fix silently-skipped resize/normalize from None-valued processor kwargs
Verified signatureFlorence2Processor.__call__ forwards do_resize/do_normalize/image_mean/image_std/resample/do_convert_rgb to the image processor unconditionally, defaulting to None when the caller doesn't override them. This transformers version's image processor treats an explicit None as "disable this feature", not "use the configured default" -- confirmed by direct testing: calling the bare CLIPImageProcessor with do_resize=None produces unresized 512x512 output (matching the raw input image) instead of the configured 768x768, and with do_normalize=None the output stays in raw [0,1] instead of the normalized [-2.12, 2.64] range, with no error in either case. Only forward kwargs the caller actually set, so the image processor's own configured defaults apply otherwise. Verified live: resize now produces the correct 768x768 output for a 512x512 input image.5e92a22 -
Fix two transformers-v5 AttributeErrors in Florence-2 remote code
Verified signaturetransformers v5 changed two things this repo's remote code still assumes the old behavior for (see MIGRATION_GUIDE_V5.md): 1. `forced_bos_token_id` is no longer auto-set as a config instance attribute ('Modeling > Generate'). `Florence2LanguageConfig` read `self.forced_bos_token_id` assuming the old behavior. 2. `additional_special_tokens` was renamed to `extra_special_tokens`. `Florence2Processor.__init__` read the old attribute name, raising AttributeError. Both fixes are minimal and backward compatible with transformers v4. Related: kijai/ComfyUI-Florence2#187, #199, Comfy-Org/ComfyUI#12277, Lightricks/ComfyUI-LTXVideo#394 all hit the symptom of bug 1. #119 also contains fixes for both but bundles them with a full-repo rewrite that corrupts config.json (swaps in Florence-2-base's architecture dimensions), so it's not safe to merge as-is -- this PR is scoped to just these two AttributeErrors. Supersedes #121, which fixed bug 1 alone and later had bug 2 added as a second commit; thi…67061fd
-
add_confidence_score (#56)
Verified signature- add confidence score parsing (2ce7cd7837dfc8d93bf1d77dae95669ef1bcf0b3)f0acedb
-
Fix invalid escape sequences (#65)
Verified signature- Fix invalid escape sequences (e66fed94dc63ee1785716366c4e51aeb05a6ba25) Co-authored-by: Junpei Kawamoto <jkawamoto@users.noreply.huggingface.co>39ddb41
-
update_model_init_fp16 (#53)
Verified signature- update model init with float16 (93d5b247d87e5e0afeafe5b49c4a796aa5ba9e7c) - update model init with float16 (bab1b3cbc340fac15205568422af11476c232442) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>6bf1792
-
update_ocr_postprocess (#52)
Verified signature- update ocr post-process (f2eb43e7c5267c1bdf4053f1478b29fc875703c8) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>df93020
-
Fix runon lines (#16)
Verified signature- Fix runon lines (e83cf618af698c7037d277e6f595ffe536d7ea17) Co-authored-by: Marcin Miłkowski <milekpl@users.noreply.huggingface.co>aec3bc5
-
add_model (#1)
Verified signature- init files (2a83a12b643b0cd18fde2bee55c8a1bc43a4949d) Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>33ee8e1