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)# 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
Fix silently-skipped resize/normalize from None-valued processor kwargs
Browse filesFlorence2Processor.__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.
- processing_florence2.py +19 -7
|
@@ -251,17 +251,29 @@ class Florence2Processor(ProcessorMixin):
|
|
| 251 |
elif isinstance(text, list) and _is_str_or_image(text[0]):
|
| 252 |
pass
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
pixel_values = self.image_processor(
|
| 255 |
images,
|
| 256 |
-
do_resize=do_resize,
|
| 257 |
-
do_normalize=do_normalize,
|
| 258 |
return_tensors=return_tensors,
|
| 259 |
-
image_mean=image_mean,
|
| 260 |
-
image_std=image_std,
|
| 261 |
-
input_data_format=input_data_format,
|
| 262 |
data_format=data_format,
|
| 263 |
-
|
| 264 |
-
do_convert_rgb=do_convert_rgb,
|
| 265 |
)["pixel_values"]
|
| 266 |
|
| 267 |
if max_length is not None:
|
|
|
|
| 251 |
elif isinstance(text, list) and _is_str_or_image(text[0]):
|
| 252 |
pass
|
| 253 |
|
| 254 |
+
# None-valued kwargs must not be forwarded: this image processor treats an
|
| 255 |
+
# explicit None as "disable this feature" rather than "use the configured
|
| 256 |
+
# default", so passing do_resize=None (the default here when the caller
|
| 257 |
+
# doesn't override it) silently skips resizing -- and do_normalize=None
|
| 258 |
+
# silently skips normalization, with no error either way.
|
| 259 |
+
image_processor_overrides = {
|
| 260 |
+
k: v
|
| 261 |
+
for k, v in {
|
| 262 |
+
"do_resize": do_resize,
|
| 263 |
+
"do_normalize": do_normalize,
|
| 264 |
+
"image_mean": image_mean,
|
| 265 |
+
"image_std": image_std,
|
| 266 |
+
"input_data_format": input_data_format,
|
| 267 |
+
"resample": resample,
|
| 268 |
+
"do_convert_rgb": do_convert_rgb,
|
| 269 |
+
}.items()
|
| 270 |
+
if v is not None
|
| 271 |
+
}
|
| 272 |
pixel_values = self.image_processor(
|
| 273 |
images,
|
|
|
|
|
|
|
| 274 |
return_tensors=return_tensors,
|
|
|
|
|
|
|
|
|
|
| 275 |
data_format=data_format,
|
| 276 |
+
**image_processor_overrides,
|
|
|
|
| 277 |
)["pixel_values"]
|
| 278 |
|
| 279 |
if max_length is not None:
|