Image-Text-to-Text
Transformers
Safetensors
qwen3_5
vllm
video
multimodal
reinforcement-learning
temporal-grounding
object-tracking
video-segmentation
visual-question-answering
spatial-reasoning
qwen3.5
conversational
Instructions to use OraRL/Video-ORA-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OraRL/Video-ORA-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OraRL/Video-ORA-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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("OraRL/Video-ORA-4B") model = AutoModelForMultimodalLM.from_pretrained("OraRL/Video-ORA-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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OraRL/Video-ORA-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OraRL/Video-ORA-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": "OraRL/Video-ORA-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/OraRL/Video-ORA-4B
- SGLang
How to use OraRL/Video-ORA-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 "OraRL/Video-ORA-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": "OraRL/Video-ORA-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 "OraRL/Video-ORA-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": "OraRL/Video-ORA-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 OraRL/Video-ORA-4B with Docker Model Runner:
docker model run hf.co/OraRL/Video-ORA-4B
| # Copyright 2024 Bytedance Ltd. and/or its affiliates | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| import json | |
| import os | |
| import random | |
| import re | |
| import shutil | |
| import tempfile | |
| from abc import ABC, abstractmethod | |
| from typing import Any, Optional, Union | |
| import numpy as np | |
| import torch | |
| import torch.distributed as dist | |
| from filelock import FileLock | |
| from torch.distributed.fsdp import FullyShardedDataParallel as FSDP | |
| from transformers import PreTrainedTokenizer, ProcessorMixin | |
| CHECKPOINT_TRACKER = "checkpoint_tracker.json" | |
| class BaseCheckpointManager(ABC): | |
| """ | |
| A checkpoint manager that saves and loads | |
| - model | |
| - optimizer | |
| - lr_scheduler | |
| - extra_states | |
| in a SPMD way. | |
| We save | |
| - sharded model states and optimizer states | |
| - full lr_scheduler states | |
| - huggingface tokenizer and config for ckpt merge | |
| """ | |
| def __init__( | |
| self, | |
| model: FSDP, | |
| optimizer: torch.optim.Optimizer, | |
| lr_scheduler: torch.optim.lr_scheduler.LRScheduler, | |
| processing_class: Union[PreTrainedTokenizer, ProcessorMixin], | |
| ): | |
| self.model = model | |
| self.optimizer = optimizer | |
| self.lr_scheduler = lr_scheduler | |
| self.processing_class = processing_class | |
| assert isinstance(self.model, FSDP) | |
| self.rank = dist.get_rank() | |
| self.world_size = dist.get_world_size() | |
| def load_checkpoint(self, *args, **kwargs): | |
| raise NotImplementedError | |
| def save_checkpoint(self, *args, **kwargs): | |
| raise NotImplementedError | |
| def local_mkdir(path: str) -> str: | |
| if not os.path.isabs(path): | |
| working_dir = os.getcwd() | |
| path = os.path.join(working_dir, path) | |
| # Using hash value of path as lock file name to avoid long file name | |
| lock_filename = f"ckpt_{hash(path) & 0xFFFFFFFF:08x}.lock" | |
| lock_path = os.path.join(tempfile.gettempdir(), lock_filename) | |
| try: | |
| with FileLock(lock_path, timeout=60): | |
| os.makedirs(path, exist_ok=True) | |
| except Exception as e: | |
| print(f"Warning: Failed to acquire lock for {path}: {e}") | |
| os.makedirs(path, exist_ok=True) # even if the lock is not acquired, try to create the directory | |
| return path | |
| def get_rng_state() -> dict[str, Any]: | |
| rng_state = { | |
| "cpu": torch.get_rng_state(), | |
| "cuda": torch.cuda.get_rng_state(), | |
| "numpy": np.random.get_state(), | |
| "random": random.getstate(), | |
| } | |
| return rng_state | |
| def load_rng_state(rng_state: dict[str, Any]): | |
| torch.set_rng_state(rng_state["cpu"]) | |
| torch.cuda.set_rng_state(rng_state["cuda"]) | |
| np.random.set_state(rng_state["numpy"]) | |
| random.setstate(rng_state["random"]) | |
| def get_checkpoint_tracker_filename(root_path: str) -> str: | |
| """ | |
| Tracker file rescords the latest chckpoint during training to restart from. | |
| """ | |
| return os.path.join(root_path, CHECKPOINT_TRACKER) | |
| def find_latest_ckpt( | |
| path: str, directory_format: str = "global_step_{}" | |
| ) -> tuple[Optional[str], Optional[dict[str, Any]]]: | |
| """ | |
| Find the latest checkpoint in the save path. | |
| """ | |
| tracker_file = get_checkpoint_tracker_filename(path) | |
| if not os.path.exists(tracker_file): | |
| return None, None | |
| with open(tracker_file, "rb") as f: | |
| checkpointer_tracker_info = json.load(f) | |
| ckpt_path = os.path.join(path, directory_format.format(checkpointer_tracker_info["last_global_step"])) | |
| if not os.path.exists(ckpt_path): | |
| print(f"Checkpoint does not exist: {ckpt_path}") | |
| return None, None | |
| print(f"Found latest checkpoint: {ckpt_path}, will resume from it. Turn off `find_last_checkpoint` to disable it.") | |
| return ckpt_path, checkpointer_tracker_info | |
| def remove_obsolete_ckpt( | |
| path: str, global_step: int, best_global_step: int, save_limit: int = -1, directory_format: str = "global_step_{}" | |
| ): | |
| """ | |
| Remove the obsolete checkpoints that exceed the save limit. | |
| """ | |
| if save_limit <= 0 or not os.path.exists(path): | |
| return | |
| num_ckpt_to_keep = save_limit - 1 # exclude the current ckpt | |
| pattern = re.escape(directory_format).replace(r"\{\}", r"(\d+)") | |
| ckpt_global_steps = [] | |
| for folder in os.listdir(path): | |
| if match := re.match(pattern, folder): | |
| step = int(match.group(1)) | |
| if step < global_step: | |
| ckpt_global_steps.append(step) | |
| ckpt_global_steps.sort(reverse=True) | |
| if best_global_step in ckpt_global_steps: # do not remove the best ckpt | |
| ckpt_global_steps.remove(best_global_step) | |
| num_ckpt_to_keep = max(num_ckpt_to_keep - 1, 0) | |
| for step in ckpt_global_steps[num_ckpt_to_keep:]: | |
| folder_path = os.path.join(path, directory_format.format(step)) | |
| try: | |
| shutil.rmtree(folder_path, ignore_errors=True) | |
| print(f"Removed obsolete checkpoint: {folder_path}") | |
| except Exception as e: | |
| print(f"Failed to remove {folder_path}: {e}") | |
| def thin_out_old_ckpts( | |
| path: str, | |
| keep_full_step: int, | |
| directory_format: str = "global_step_{}", | |
| subdirs: tuple = ("actor", "critic"), | |
| ): | |
| """Reduce every ``global_step_*`` except ``keep_full_step`` to weights only. | |
| Model weights (``model_*.pt`` and ``huggingface/``) stay; optimizer and | |
| extra_state shards plus the step-level ``dataloader.pt`` are deleted. Paired | |
| with ``save_limit`` this keeps the N most recent checkpoints while only the | |
| newest one can resume an optimizer, which cuts disk usage substantially. | |
| Call order: ``remove_obsolete_ckpt`` to bound the count, then | |
| ``save_checkpoint``, then this function to thin the older steps. | |
| """ | |
| if not os.path.exists(path): | |
| return | |
| pattern = re.escape(directory_format).replace(r"\{\}", r"(\d+)") | |
| for folder in os.listdir(path): | |
| match = re.match(pattern, folder) | |
| if match is None: | |
| continue | |
| step = int(match.group(1)) | |
| if step == keep_full_step: | |
| continue | |
| ckpt_root = os.path.join(path, folder) | |
| # dataloader.pt sits at the root of the step directory. | |
| dataloader_pt = os.path.join(ckpt_root, "dataloader.pt") | |
| if os.path.isfile(dataloader_pt): | |
| try: | |
| os.remove(dataloader_pt) | |
| except OSError as e: | |
| print(f"Failed to remove {dataloader_pt}: {e}") | |
| # optimizer / extra_state shards live under the actor/critic subdirectories. | |
| for sub in subdirs: | |
| subdir = os.path.join(ckpt_root, sub) | |
| if not os.path.isdir(subdir): | |
| continue | |
| for fname in os.listdir(subdir): | |
| if fname.startswith("optim_") or fname.startswith("extra_state_"): | |
| try: | |
| os.remove(os.path.join(subdir, fname)) | |
| except OSError as e: | |
| print(f"Failed to remove {os.path.join(subdir, fname)}: {e}") | |
| print(f"Thinned out old checkpoint (kept model weights only): {ckpt_root}") | |