Image-Text-to-Text
Transformers
Safetensors
qwen3_vl
image-captioning
video-captioning
reinforcement-learning
vllm
conversational
Instructions to use fengyao123/DiffCapRL-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use fengyao123/DiffCapRL-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="fengyao123/DiffCapRL-4B") 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("fengyao123/DiffCapRL-4B") model = AutoModelForMultimodalLM.from_pretrained("fengyao123/DiffCapRL-4B", 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 fengyao123/DiffCapRL-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "fengyao123/DiffCapRL-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "fengyao123/DiffCapRL-4B", "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/fengyao123/DiffCapRL-4B
- SGLang
How to use fengyao123/DiffCapRL-4B 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 "fengyao123/DiffCapRL-4B" \ --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": "fengyao123/DiffCapRL-4B", "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 "fengyao123/DiffCapRL-4B" \ --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": "fengyao123/DiffCapRL-4B", "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 fengyao123/DiffCapRL-4B with Docker Model Runner:
docker model run hf.co/fengyao123/DiffCapRL-4B
|
Download README.md from fengyao123/DiffCapRL-4B: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/fengyao123/DiffCapRL-4B/resolve/main/README.md
- Command line
-
hf download hf://fengyao123/DiffCapRL-4B/README.md
-
curl -L -o README.md https://huggingface.co/fengyao123/DiffCapRL-4B/resolve/main/README.md
2.75 kB
| license: apache-2.0 | |
| base_model: Qwen/Qwen3-VL-4B-Instruct | |
| base_model_relation: finetune | |
| library_name: transformers | |
| pipeline_tag: image-text-to-text | |
| tags: | |
| - image-captioning | |
| - video-captioning | |
| - reinforcement-learning | |
| - vllm | |
| # DiffCap-RL 4B | |
| DiffCap-RL 4B is a multimodal captioning model fine-tuned from [Qwen3-VL-4B-Instruct](https://huggingface.co/Qwen/Qwen3-VL-4B-Instruct) with reinforcement learning. It generates detailed captions for images and videos. This repository contains the full BF16 model weights, tokenizer, chat template, and image/video processors. | |
| ## Case | |
| Install the dependencies in a fresh environment: | |
| ```bash | |
| python -m pip install torch==2.8.0 torchvision==0.23.0 transformers==4.57.1 vllm==0.11.0 qwen-vl-utils==0.0.14 Pillow==12.1.0 | |
| ``` | |
| ```python | |
| from pathlib import Path | |
| from vllm import LLM, SamplingParams | |
| MODEL_ID = "fengyao123/DiffCapRL-4B" # Or the path to downloaded model weights. | |
| IMAGE = "https://huggingface.co/datasets/Borise/CaptionQA/resolve/main/natural/images/4.jpg" | |
| # To caption your own image, set IMAGE = "/path/to/image.jpg". | |
| if __name__ == "__main__": | |
| image_url = IMAGE | |
| local_media_dir = "" | |
| if not IMAGE.startswith(("https://", "http://")): | |
| image_path = Path(IMAGE).expanduser().resolve(strict=True) | |
| image_url = image_path.as_uri() | |
| local_media_dir = str(image_path.parent) | |
| llm = LLM( | |
| model=MODEL_ID, | |
| dtype="bfloat16", | |
| tensor_parallel_size=1, | |
| gpu_memory_utilization=0.6, | |
| max_model_len=32768, | |
| max_num_seqs=32, | |
| limit_mm_per_prompt={"image": 1, "video": 0}, | |
| allowed_local_media_path=local_media_dir, | |
| seed=1, | |
| generation_config="vllm", | |
| enable_chunked_prefill=True, | |
| ) | |
| sampling = SamplingParams( | |
| temperature=0.7, | |
| top_p=1.0, | |
| top_k=-1, | |
| max_tokens=4096, | |
| repetition_penalty=1.0, | |
| frequency_penalty=0.0, | |
| presence_penalty=0.0, | |
| ) | |
| messages = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "text", "text": "Describe this image in detail."}, | |
| {"type": "image_url", "image_url": {"url": image_url}}, | |
| ], | |
| } | |
| ] | |
| result = llm.chat( | |
| messages=[messages], | |
| sampling_params=sampling, | |
| use_tqdm=False, | |
| )[0] | |
| prediction = result.outputs[0] | |
| print(prediction.text.strip()) | |
| if prediction.finish_reason == "length": | |
| print("\n[Output limit reached: this caption may be incomplete.]") | |
| ``` | |
| ## License and limitations | |
| Released under Apache-2.0. Retain the base model's license and attribution. Generated captions may contain incorrect or unsupported details; verify them against the input image. | |