Compare commits

...
Author SHA1 Message Date
868ba03d9b fix: use qwen3_coder tool parser for Qwen3.5 models (#1953)
Release / Push CUDA image to Docker (push) Canceled after 0s
* fix: use qwen3_coder tool parser for Qwen3.5 models

Qwen3.5 uses a different tool call format than Qwen3. Qwen3 uses
hermes-style JSON, but Qwen3.5 uses an XML-like format with
<function=name><parameter=arg> tags. Map all Qwen3.5 variants to
the qwen3_coder parser so tool calls are parsed correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix for tool parser test

---------

Co-authored-by: root <root@vivid-capybara-of-dignity.datacrunch.io>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Johannes Hagemann <johannes@primeintellect.ai>
2026-03-04 21:36:31 -08:00
halleriteandGitHub aa33d910a4 update deep-gemm (#1944)
Release / Push CUDA image to Docker (push) Canceled after 0s
2026-03-04 12:57:07 -08:00
ac7ac62115 chore: update pydantic-config for JSON dict CLI support (#1943)
Release / Push CUDA image to Docker (push) Canceled after 0s
* chore: update pydantic-config for JSON dict CLI support

Update pydantic-config to latest main which adds support for passing
dict[str, Any] fields as JSON via CLI:
  --inference.vllm-extra '{"custom_arg": "value"}'

Also switch source from pinned rev to branch = "main".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: update pydantic-config lock to include JSON dict fix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 12:33:16 -08:00
JannikStandGitHub 99058e9e37 bump nvidia-cutlass-dsl to 4.4.1 for flash-attn-cute ampere_helpers (#1945)
Release / Push CUDA image to Docker (push) Canceled after 0s
2026-03-04 05:54:10 +01:00
halleriteandGitHub fe32efbee1 perf: deduplicate VLM image bytes in orchestrator cache (#1935)
Release / Push CUDA image to Docker (push) Canceled after 0s
2026-03-03 13:49:21 -08:00
6a97762b5c fix: use space-separated list args for tyro CLI compatibility (#1942)
Release / Push CUDA image to Docker (push) Canceled after 0s
* fix: use space-separated list args for tyro CLI compatibility

tyro parses list[str] fields as space-separated values, not
comma-separated. Update the multi-node SLURM template and integration
test to match. Also fix snake_case --weight_broadcast.host to
kebab-case --weight-broadcast.host.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* revert unnecessary kebab-case change for weight_broadcast.host

Both snake_case and kebab-case are accepted by tyro, so keep the
original snake_case to minimize diff.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 13:33:19 -08:00
8451067db7 fix env server task cancellation (#1939)
Release / Push CUDA image to Docker (push) Canceled after 0s
* bump vf (bb73f78, feature branch)

* fix: drop stale groups concurrently to avoid inflated cancellation count

The sequential drop_group loop allowed _fill_inflight_requests to add
new tasks to not-yet-dropped stale groups during yields, causing the
cancelled count to exceed max_inflight_rollouts. Using asyncio.gather
ensures all drops snapshot inflight_requests before any of them yield.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* bump vf (45fae8d, main)

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 12:03:21 -08:00
ea161dd743 fix: validate prompt length in TITO endpoint before computing max_tokens (#1938)
Release / Push CUDA image to Docker (push) Canceled after 0s
In multi-turn TITO rollouts, prompt_token_ids are injected after
render_chat_request, bypassing vLLM's built-in context length
validation. When the prompt exceeds max_model_len, get_max_tokens
returns a negative value, causing a BadRequestError ("max_tokens must
be at least 1") that isn't recognized as an overlong prompt by the
verifiers client — aborting the rollout instead of truncating it.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 11:07:29 -08:00
10 changed files with 426 additions and 99 deletions
+4 -3
View File
@@ -61,7 +61,7 @@ flash-attn-cute = [
]
[dependency-groups]
fp8-inference = [
"deep-gemm @ https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl",
"deep-gemm @ https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0-torch2.9/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl",
]
dev = [
"ipykernel>=6.29.5",
@@ -79,18 +79,19 @@ no-build-isolation-package = ["flash-attn"]
# See: https://github.com/pytorch/pytorch/issues/166122
override-dependencies = [
"nvidia-cudnn-cu12>=9.15",
"nvidia-cutlass-dsl>=4.4.1",
"transformers>=5.1.0.dev0",
]
[tool.uv.sources]
torch = { index = "pytorch-cu128" }
math-env = { index = "primeintellect" }
verifiers = { git = "https://github.com/PrimeIntellect-ai/verifiers.git", rev = "b35d0c7" }
verifiers = { git = "https://github.com/PrimeIntellect-ai/verifiers.git", rev = "45fae8d" }
torchtitan = { git = "https://github.com/pytorch/torchtitan", rev = "a1fdd7e" }
dion = { git = "https://github.com/samsja/dion.git", rev = "d891eeb" }
transformers = { git = "https://github.com/huggingface/transformers.git", rev = "609e3d5" }
flash-attn-cute = { git = "https://github.com/Dao-AILab/flash-attention.git", subdirectory = "flash_attn/cute", rev = "main" }
pydantic-config = { git = "https://github.com/samsja/pydantic_config.git", rev = "6990941" }
pydantic-config = { git = "https://github.com/samsja/pydantic_config.git", branch = "main" }
reverse-text = { index = "primeintellect" }
[tool.uv.extra-build-dependencies]
+19 -3
View File
@@ -98,9 +98,25 @@ MODEL_TOOL_CALL_PARSER: dict[str, str] = {
"Qwen/Qwen3-Coder-Next": "hermes",
"Qwen/Qwen3-Coder-Next-Base": "hermes",
"Qwen/Qwen3-Coder-Next-FP8": "hermes",
# Qwen3.5
"Qwen/Qwen3.5-397B-A17B": "hermes",
"Qwen/Qwen3.5-397B-A17B-FP8": "hermes",
# Qwen3.5 dense (uses qwen3_coder tool format, not hermes)
"Qwen/Qwen3.5-0.8B": "qwen3_coder",
"Qwen/Qwen3.5-0.8B-Base": "qwen3_coder",
"Qwen/Qwen3.5-2B": "qwen3_coder",
"Qwen/Qwen3.5-2B-Base": "qwen3_coder",
"Qwen/Qwen3.5-4B": "qwen3_coder",
"Qwen/Qwen3.5-4B-Base": "qwen3_coder",
"Qwen/Qwen3.5-9B": "qwen3_coder",
"Qwen/Qwen3.5-9B-Base": "qwen3_coder",
"Qwen/Qwen3.5-27B": "qwen3_coder",
"Qwen/Qwen3.5-27B-FP8": "qwen3_coder",
# Qwen3.5 MoE (uses qwen3_coder tool format, not hermes)
"Qwen/Qwen3.5-35B-A3B": "qwen3_coder",
"Qwen/Qwen3.5-35B-A3B-Base": "qwen3_coder",
"Qwen/Qwen3.5-35B-A3B-FP8": "qwen3_coder",
"Qwen/Qwen3.5-122B-A10B": "qwen3_coder",
"Qwen/Qwen3.5-122B-A10B-FP8": "qwen3_coder",
"Qwen/Qwen3.5-397B-A17B": "qwen3_coder",
"Qwen/Qwen3.5-397B-A17B-FP8": "qwen3_coder",
}
@@ -10,6 +10,7 @@ from vllm.entrypoints.openai.chat_completion.serving import OpenAIServingChat
from vllm.entrypoints.openai.engine.protocol import ErrorResponse, RequestResponseMetadata
from vllm.entrypoints.openai.engine.serving import GenerationError
from vllm.entrypoints.utils import get_max_tokens
from vllm.exceptions import VLLMValidationError
from vllm.logger import init_logger
from vllm.outputs import RequestOutput
from vllm.reasoning import ReasoningParser
@@ -154,10 +155,21 @@ class OpenAIServingChatWithTokens(OpenAIServingChat):
# have unique request ids.
sub_request_id = request_id if len(engine_prompts) == 1 else f"{request_id}_{i}"
prompt_len = self._extract_prompt_len(engine_prompt)
if prompt_len >= self.max_model_len:
raise VLLMValidationError(
f"This model's maximum context length is "
f"{self.max_model_len} tokens. However, your request has "
f"{prompt_len} input tokens. Please reduce the length of "
"the input messages.",
parameter="input_tokens",
value=prompt_len,
)
max_tokens = get_max_tokens(
self.max_model_len,
request.max_completion_tokens if request.max_completion_tokens is not None else request.max_tokens,
self._extract_prompt_len(engine_prompt),
prompt_len,
self.default_sampling_params,
)
+3 -3
View File
@@ -282,9 +282,9 @@ class Scheduler:
for task, info in list(self.inflight_requests.items())
if info.group_id is None or info.group_id not in stale_group_ids
]
removed = 0
for gid in stale_group_ids:
removed += await self.drop_group(gid)
counts = await asyncio.gather(*(self.drop_group(gid) for gid in stale_group_ids))
removed = sum(counts)
for task in tasks_to_increment:
info = self.inflight_requests.get(task)
if info is None:
+173 -68
View File
@@ -1,5 +1,6 @@
import base64
import time
from concurrent.futures import ThreadPoolExecutor
from io import BytesIO
import torch
@@ -73,13 +74,7 @@ def interleave_rollout(
# this field should be guaranteed because we set temperature in get_sampling_args
temperature = output["sampling_args"]["temperature"]
def get_images(step_idx: int) -> tuple[bytes | None, list[int] | None, list[list[int]] | None]:
if vlm_cache is None:
return None, None, None
key = output["example_id"] if cache_key is None else cache_key
return vlm_cache.get_for_step(key, step_idx)
def make_sample(step: vf.TrajectoryStep, step_idx: int) -> TrainingSample:
def make_sample(step: vf.TrajectoryStep) -> TrainingSample:
"""Create a new TrainingSample from a trajectory step."""
tokens = step["tokens"]
assert tokens is not None
@@ -88,7 +83,6 @@ def interleave_rollout(
else:
completion_mask = [bool(i) for i in tokens["completion_mask"]]
completion_ids = list(tokens["completion_ids"])
pixel_values, pixel_values_shape, image_grid_thw = get_images(step_idx)
routed_experts = _align_routed_experts(
tokens.get("routed_experts"),
@@ -104,13 +98,10 @@ def interleave_rollout(
completion_temperatures=[temperature] * len(completion_ids),
teacher_logprobs=None,
advantage=None,
pixel_values=pixel_values,
pixel_values_shape=pixel_values_shape,
image_grid_thw=image_grid_thw,
routed_experts=routed_experts,
)
def extend_sample(sample: TrainingSample, step: vf.TrajectoryStep, prefix_len: int, step_idx: int) -> None:
def extend_sample(sample: TrainingSample, step: vf.TrajectoryStep, prefix_len: int) -> None:
"""Extend an existing sample with a new trajectory step (extension property holds)."""
tokens = step["tokens"]
assert tokens is not None
@@ -132,12 +123,6 @@ def interleave_rollout(
sample.completion_logprobs.extend(tokens["completion_logprobs"])
sample.completion_temperatures.extend([temperature] * len(completion_ids))
# Update cumulative images to include any new images from this step
pixel_values, pixel_values_shape, image_grid_thw = get_images(step_idx)
sample.pixel_values = pixel_values
sample.pixel_values_shape = pixel_values_shape
sample.image_grid_thw = image_grid_thw
if tokens.get("routed_experts") is not None and sample.routed_experts is not None:
step_routed = tokens["routed_experts"]
# The previous step's last routing entry was zero-padded by _align_routed_experts
@@ -150,13 +135,12 @@ def interleave_rollout(
expected_len = len(sample.prompt_ids) + len(sample.completion_ids)
sample.routed_experts = _align_routed_experts(sample.routed_experts, expected_len)
# Track multiple active (prefix, sample) pairs to handle interleaved agents
# Each entry is [prefix_tokens, sample] where prefix_tokens is the accumulated token sequence
# Track [prefix_tokens, sample, last_step_idx] per active sample
active_samples: list[list] = []
first_tokens = trajectory[0]["tokens"]
first_prefix = first_tokens["prompt_ids"] + first_tokens["completion_ids"]
active_samples.append([first_prefix, make_sample(trajectory[0], step_idx=0)])
active_samples.append([first_prefix, make_sample(trajectory[0]), 0])
for step_idx, step in enumerate(trajectory[1:], start=1):
tokens = step["tokens"]
@@ -164,17 +148,17 @@ def interleave_rollout(
# Check if this step extends ANY active prefix
matched_idx = None
for idx, (prefix_tokens, _) in enumerate(active_samples):
for idx, (prefix_tokens, _, _) in enumerate(active_samples):
if step_prompt_ids[: len(prefix_tokens)] == prefix_tokens:
matched_idx = idx
break
if matched_idx is not None:
# Extension holds - merge into matched sample
prefix_tokens, sample = active_samples[matched_idx]
extend_sample(sample, step, len(prefix_tokens), step_idx=step_idx)
# Update prefix for this sample
prefix_tokens, sample, _ = active_samples[matched_idx]
extend_sample(sample, step, len(prefix_tokens))
active_samples[matched_idx][0] = tokens["prompt_ids"] + tokens["completion_ids"]
active_samples[matched_idx][2] = step_idx
else:
# No prefix matches - start a new sample
logger.debug(
@@ -182,9 +166,18 @@ def interleave_rollout(
f"Starting new sample (active_prefixes={len(active_samples)}, step_prompt_len={len(step_prompt_ids)})."
)
new_prefix = tokens["prompt_ids"] + tokens["completion_ids"]
active_samples.append([new_prefix, make_sample(step, step_idx=step_idx)])
active_samples.append([new_prefix, make_sample(step), step_idx])
return [sample for _, sample in active_samples]
# Attach images once per sample using only the last merged step
if vlm_cache is not None:
key = output["example_id"] if cache_key is None else cache_key
for _, sample, last_step_idx in active_samples:
pv, shape, grids = vlm_cache.get_for_step(key, last_step_idx)
sample.pixel_values = pv
sample.pixel_values_shape = shape
sample.image_grid_thw = grids
return [sample for _, sample, _ in active_samples]
# =============================================================================
@@ -212,15 +205,38 @@ def _extract_images_from_messages(messages: list) -> list[tuple[Image.Image, str
return images
def _collect_b64_keys_from_messages(messages: list) -> list[str]:
"""Extract base64 keys from OpenAI-style chat messages without decoding."""
keys = []
if not messages or not isinstance(messages, list):
return keys
for msg in messages:
content = msg.get("content", [])
if isinstance(content, list):
for item in content:
if item.get("type") == "image_url":
url = item.get("image_url", {}).get("url", "")
if url.startswith("data:image"):
keys.append(url.split(",", 1)[1])
return keys
def _decode_b64_image(b64_data: str) -> Image.Image:
"""Decode a single base64 string into a PIL Image."""
return Image.open(BytesIO(base64.b64decode(b64_data)))
_PARALLEL_DECODE_THRESHOLD = 4
def _extract_images_from_examples(
examples: list[tuple[int, vf.RolloutOutput]],
) -> tuple[list[Image.Image], dict[int, list[list[int]]]]:
"""
Extract images from all trajectory steps of each example.
Parses OpenAI-style message content looking for image_url items with base64 data URLs.
Images are deduplicated across the batch by their base64 content. Each step records
the indices of its images into the deduplicated all_images list.
Two-pass approach: first collects unique base64 keys (fast, string-only),
then decodes unique images in parallel via ThreadPoolExecutor.
Args:
examples: List of (cache_key, output) tuples where output contains a "trajectory"
@@ -232,8 +248,9 @@ def _extract_images_from_examples(
- step_image_indices_per_example: dict mapping cache_key to per-step lists of
indices into all_images (e.g., [[0], [0, 1], [1]] for the decreasing-images case)
"""
all_images: list[Image.Image] = []
image_registry: dict[str, int] = {} # b64_key -> index in all_images
# Pass 1: collect unique b64 keys and build step indices
unique_keys: list[str] = []
key_to_index: dict[str, int] = {}
step_image_indices_per_example: dict[int, list[list[int]]] = {}
for eid, output in examples:
@@ -245,42 +262,89 @@ def _extract_images_from_examples(
step_image_indices = []
for step in trajectory:
prompt = step.get("prompt")
step_image_pairs = _extract_images_from_messages(prompt)
b64_keys = _collect_b64_keys_from_messages(prompt)
indices = []
for img, key in step_image_pairs:
if key not in image_registry:
image_registry[key] = len(all_images)
all_images.append(img)
indices.append(image_registry[key])
for key in b64_keys:
if key not in key_to_index:
key_to_index[key] = len(unique_keys)
unique_keys.append(key)
indices.append(key_to_index[key])
step_image_indices.append(indices)
step_image_indices_per_example[eid] = step_image_indices
# Pass 2: decode unique images (parallel when worthwhile)
if len(unique_keys) > _PARALLEL_DECODE_THRESHOLD:
with ThreadPoolExecutor(max_workers=min(len(unique_keys), 16)) as pool:
all_images = list(pool.map(_decode_b64_image, unique_keys))
else:
all_images = [_decode_b64_image(k) for k in unique_keys]
return all_images, step_image_indices_per_example
_IMAGE_CHUNK_SIZE = 8
_DEFAULT_IMAGE_CHUNK_SIZE = 32
class _ImageStore:
"""Holds per-unique-image data, assembled lazily on demand.
Instead of duplicating pixel bytes for every step that references an image,
we store each image's bytes once and assemble the concatenation at retrieval time.
"""
def __init__(
self,
image_bytes: list[bytes],
image_num_patches: list[int],
patch_dim: int,
image_grids: list[list[int]],
):
self.image_bytes = image_bytes
self.image_num_patches = image_num_patches
self.patch_dim = patch_dim
self.image_grids = image_grids
self._cache: dict[tuple[int, ...], tuple[bytes, list[int], list[list[int]]]] = {}
def assemble(self, indices: list[int]) -> tuple[bytes, list[int], list[list[int]]]:
"""Assemble pixel bytes, shape, and grids for a set of image indices.
Results are cached by index tuple — multi-turn rollouts with the same
cumulative image set (common across rollouts of the same example) hit
the cache and skip the join.
"""
cache_key = tuple(indices)
cached = self._cache.get(cache_key)
if cached is not None:
return cached
total_patches = sum(self.image_num_patches[i] for i in indices)
pixel_bytes = b"".join(self.image_bytes[i] for i in indices)
shape = [total_patches, self.patch_dim]
grids = [self.image_grids[i] for i in indices]
result = (pixel_bytes, shape, grids)
self._cache[cache_key] = result
return result
def _preprocess_images_batched(
images: list[Image.Image],
step_image_indices_per_example: dict[int, list[list[int]]],
processor,
) -> dict[int, list[tuple[bytes | None, list[int] | None, list[list[int]] | None]]]:
chunk_size: int = _DEFAULT_IMAGE_CHUNK_SIZE,
) -> tuple["_ImageStore | None", dict[int, list[list[int]]]]:
"""
Preprocess all images in chunked batches, then distribute results per step.
Preprocess all images in chunked batches, returning an _ImageStore and step indices.
Images are processed in chunks to avoid OOM on large batches. Pixel values are
stored as raw float32 bytes for efficient serialization via msgspec.
Images are processed in chunks to avoid OOM on large batches. Per-image bytes are
stored once in the _ImageStore and assembled lazily at retrieval time.
Returns:
Dict mapping cache_key to list of (pixel_values_bytes, pixel_values_shape, image_grid_thw) per step.
Tuple of (_ImageStore or None, step_image_indices_per_example).
The store is None when there are no images or no processor.
"""
if not images or processor is None:
return {
eid: [(None, None, None)] * max(len(step_indices), 1)
for eid, step_indices in step_image_indices_per_example.items()
}
return None, step_image_indices_per_example
logger = get_logger()
image_sizes = [(img.width, img.height) for img in images]
@@ -288,8 +352,8 @@ def _preprocess_images_batched(
# Process images in chunks to avoid OOM
all_pixel_values_list = []
all_grid_thw_list = []
for i in range(0, len(images), _IMAGE_CHUNK_SIZE):
chunk = images[i : i + _IMAGE_CHUNK_SIZE]
for i in range(0, len(images), chunk_size):
chunk = images[i : i + chunk_size]
processed = processor.image_processor(images=chunk, return_tensors="pt")
all_pixel_values_list.append(processed["pixel_values"])
all_grid_thw_list.append(processed["image_grid_thw"])
@@ -307,24 +371,26 @@ def _preprocess_images_batched(
for g in all_grid_thw:
patch_starts.append(patch_starts[-1] + int(g[0] * g[1] * g[2]))
result = {}
for eid, step_indices_list in step_image_indices_per_example.items():
if not step_indices_list:
result[eid] = [(None, None, None)]
continue
patch_dim = all_pixel_values.shape[1]
per_step = []
for indices in step_indices_list:
if not indices:
per_step.append((None, None, None))
else:
grids = all_grid_thw[indices]
patches = torch.cat([all_pixel_values[patch_starts[i] : patch_starts[i + 1]] for i in indices], dim=0)
per_step.append((patches.numpy().tobytes(), list(patches.shape), grids.tolist()))
# Store per-image bytes once
image_bytes_list: list[bytes] = []
image_num_patches_list: list[int] = []
image_grids_list: list[list[int]] = []
for i in range(len(images)):
img_slice = all_pixel_values[patch_starts[i] : patch_starts[i + 1]]
image_bytes_list.append(img_slice.numpy().tobytes())
image_num_patches_list.append(img_slice.shape[0])
image_grids_list.append(all_grid_thw[i].tolist())
result[eid] = per_step
store = _ImageStore(
image_bytes=image_bytes_list,
image_num_patches=image_num_patches_list,
patch_dim=patch_dim,
image_grids=image_grids_list,
)
return result
return store, step_image_indices_per_example
class VLMImageCache:
@@ -337,15 +403,47 @@ class VLMImageCache:
extract_time: float,
preprocess_time: float,
):
self._store: _ImageStore | None = None
self._step_indices: dict[int, list[list[int]]] | None = None
self.cache = cache
self.num_unique_examples = num_unique_examples
self.extract_time = extract_time
self.preprocess_time = preprocess_time
@classmethod
def from_store(
cls,
store: _ImageStore | None,
step_indices: dict[int, list[list[int]]],
num_unique_examples: int,
extract_time: float,
preprocess_time: float,
) -> "VLMImageCache":
"""Create a store-backed cache that assembles bytes lazily."""
obj = cls.__new__(cls)
obj._store = store
obj._step_indices = step_indices
obj.cache = {}
obj.num_unique_examples = num_unique_examples
obj.extract_time = extract_time
obj.preprocess_time = preprocess_time
return obj
def _assemble(self, indices: list[int]) -> tuple[bytes | None, list[int] | None, list[list[int]] | None]:
if not indices:
return (None, None, None)
return self._store.assemble(indices)
def get_for_step(
self, cache_key: int, step_idx: int
) -> tuple[bytes | None, list[int] | None, list[list[int]] | None]:
"""Get cumulative images up to and including the given step."""
if self._store is not None:
steps = self._step_indices.get(cache_key, [])
if not steps or step_idx >= len(steps):
return (None, None, None)
return self._assemble(steps[step_idx])
steps = self.cache.get(cache_key, [])
if not steps or step_idx >= len(steps):
return (None, None, None)
@@ -353,6 +451,12 @@ class VLMImageCache:
def get_all(self, cache_key: int) -> tuple[bytes | None, list[int] | None, list[list[int]] | None]:
"""Get all images for the cache key (last step's cumulative images)."""
if self._store is not None:
steps = self._step_indices.get(cache_key, [])
if not steps:
return (None, None, None)
return self._assemble(steps[-1])
steps = self.cache.get(cache_key, [])
if not steps:
return (None, None, None)
@@ -375,11 +479,12 @@ def build_vlm_image_cache(rollouts: list[vf.RolloutOutput], processor) -> VLMIma
# Preprocess images
preprocess_start = time.perf_counter()
cache = _preprocess_images_batched(all_images, images_per_example, processor)
store, step_indices = _preprocess_images_batched(all_images, images_per_example, processor)
preprocess_time = time.perf_counter() - preprocess_start
return VLMImageCache(
cache=cache,
return VLMImageCache.from_store(
store=store,
step_indices=step_indices,
num_unique_examples=len(unique_example_ids),
extract_time=extract_time,
preprocess_time=preprocess_time,
@@ -58,7 +58,7 @@ else
if [ -z "$INFER_URLS" ]; then
INFER_URLS="http://$host:8000/v1"
else
INFER_URLS="$INFER_URLS,http://$host:8000/v1"
INFER_URLS="$INFER_URLS http://$host:8000/v1"
fi
done
fi
+2 -2
View File
@@ -212,8 +212,8 @@ def start_orchestrator(
"--wandb.name",
f"{wandb_name}-{proc_name}",
]
for base_url in INFERENCE_BASE_URLS:
cmd.extend(["--client.base-url", base_url])
cmd.append("--client.base-url")
cmd.extend(INFERENCE_BASE_URLS)
with open(orch_log_dir / "orchestrator.stdout", "w") as f:
proc = subprocess.Popen(
@@ -12,6 +12,7 @@ from prime_rl.orchestrator.trajectories import (
_align_routed_experts,
_extract_images_from_examples,
_extract_images_from_messages,
_ImageStore,
build_vlm_image_cache,
interleave_rollout,
)
@@ -2002,3 +2003,154 @@ def test_interleave_rollout_none_routed_experts_stays_none():
rollouts = interleave_rollout(output)
assert rollouts is not None
assert rollouts[0].routed_experts is None
# =============================================================================
# _ImageStore and store-backed VLMImageCache tests
# =============================================================================
def test_image_store_assemble():
"""_ImageStore.assemble joins per-image bytes and computes correct shape/grids."""
# 2 images: image 0 has 3 patches, image 1 has 2 patches, patch_dim=4
patch_dim = 4
img0 = np.arange(3 * patch_dim, dtype=np.float32).tobytes()
img1 = np.arange(2 * patch_dim, dtype=np.float32).tobytes()
store = _ImageStore(
image_bytes=[img0, img1],
image_num_patches=[3, 2],
patch_dim=patch_dim,
image_grids=[[1, 1, 3], [1, 1, 2]],
)
# Assemble both images
pixel_bytes, shape, grids = store.assemble([0, 1])
assert shape == [5, 4]
assert grids == [[1, 1, 3], [1, 1, 2]]
assert pixel_bytes == img0 + img1
# Assemble single image
pixel_bytes, shape, grids = store.assemble([1])
assert shape == [2, 4]
assert grids == [[1, 1, 2]]
assert pixel_bytes == img1
# Assemble in reverse order
pixel_bytes, shape, grids = store.assemble([1, 0])
assert shape == [5, 4]
assert grids == [[1, 1, 2], [1, 1, 3]]
assert pixel_bytes == img1 + img0
def test_vlm_image_cache_from_store():
"""VLMImageCache.from_store provides correct get_for_step/get_all via lazy assembly."""
patch_dim = 2
img0_data = np.array([[1.0, 2.0]], dtype=np.float32)
img1_data = np.array([[3.0, 4.0]], dtype=np.float32)
store = _ImageStore(
image_bytes=[img0_data.tobytes(), img1_data.tobytes()],
image_num_patches=[1, 1],
patch_dim=patch_dim,
image_grids=[[1, 2, 3], [1, 4, 4]],
)
step_indices = {
1: [[0], [0, 1]], # step 0: image 0; step 1: images 0+1
}
cache = VLMImageCache.from_store(
store=store,
step_indices=step_indices,
num_unique_examples=1,
extract_time=0.0,
preprocess_time=0.0,
)
# Step 0: just image 0
pv, shape, grid = cache.get_for_step(1, 0)
assert _decode_pixels(pv, shape) == [[1.0, 2.0]]
assert grid == [[1, 2, 3]]
# Step 1: images 0 + 1
pv, shape, grid = cache.get_for_step(1, 1)
assert _decode_pixels(pv, shape) == [[1.0, 2.0], [3.0, 4.0]]
assert grid == [[1, 2, 3], [1, 4, 4]]
# get_all returns last step
pv, shape, grid = cache.get_all(1)
assert _decode_pixels(pv, shape) == [[1.0, 2.0], [3.0, 4.0]]
assert grid == [[1, 2, 3], [1, 4, 4]]
# Missing key
pv, shape, grid = cache.get_for_step(999, 0)
assert pv is None
# Out of range step
pv, shape, grid = cache.get_for_step(1, 5)
assert pv is None
def test_vlm_image_cache_from_store_no_images():
"""from_store with store=None returns (None, None, None) for all queries."""
step_indices = {0: [[], []]} # 2 steps with no images
cache = VLMImageCache.from_store(
store=None,
step_indices=step_indices,
num_unique_examples=1,
extract_time=0.0,
preprocess_time=0.0,
)
pv, shape, grid = cache.get_for_step(0, 0)
assert pv is None
assert shape is None
assert grid is None
def test_build_vlm_image_cache_uses_store():
"""build_vlm_image_cache returns a store-backed cache."""
import torch
red_url = _create_test_image("red")
output = vf.RolloutOutput(
example_id=1,
trajectory=[
vf.TrajectoryStep(
prompt=[_create_image_message(red_url, "What color?")],
completion=[{"role": "assistant", "content": "Red"}],
response=MagicMock(),
tokens=MagicMock(),
reward=None,
advantage=None,
is_truncated=False,
trajectory_id="1",
extras={},
),
],
sampling_args={"temperature": 1.0},
error=None,
)
mock_processor = MagicMock()
mock_processor.image_processor = MagicMock(
side_effect=lambda images, return_tensors: {
"pixel_values": torch.arange(len(images), dtype=torch.float32).view(-1, 1),
"image_grid_thw": torch.tensor([[1, 1, 1]] * len(images)),
}
)
cache = build_vlm_image_cache([output], mock_processor)
# Should be store-backed
assert cache._store is not None
assert cache._step_indices is not None
# Should still work correctly
pv, shape, grid = cache.get_for_step(0, 0)
assert pv is not None
assert shape == [1, 1]
assert grid == [[1, 1, 1]]
+1 -1
View File
@@ -28,7 +28,7 @@ from prime_rl.inference.vllm.server import resolve_tool_call_parser
("Qwen/Qwen3-4B-Instruct-2507", "hermes"),
("Qwen/Qwen3-Coder-480B-A35B-Instruct", "hermes"),
("Qwen/Qwen3-Next-80B-A3B-Instruct", "hermes"),
("Qwen/Qwen3.5-397B-A17B", "hermes"),
("Qwen/Qwen3.5-397B-A17B", "qwen3_coder"),
],
)
def test_auto_detect_tool_call_parser(model_name: str, expected_parser: str):
Generated
+58 -17
View File
@@ -10,6 +10,7 @@ resolution-markers = [
[manifest]
overrides = [
{ name = "nvidia-cudnn-cu12", specifier = ">=9.15" },
{ name = "nvidia-cutlass-dsl", specifier = ">=4.4.1" },
{ name = "transformers", git = "https://github.com/huggingface/transformers.git?rev=609e3d5" },
]
@@ -390,6 +391,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/0b/b5/61ac2563c62490922b603c09113a083fd74af3630ec3931e769484d6dcb5/compressed_tensors-0.13.0-py3-none-any.whl", hash = "sha256:3518799c9baf034eb642efb551db6b0537b8713d45a64fe4def26f7f8d6cabec", size = 192620, upload-time = "2025-12-16T16:03:53.041Z" },
]
[[package]]
name = "connect-python"
version = "0.8.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "protobuf" },
{ name = "pyqwest" },
]
sdist = { url = "https://files.pythonhosted.org/packages/8f/8d/e04954dacc3c32c2f858a115b2b989ed6cccefc3835fb440bb12dcb468c2/connect_python-0.8.1.tar.gz", hash = "sha256:0d36c9cfe050661f8f167afcfff8df622805a4f348961d0d8fab630c96f0bdab", size = 39292, upload-time = "2026-01-27T05:00:02.751Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/7d/e4/e36a6d0450493e2b940086ebe94394381803b2b09c97e8f8e34230bcaa99/connect_python-0.8.1-py3-none-any.whl", hash = "sha256:bfe31fb3d90c2a6715fc2996fa4bd5c98dfdccd81e47ac232c9d03aadd666be1", size = 54902, upload-time = "2026-01-27T05:00:01.18Z" },
]
[[package]]
name = "cryptography"
version = "46.0.3"
@@ -562,9 +576,9 @@ wheels = [
[[package]]
name = "deep-gemm"
version = "2.3.0+35c4bc8"
source = { url = "https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl" }
source = { url = "https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0-torch2.9/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl" }
wheels = [
{ url = "https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl", hash = "sha256:e335e99dffeee5a10e91f375d3e9a8ed348f144ffa56aebff1576b9a2b56b697" },
{ url = "https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0-torch2.9/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl", hash = "sha256:c8ab813c466c7f4e63e85e39f35386ff8783cea885eadddbc2a7a0baf0240289" },
]
[[package]]
@@ -1969,7 +1983,18 @@ wheels = [
[[package]]
name = "nvidia-cutlass-dsl"
version = "4.3.5"
version = "4.4.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "nvidia-cutlass-dsl-libs-base" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/0d/a8/d9f2b82bf6f6b48502267fcf2fa7b229392affb68a6092da92b0edef7476/nvidia_cutlass_dsl-4.4.1-py3-none-any.whl", hash = "sha256:7b8ffa0117be35ef6c9a88f4462ee2a794efd0f7d9f65090e10a953e434fbfce", size = 10167, upload-time = "2026-02-27T09:37:34.551Z" },
]
[[package]]
name = "nvidia-cutlass-dsl-libs-base"
version = "4.4.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "cuda-python", version = "12.9.4", source = { registry = "https://pypi.org/simple" }, marker = "sys_platform == 'linux'" },
@@ -1978,8 +2003,8 @@ dependencies = [
{ name = "typing-extensions" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/78/6c/f45c930f662e0ec7856baa5d4e6f4d1e2ca6b029678f9e05d2df54c865be/nvidia_cutlass_dsl-4.3.5-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:6a79e94d157b16ab34069dd73fb708ff0ef31f486d699b6d5a015217f754cb0b", size = 58739895, upload-time = "2026-01-09T01:38:22.076Z" },
{ url = "https://files.pythonhosted.org/packages/76/cb/998e79b6f028268bf2653250deb4a2edb618db81244e549ced71112c6f85/nvidia_cutlass_dsl-4.3.5-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:4687eef20c405023daa99dd4653a292fd875d6c9486f8d9a069ff6fcdb00834f", size = 58602784, upload-time = "2026-01-09T01:40:52.873Z" },
{ url = "https://files.pythonhosted.org/packages/f5/cd/d09f6c998a9d52372d97d85d6561392d745ca00cf46de956d7cd7ec608cf/nvidia_cutlass_dsl_libs_base-4.4.1-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:74192716b18c1825382723891842f87fa2a045b4b100c5c0f474042731e21e86", size = 75458464, upload-time = "2026-02-27T09:45:01.155Z" },
{ url = "https://files.pythonhosted.org/packages/b4/c1/acca814bc209562ef6cefbdec2ca36520f9a0380cdc7c6feaa69874bb50d/nvidia_cutlass_dsl_libs_base-4.4.1-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:ba5e3d7148f7882911bb3cb453c313c790d1c2096bdfdd2d96da2123cf562201", size = 74347149, upload-time = "2026-02-27T09:45:56.602Z" },
]
[[package]]
@@ -2388,7 +2413,7 @@ requires-dist = [
{ name = "prime", specifier = ">=0.5.37" },
{ name = "pyarrow", specifier = ">=21.0.0" },
{ name = "pydantic", specifier = ">=1.10.13" },
{ name = "pydantic-config", git = "https://github.com/samsja/pydantic_config.git?rev=6990941" },
{ name = "pydantic-config", git = "https://github.com/samsja/pydantic_config.git?branch=main" },
{ name = "pyzmq", specifier = ">=27.1.0" },
{ name = "reverse-text", index = "https://hub.primeintellect.ai/primeintellect/simple/" },
{ name = "rich", specifier = ">=14.0.0" },
@@ -2402,7 +2427,7 @@ requires-dist = [
{ name = "torchtitan", git = "https://github.com/pytorch/torchtitan?rev=a1fdd7e" },
{ name = "transformers", git = "https://github.com/huggingface/transformers.git?rev=609e3d5" },
{ name = "uvloop", specifier = ">=0.21.0" },
{ name = "verifiers", git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=b35d0c7" },
{ name = "verifiers", git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=45fae8d" },
{ name = "vllm", specifier = ">=0.16.0" },
{ name = "wandb", specifier = ">=0.24.2" },
]
@@ -2416,35 +2441,37 @@ dev = [
{ name = "pytest", specifier = ">=8.4.1" },
{ name = "ruff", specifier = ">=0.12.1" },
]
fp8-inference = [{ name = "deep-gemm", url = "https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl" }]
fp8-inference = [{ name = "deep-gemm", url = "https://github.com/hallerite/DeepGEMM/releases/download/v2.3.0-torch2.9/deep_gemm-2.3.0+35c4bc8-cp312-cp312-linux_x86_64.whl" }]
[[package]]
name = "prime-sandboxes"
version = "0.2.14"
version = "0.2.16"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "aiofiles" },
{ name = "connect-python" },
{ name = "httpx" },
{ name = "protobuf" },
{ name = "pydantic" },
{ name = "tenacity" },
]
sdist = { url = "https://files.pythonhosted.org/packages/7c/aa/e6f8e67aa0dc712e84f2c0280cb167e385b6527416405c74a67151e08e2e/prime_sandboxes-0.2.14.tar.gz", hash = "sha256:fbdfc80b1b00e16d2c7448d735f2080b42a51672cd8c6e937b44668348b3d640", size = 47506, upload-time = "2026-02-01T08:24:41.288Z" }
sdist = { url = "https://files.pythonhosted.org/packages/83/58/fdb9a63f1ea0c793da5e08b283c0eb2a3d986a25953126abd0b9bfa9535a/prime_sandboxes-0.2.16.tar.gz", hash = "sha256:c1a4504d7c094427fee436ad1561e12079c1d607003dd0345d4fead34ae873a8", size = 55606, upload-time = "2026-02-28T00:45:49.118Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/69/4c/9289d7e06e9307b0476287234576013703e09e12a76d402b1e827f1b3dd4/prime_sandboxes-0.2.14-py3-none-any.whl", hash = "sha256:9ca2067c0d1e970ee71e2be9f0be53fe0ef6c87c54fcb24ba1ef71374a173d08", size = 20820, upload-time = "2026-02-01T08:24:39.822Z" },
{ url = "https://files.pythonhosted.org/packages/33/7f/b717338c70a785feef5cb1bdaff46a1f942115a40fcd53df3127dea8c2f7/prime_sandboxes-0.2.16-py3-none-any.whl", hash = "sha256:18ef8b2bd073628bdc979b5a17acb640e5c30d19ab7ec356153b51c8fe3b12a2", size = 26639, upload-time = "2026-02-28T00:45:47.891Z" },
]
[[package]]
name = "prime-tunnel"
version = "0.1.2"
version = "0.1.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "httpx" },
{ name = "pydantic" },
{ name = "tenacity" },
]
sdist = { url = "https://files.pythonhosted.org/packages/18/0e/19e74e9962479bea2ab4752b327d448bc0b122ef3043203eb45e5935550b/prime_tunnel-0.1.2.tar.gz", hash = "sha256:e15b67ffb6fbb44e13e764629e178dafb2415c7c23cbd56d63638ad8c530e163", size = 11506, upload-time = "2026-02-12T14:50:38.481Z" }
sdist = { url = "https://files.pythonhosted.org/packages/50/d4/be7356eab434edd623bc000b5c8d457e98b6feb3eed513b88e7865522178/prime_tunnel-0.1.4.tar.gz", hash = "sha256:caf092ae01be921a17824d14aca3b526f8b5b704f9996dbc6cdcefd40619ca8a", size = 11660, upload-time = "2026-02-27T01:32:15.261Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d8/f8/3561a75acddd7c13bf905e435d870bbf70a109b52534ca253195aa0db353/prime_tunnel-0.1.2-py3-none-any.whl", hash = "sha256:2a0e5631d12a3b615a5ba6817cf9755a762cf22a9b6c3ef9d9125a76c7652793", size = 13511, upload-time = "2026-02-12T14:50:37.148Z" },
{ url = "https://files.pythonhosted.org/packages/42/c3/8def582c17f0f64f31efe11f7a0299139af3120c19fb2937a21c63de48d0/prime_tunnel-0.1.4-py3-none-any.whl", hash = "sha256:8e49715fdcdeed2e761c9b96fc7a94f07e6733ba9bf8e4022f8c46f496998a54", size = 13675, upload-time = "2026-02-27T01:32:13.816Z" },
]
[[package]]
@@ -2646,7 +2673,7 @@ email = [
[[package]]
name = "pydantic-config"
version = "0.3.0"
source = { git = "https://github.com/samsja/pydantic_config.git?rev=6990941#699094170fb4ef906bd05b2f3dd811c16278775d" }
source = { git = "https://github.com/samsja/pydantic_config.git?branch=main#204aef7f81719b1ddf7176f844b29dd15c08abea" }
dependencies = [
{ name = "pydantic" },
{ name = "tyro" },
@@ -2745,6 +2772,20 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/bd/24/12818598c362d7f300f18e74db45963dbcb85150324092410c8b49405e42/pyproject_hooks-1.2.0-py3-none-any.whl", hash = "sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913", size = 10216, upload-time = "2024-09-29T09:24:11.978Z" },
]
[[package]]
name = "pyqwest"
version = "0.3.3"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/37/d5/37c968f2ad6a1e6d443215063a9fcc109999f796aaf697806ea1ccf562af/pyqwest-0.3.3.tar.gz", hash = "sha256:473a9ede8a96d1d993a1628eb62edd056a3c57b74e65cfd30d72eb451be1a23d", size = 423176, upload-time = "2026-01-21T12:54:44.453Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/7c/22/1a124da1eb328bcd38b207afce037b8322c03848d53ad372a44f90bcb7a9/pyqwest-0.3.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4666516358c2349a3c1f1f00816b27df6cc127b0d75cdd5d07bf4498c407ba4f", size = 4910119, upload-time = "2026-01-21T12:53:45.153Z" },
{ url = "https://files.pythonhosted.org/packages/90/05/35c546933d6765c9f38841ee703a299cd08d115e8f9df5a882669775b07d/pyqwest-0.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b802af427c9e4ed33c5a6ed47612887dce1128ba3cf685c7a26a383d9412c811", size = 5267540, upload-time = "2026-01-21T12:53:46.707Z" },
{ url = "https://files.pythonhosted.org/packages/f9/a6/97990418194cd24640486a14f6cb390d9f7005bc1aa06fe2324ef0aa8050/pyqwest-0.3.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81118f530429b10eb295ae5b9b1353593e17ad15e0166203d2dfca51b763db85", size = 5309338, upload-time = "2026-01-21T12:53:48.903Z" },
{ url = "https://files.pythonhosted.org/packages/70/12/1e503ba23b8cfe008178610ee649e4ec6536a4d98bce9786287ae82ebb33/pyqwest-0.3.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:420e26aed443f6beb8a10fe5eb06913084be48e549b537b0a8887088358ed354", size = 5455416, upload-time = "2026-01-21T12:53:50.466Z" },
{ url = "https://files.pythonhosted.org/packages/70/9f/d39e0ba8fa4396f9a68ad60e2544f76d79688e93f5bb6be777f6070435e8/pyqwest-0.3.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:f596adcd385d2125c8c715e6c107068139d36b5ebcb14709e1ed2f98423e624e", size = 5613290, upload-time = "2026-01-21T12:53:52.428Z" },
{ url = "https://files.pythonhosted.org/packages/c4/ea/9fe5998f570978925102f0302107562c285e658a03587f7b7c04e51456b1/pyqwest-0.3.3-cp312-cp312-win_amd64.whl", hash = "sha256:66f1d9b0338592949bb53e76361f15b869a9aeca9503e00d6c46d648d609c0be", size = 4524367, upload-time = "2026-01-21T12:53:54.112Z" },
]
[[package]]
name = "pytest"
version = "8.4.2"
@@ -3752,8 +3793,8 @@ wheels = [
[[package]]
name = "verifiers"
version = "0.1.11.dev0"
source = { git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=b35d0c7#b35d0c7e464d67ea8cc8fccaaec0903cd5fd7b32" }
version = "0.1.11.dev1"
source = { git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=45fae8d#45fae8dd7b44043672cc27ee75c0a2741f2d1b97" }
dependencies = [
{ name = "anthropic" },
{ name = "datasets" },