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, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True) model = AutoModelForImageTextToText.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- 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
initial tuned 4k context length model (#84)
Browse files- add 4k context length model (43013a8f5eccffac1f83ec7d00e94b9ecb218380)
Co-authored-by: Haiping Wu <haipingwu@users.noreply.huggingface.co>
- README.md +3 -1
- config.json +1 -1
- pytorch_model.bin +2 -2
README.md
CHANGED
|
@@ -10,6 +10,8 @@ tags:
|
|
| 10 |
|
| 11 |
## Model Summary
|
| 12 |
|
|
|
|
|
|
|
| 13 |
This Hub repository contains a HuggingFace's `transformers` implementation of Florence-2 model from Microsoft.
|
| 14 |
|
| 15 |
Florence-2 is an advanced vision foundation model that uses a prompt-based approach to handle a wide range of vision and vision-language tasks. Florence-2 can interpret simple text prompts to perform tasks like captioning, object detection, and segmentation. It leverages our FLD-5B dataset, containing 5.4 billion annotations across 126 million images, to master multi-task learning. The model's sequence-to-sequence architecture enables it to excel in both zero-shot and fine-tuned settings, proving to be a competitive vision foundation model.
|
|
@@ -53,7 +55,7 @@ inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, to
|
|
| 53 |
generated_ids = model.generate(
|
| 54 |
input_ids=inputs["input_ids"],
|
| 55 |
pixel_values=inputs["pixel_values"],
|
| 56 |
-
max_new_tokens=
|
| 57 |
num_beams=3,
|
| 58 |
do_sample=False
|
| 59 |
)
|
|
|
|
| 10 |
|
| 11 |
## Model Summary
|
| 12 |
|
| 13 |
+
**This is a continued pretrained version of Florence-2-large model with 4k context length, only 0.1B samples are used for continue pretraining, thus it might not be trained well. In addition, OCR task has been updated with line separator ('\n'). COCO OD AP 39.8**
|
| 14 |
+
|
| 15 |
This Hub repository contains a HuggingFace's `transformers` implementation of Florence-2 model from Microsoft.
|
| 16 |
|
| 17 |
Florence-2 is an advanced vision foundation model that uses a prompt-based approach to handle a wide range of vision and vision-language tasks. Florence-2 can interpret simple text prompts to perform tasks like captioning, object detection, and segmentation. It leverages our FLD-5B dataset, containing 5.4 billion annotations across 126 million images, to master multi-task learning. The model's sequence-to-sequence architecture enables it to excel in both zero-shot and fine-tuned settings, proving to be a competitive vision foundation model.
|
|
|
|
| 55 |
generated_ids = model.generate(
|
| 56 |
input_ids=inputs["input_ids"],
|
| 57 |
pixel_values=inputs["pixel_values"],
|
| 58 |
+
max_new_tokens=4096,
|
| 59 |
num_beams=3,
|
| 60 |
do_sample=False
|
| 61 |
)
|
config.json
CHANGED
|
@@ -46,7 +46,7 @@
|
|
| 46 |
"LABEL_1": 1,
|
| 47 |
"LABEL_2": 2
|
| 48 |
},
|
| 49 |
-
"max_position_embeddings":
|
| 50 |
"no_repeat_ngram_size": 3,
|
| 51 |
"normalize_before": false,
|
| 52 |
"num_hidden_layers": 12,
|
|
|
|
| 46 |
"LABEL_1": 1,
|
| 47 |
"LABEL_2": 2
|
| 48 |
},
|
| 49 |
+
"max_position_embeddings": 4096,
|
| 50 |
"no_repeat_ngram_size": 3,
|
| 51 |
"normalize_before": false,
|
| 52 |
"num_hidden_layers": 12,
|
pytorch_model.bin
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:8b7d99c2ca930af3bcc4625df55c82b6bb372456280310b5189c519d6083a270
|
| 3 |
+
size 1555689792
|