Image-Text-to-Text
Transformers
Safetensors
qwen3_5
qwen3.5
video
video-captioning
data-engine
conversational
Instructions to use nvidia/Flora-Captioner with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Flora-Captioner with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="nvidia/Flora-Captioner") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("nvidia/Flora-Captioner") model = AutoModelForMultimodalLM.from_pretrained("nvidia/Flora-Captioner", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nvidia/Flora-Captioner with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Flora-Captioner" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Flora-Captioner", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/nvidia/Flora-Captioner
- SGLang
How to use nvidia/Flora-Captioner 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 "nvidia/Flora-Captioner" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Flora-Captioner", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "nvidia/Flora-Captioner" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Flora-Captioner", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use nvidia/Flora-Captioner with Docker Model Runner:
docker model run hf.co/nvidia/Flora-Captioner
Download batch_utils/vendor/tempseg_fp32_loader.py from nvidia/Flora-Captioner: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/nvidia/Flora-Captioner/resolve/main/batch_utils/vendor/tempseg_fp32_loader.py
- Command line
-
hf download hf://nvidia/Flora-Captioner/batch_utils/vendor/tempseg_fp32_loader.py
-
curl -L -o tempseg_fp32_loader.py https://huggingface.co/nvidia/Flora-Captioner/resolve/main/batch_utils/vendor/tempseg_fp32_loader.py
3.42 kB
| from collections import Counter | |
| import hashlib | |
| from pathlib import Path | |
| import types | |
| def digest(path): | |
| with Path(path).open('rb') as stream: | |
| return hashlib.file_digest(stream, 'sha256').hexdigest() | |
| def load(spec, save): | |
| import torch | |
| from transformers import AutoModelForImageTextToText | |
| from transformers.models.qwen3_5.modeling_qwen3_5 import Qwen3_5PreTrainedModel | |
| from safetensors.torch import load_file | |
| from peft import PeftConfig, get_peft_model, get_peft_model_state_dict, set_peft_model_state_dict | |
| from production_gdn_fix import _keep_native_gdn_fp32 | |
| from verify_gdn import verify | |
| _keep_native_gdn_fp32(Qwen3_5PreTrainedModel) | |
| base, info = AutoModelForImageTextToText.from_pretrained(spec['base'], local_files_only=True, dtype=torch.bfloat16, attn_implementation='sdpa', output_loading_info=True) | |
| assert not any((info.get(k) for k in ['missing_keys', 'unexpected_keys', 'mismatched_keys', 'error_msgs'])), info | |
| path = Path(spec['export']) / 'adapter_model.safetensors' | |
| assert digest(path) == spec['adapter_sha256'] | |
| source = load_file(str(path), device='cpu') | |
| assert len(source) == 496 and sum((v.numel() for v in source.values())) == 86556672 | |
| assert all((v.dtype == torch.float32 for v in source.values())), 'Expected corrected FP32 checkpoint' | |
| model = get_peft_model(base, PeftConfig.from_pretrained(spec['export'], local_files_only=True), adapter_name='candidate', autocast_adapter_dtype=True) | |
| initial = get_peft_model_state_dict(model, adapter_name='candidate') | |
| assert set(initial) == set(source) | |
| assert all((v.dtype == torch.float32 for v in initial.values())), 'PEFT must create FP32 adapter holders' | |
| del initial | |
| load_info = set_peft_model_state_dict(model, source, adapter_name='candidate') | |
| assert not load_info.unexpected_keys, load_info | |
| actual = get_peft_model_state_dict(model, adapter_name='candidate') | |
| assert set(actual) == set(source) | |
| assert all((actual[k].dtype == v.dtype and torch.equal(actual[k].detach().cpu(), v) for k, v in source.items())), 'Saved FP32 LoRA values must be loaded exactly' | |
| del actual | |
| model.to('cuda:0').eval() | |
| actual = get_peft_model_state_dict(model, adapter_name='candidate') | |
| assert all((actual[k].dtype == torch.float32 and torch.equal(actual[k].detach().cpu(), v) for k, v in source.items())), 'Final device placement must preserve saved FP32 values' | |
| save('ADAPTER_VALUE_VERIFICATION.json', dict(tensors=496, elements=86556672, source_dtypes=dict(Counter((str(v.dtype) for v in source.values()))), holders_fp32_before_assignment=True, all_saved_values_exact_before_and_after_placement=True, adapter_sha256=spec['adapter_sha256'], merged=False)) | |
| del source, actual | |
| gdn = verify(model, spec['base'], peft_prefix=True) | |
| save('GDN_VALUE_VERIFICATION.json', gdn) | |
| original_generate = model.generate | |
| def generate_bf16(self, *args, **kwargs): | |
| with torch.autocast(device_type='cuda', dtype=torch.bfloat16): | |
| return original_generate(*args, **kwargs) | |
| model.generate = types.MethodType(generate_bf16, model) | |
| save('MODEL_LOADED.json', dict(adapter_persistent_dtype='torch.float32', compute_autocast='torch.bfloat16', gdn_values_exact=True, base_loading_info=info, parameter_dtypes=dict(Counter((str(p.dtype) for p in model.parameters()))), input_output_generation_policy_changed=False)) | |
| return model | |