"""Budgeted multiple-choice inference for VideoLLaMA3 + qbase compressor checkpoints. Per video (see vbe/budget.py for the rules): decode (1 fps, or lower so that T <= B//64*8 frames) -> one resolution for all frames -> frozen encoder -> plan: all raw / hybrid (lowest-variation groups compressed) / forced 8-frame groups -> compressed groups: qbase over the WHOLE video's encoder tokens (as in training, so Option A's reference stats are the full window's) -> checkpoint mm_projector -> raw frames: ORIGINAL VideoLLaMA3 mm_projector (--raw_mode orig, Phase-1 checkpoints), or (--raw_mode phase3) as Phase-3 training sends them (videollama3/model/hybrid_raw.py): at most --raw_max_tokens rows per frame, re-encoded from the frame's pixels when larger, through the checkpoint mm_projector -> LLM input in time order: raw frame Time {t:.1f}s: followed by "," (or "\n" after the last block) compressed group Time:{a}s-{b}s:<|compression_start|><|compression_end|> a / b = integer seconds of the group's first / last frame. One process per GPU; videos sharded round-robin; results appended to a jsonl and resumed by qid. """ import argparse import itertools import json import math import os import time from collections import OrderedDict, deque from concurrent.futures import ThreadPoolExecutor os.environ.setdefault("TOKENIZERS_PARALLELISM", "false") import ffmpeg import numpy as np import torch from torch.utils.data import DataLoader, Dataset from transformers import DynamicCache from videollama3.constants import DEFAULT_IMAGE_TOKEN from videollama3.model import Videollama3Qwen2ForCausalLM from videollama3.model.processor import Videollama3Processor from videollama3.model.projector import build_vision_projector from vbe import budget as bd from vbe.benchmarks import DEFAULT_ROOT, build_prompt, extract_choice, load_benchmark VIDEO_SLOT = "<<