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)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True) model = AutoModelForImageTextToText.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- 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
Matt commited on
Commit ·
1e8c51f
1
Parent(s): bef74d7
Tie weights correctly and update weights
Browse files- model.safetensors +2 -2
- modeling_florence2.py +6 -0
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:43c6d08c6afba4b18c373b5c0f94be59550c84ffe17993c1d3c2fe06c46f94ea
|
| 3 |
+
size 463221938
|
modeling_florence2.py
CHANGED
|
@@ -2066,6 +2066,12 @@ class Florence2LanguageForConditionalGeneration(Florence2LanguagePreTrainedModel
|
|
| 2066 |
# Initialize weights and apply final processing
|
| 2067 |
self.post_init()
|
| 2068 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2069 |
def get_encoder(self):
|
| 2070 |
return self.model.get_encoder()
|
| 2071 |
|
|
|
|
| 2066 |
# Initialize weights and apply final processing
|
| 2067 |
self.post_init()
|
| 2068 |
|
| 2069 |
+
def _tie_weights(self):
|
| 2070 |
+
if self.config.tie_word_embeddings:
|
| 2071 |
+
self._tie_or_clone_weights(self.model.encoder.embed_tokens, self.model.shared)
|
| 2072 |
+
self._tie_or_clone_weights(self.model.decoder.embed_tokens, self.model.shared)
|
| 2073 |
+
self._tie_or_clone_weights(self.lm_head, self.model.shared)
|
| 2074 |
+
|
| 2075 |
def get_encoder(self):
|
| 2076 |
return self.model.get_encoder()
|
| 2077 |
|