Instructions to use microsoft/Florence-2-large-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Florence-2-large-ft 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-ft", trust_remote_code=True)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True) model = AutoModelForImageTextToText.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use microsoft/Florence-2-large-ft 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-ft" # 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-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/Florence-2-large-ft
- SGLang
How to use microsoft/Florence-2-large-ft 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-ft" \ --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-ft", "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-ft" \ --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-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/Florence-2-large-ft with Docker Model Runner:
docker model run hf.co/microsoft/Florence-2-large-ft
Add GenerationMixin to ConditionalGeneration class
#34
by rockerBOO - opened
- modeling_florence2.py +2 -1
modeling_florence2.py
CHANGED
|
@@ -28,6 +28,7 @@ from collections import OrderedDict
|
|
| 28 |
from einops import rearrange
|
| 29 |
from timm.models.layers import DropPath, trunc_normal_
|
| 30 |
|
|
|
|
| 31 |
from transformers.modeling_utils import PreTrainedModel
|
| 32 |
from transformers.utils import (
|
| 33 |
ModelOutput,
|
|
@@ -2529,7 +2530,7 @@ class Florence2VisionModelWithProjection(Florence2PreTrainedModel):
|
|
| 2529 |
"""The FLORENCE2 model which consists of a vision backbone and a language model.""",
|
| 2530 |
FLORENCE2_START_DOCSTRING,
|
| 2531 |
)
|
| 2532 |
-
class Florence2ForConditionalGeneration(Florence2PreTrainedModel):
|
| 2533 |
def __init__(self, config: Florence2Config):
|
| 2534 |
super().__init__(config)
|
| 2535 |
assert config.vision_config.model_type == 'davit', 'only DaViT is supported for now'
|
|
|
|
| 28 |
from einops import rearrange
|
| 29 |
from timm.models.layers import DropPath, trunc_normal_
|
| 30 |
|
| 31 |
+
from transformers import GenerationMixin
|
| 32 |
from transformers.modeling_utils import PreTrainedModel
|
| 33 |
from transformers.utils import (
|
| 34 |
ModelOutput,
|
|
|
|
| 2530 |
"""The FLORENCE2 model which consists of a vision backbone and a language model.""",
|
| 2531 |
FLORENCE2_START_DOCSTRING,
|
| 2532 |
)
|
| 2533 |
+
class Florence2ForConditionalGeneration(Florence2PreTrainedModel, GenerationMixin):
|
| 2534 |
def __init__(self, config: Florence2Config):
|
| 2535 |
super().__init__(config)
|
| 2536 |
assert config.vision_config.model_type == 'davit', 'only DaViT is supported for now'
|