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
-
Add GenerationMixin as parent class
Verified signatureRelated to [florence2-large discussion](https://huggingface.co/microsoft/Florence-2-large/discussions/80). Florence-2 currently triggers the following deprecation warning in the transformers library: ``` Florence2LanguageForConditionalGeneration has generative capabilities, as `prepare_inputs_for_generation` is explicitly overwritten. However, it doesn't directly inherit from `GenerationMixin`. From 👉v4.50👈 onwards, `PreTrainedModel` will NOT inherit from `GenerationMixin`, and this model will lose the ability to call `generate` and other related functions. - If you're using `trust_remote_code=True`, you can get rid of this warning by loading the model with an auto class. See https://huggingface.co/docs/transformers/en/model_doc/auto#auto-classes - If you are the owner of the model architecture code, please modify your model class such that it inherits from `GenerationMixin` (after `PreTrainedModel`, otherwise you'll get an exception). - If you are not the owner of the model ar…2a2d45e
-
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