Compare commits

...
Author SHA1 Message Date
66b1f4b6b7 configure default logger instead of raise (#1804)
Release / Push CUDA image to Docker (push) Canceled after 0s
* configure default logger instead of raise

* fix: cleanup old logger resources when calling setup_logger

Calling setup_logger multiple times now properly cleans up the old
logger instance by calling logger.remove() before creating a new one.
This prevents resource leaks:
- Background threads from enqueue=True handlers are stopped
- JsonFileSink file handles are properly released

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

* fix: add cleanup to reset_logger to prevent resource leaks

Calling reset_logger now properly cleans up the logger instance by
calling logger.remove() before setting _LOGGER to None. This ensures
that any active handlers (file sinks, enqueued handlers, background
threads) are properly released, matching the cleanup pattern in
setup_logger.

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

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-16 09:52:47 -08:00
bb5e48292d fix: upgrade flash-attn from 2.6.3 to 2.8.3 (#1803)
Release / Push CUDA image to Docker (push) Canceled after 0s
The downgrade from 2.8.3 to 2.6.3 happened during the vllm/transformers
bump (commit 8f2e6bbc) when PyTorch was upgraded from 2.9 to 2.10.

Flash-attn 2.6.3 does not support Blackwell GPUs (compute capability 12.0),
causing "FlashAttention only supports Ampere GPUs or newer" errors.

This upgrades back to 2.8.3 which may have better compatibility with newer
GPU architectures. The 2.8.3 wheel for torch 2.10 + cu128 is available in
the same v0.7.16 release.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-16 07:53:46 -08:00
187b7a438c fix env server deadlock (#1801)
Release / Push CUDA image to Docker (push) Canceled after 0s
* fix(deps): bump verifiers to e629347 (ZMQ env server deadlock fix)

The ZMQ env server used asyncio.wait_for around recv_multipart which
has a race condition in CPython's Task cancellation that silently
discards consumed messages. The verifiers fix replaces it with a
zmq.asyncio.Poller.

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

* use spawn method

* bump to commit on main

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 05:06:00 -08:00
faresobeidandGitHub 1b725b84b8 track prefill vs decode tokens (#1797)
Release / Push CUDA image to Docker (push) Canceled after 0s
* track prefill vs decode tokens

* fix ruff
2026-02-16 00:47:04 +00:00
5 changed files with 54 additions and 40 deletions
+2 -2
View File
@@ -45,7 +45,7 @@ sft = "prime_rl.trainer.sft.train:main"
[project.optional-dependencies]
flash-attn = [
"flash-attn @ https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.6.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl",
"flash-attn @ https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.8.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl",
]
flash-attn-3 = [
"flash_attn_3 @ https://github.com/samsja/flash-attn-builds/releases/download/v0.1/flash_attn_3-3.0.0b1-cp39-abi3-linux_x86_64.whl",
@@ -77,7 +77,7 @@ override-dependencies = [
[tool.uv.sources]
torch = { index = "pytorch-cu128" }
verifiers = { git = "https://github.com/PrimeIntellect-ai/verifiers.git", rev = "786d300" }
verifiers = { git = "https://github.com/PrimeIntellect-ai/verifiers.git", rev = "ad77074" }
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" }
+25 -10
View File
@@ -41,7 +41,6 @@ from prime_rl.orchestrator.utils import (
from prime_rl.orchestrator.vf_utils import (
generate,
get_completion_len,
get_prompt_len,
get_seq_len,
setup_env_client,
spawn_env_server,
@@ -473,12 +472,26 @@ async def orchestrate(config: OrchestratorConfig):
# Collect results and assign advantages
train_examples: list[TrainingSample] = []
rollout_prefill_lens: list[int] = []
rollout_decode_lens: list[int] = []
num_prefill_tokens = 0
num_decode_tokens = 0
for rollout, advantage, samples in zip(train_rollouts, advantages, results):
rollout_prefill_tokens = 0
rollout_decode_tokens = 0
if samples is not None:
for sample in samples:
sample.advantage = advantage
sample.reward = rollout["reward"]
train_examples.extend(samples)
sample_decode_tokens = sum(sample.completion_mask)
sample_prefill_tokens = len(sample.prompt_ids) + len(sample.completion_mask) - sample_decode_tokens
rollout_decode_tokens += sample_decode_tokens
rollout_prefill_tokens += sample_prefill_tokens
train_examples.append(sample)
rollout_prefill_lens.append(rollout_prefill_tokens)
rollout_decode_lens.append(rollout_decode_tokens)
num_prefill_tokens += rollout_prefill_tokens
num_decode_tokens += rollout_decode_tokens
parallel_preprocess_time = time.perf_counter() - parallel_preprocess_start
logger.debug(
@@ -539,9 +552,9 @@ async def orchestrate(config: OrchestratorConfig):
"reward": [rollout["reward"] for rollout in train_rollouts],
"is_truncated": [rollout["is_truncated"] for rollout in train_rollouts],
"error": [rollout["error"] for rollout in train_rollouts],
"completion_len": [get_completion_len(rollout) for rollout in train_rollouts],
"prompt_len": [get_prompt_len(rollout) for rollout in train_rollouts],
"seq_len": [get_seq_len(rollout) for rollout in train_rollouts],
"prefill_len": rollout_prefill_lens,
"decode_len": rollout_decode_lens,
"num_turns": [len(rollout["trajectory"]) for rollout in train_rollouts],
"generation_ms": [rollout["timing"]["generation_ms"] for rollout in train_rollouts],
"scoring_ms": [rollout["timing"]["scoring_ms"] for rollout in train_rollouts],
@@ -598,6 +611,8 @@ async def orchestrate(config: OrchestratorConfig):
to_log = {
# Progress metrics
"progress/tokens": num_tokens,
"progress/prefill_tokens": num_prefill_tokens,
"progress/decode_tokens": num_decode_tokens,
"progress/samples": config.batch_size,
"progress/problems": config.batch_size // config.rollouts_per_example,
"progress/total_tokens": progress.total_tokens,
@@ -608,12 +623,12 @@ async def orchestrate(config: OrchestratorConfig):
"seq_len/mean": results_df.groupby("example_id").seq_len.mean().mean(),
"seq_len/max": results_df.groupby("example_id").seq_len.mean().max(),
"seq_len/min": results_df.groupby("example_id").seq_len.mean().min(),
"prompt_len/mean": results_df.groupby("example_id").prompt_len.mean().mean(),
"prompt_len/max": results_df.groupby("example_id").prompt_len.mean().max(),
"prompt_len/min": results_df.groupby("example_id").prompt_len.mean().min(),
"completion_len/mean": results_df.groupby("example_id").completion_len.mean().mean(),
"completion_len/max": results_df.groupby("example_id").completion_len.mean().max(),
"completion_len/min": results_df.groupby("example_id").completion_len.mean().min(),
"prefill_len/mean": results_df.groupby("example_id").prefill_len.mean().mean(),
"prefill_len/max": results_df.groupby("example_id").prefill_len.mean().max(),
"prefill_len/min": results_df.groupby("example_id").prefill_len.mean().min(),
"decode_len/mean": results_df.groupby("example_id").decode_len.mean().mean(),
"decode_len/max": results_df.groupby("example_id").decode_len.mean().max(),
"decode_len/min": results_df.groupby("example_id").decode_len.mean().min(),
"is_truncated/mean": results_df.groupby("example_id").is_truncated.mean().mean(),
"is_truncated/max": results_df.groupby("example_id").is_truncated.mean().max(),
"is_truncated/min": results_df.groupby("example_id").is_truncated.mean().min(),
+5 -2
View File
@@ -1,8 +1,8 @@
import asyncio
import logging
import multiprocessing as mp
from collections.abc import Awaitable, Callable
from itertools import cycle
from multiprocessing import Process
from typing import Any
import verifiers as vf
@@ -33,7 +33,10 @@ def spawn_env_server(
Mirrors vf.Environment.start_server().
"""
address = address or f"tcp://127.0.0.1:{get_free_port()}"
Process(
# Use spawn to avoid inheriting file descriptors (e.g. sockets) from
# the parent process, which has caused hangs when multiple env server
# subprocesses share the same fds.
mp.get_context("spawn").Process(
target=ZMQEnvServer.run_server,
args=(
env_id,
+16 -20
View File
@@ -14,7 +14,7 @@ NO_BOLD = "\033[22m"
RESET = "\033[0m"
def _build_log_entry(record) -> dict:
def build_log_entry(record) -> dict:
"""Build a flat JSON log entry from a loguru record."""
extra = record["extra"]
@@ -54,14 +54,14 @@ def _build_log_entry(record) -> dict:
return log_entry
def _json_sink(message) -> None:
def json_sink(message) -> None:
"""Sink that outputs flat JSON to stdout for log aggregation (Loki, Grafana, etc.)."""
log_entry = _build_log_entry(message.record)
log_entry = build_log_entry(message.record)
sys.stdout.write(json_module.dumps(log_entry) + "\n")
sys.stdout.flush()
class _JsonFileSink:
class JsonFileSink:
"""File sink that keeps the handle open and writes flat JSON lines."""
def __init__(self, log_file: Path):
@@ -74,7 +74,7 @@ class _JsonFileSink:
self._file.close()
def write(self, message) -> None:
log_entry = _build_log_entry(message.record)
log_entry = build_log_entry(message.record)
self._file.write(json_module.dumps(log_entry) + "\n")
self._file.flush()
@@ -102,17 +102,19 @@ class InterceptHandler(logging.Handler):
def setup_logger(
log_level: str,
log_level: str = "info",
log_file: Path | None = None,
append: bool = False,
tag: str | None = None,
json_logging: bool = False,
):
global _LOGGER, _JSON_LOGGING
if _LOGGER is not None:
raise RuntimeError("Logger already set. Please call `setup_logger` only once.")
_JSON_LOGGING = json_logging
# Clean up old logger instance to prevent resource leaks
if _LOGGER is not None:
_LOGGER.remove()
# Format message with optional tag prefix
tag_prefix = f"[{tag}] " if tag else ""
message = "".join(
@@ -154,7 +156,7 @@ def setup_logger(
# Install console handler (enqueue=True only for JSON mode to avoid blocking in async contexts)
if json_logging:
logger.add(_json_sink, level=log_level.upper(), enqueue=True)
logger.add(json_sink, level=log_level.upper(), enqueue=True)
else:
logger.add(sys.stdout, format=format, level=log_level.upper(), colorize=True)
@@ -163,7 +165,7 @@ def setup_logger(
if not append and log_file.exists():
log_file.unlink()
if json_logging:
file_sink = _JsonFileSink(log_file)
file_sink = JsonFileSink(log_file)
logger.add(file_sink.write, level=log_level.upper(), enqueue=True)
else:
logger.add(log_file, format=format, level=log_level.upper(), colorize=True)
@@ -178,23 +180,17 @@ def setup_logger(
def get_logger():
"""
Get the global logger. This function is shared across submodules such as
training and inference to access the global logger instance. Raises if the
logger has not been set.
Returns:
The global logger.
"""
global _LOGGER
if _LOGGER is None:
raise RuntimeError("Logger not set. Please call `set_logger` first.")
_LOGGER = setup_logger()
return _LOGGER
def reset_logger():
"""Reset the global logger. Useful mainly in test to clear loggers between tests."""
"""Reset the logger. Useful mainly in tests."""
global _LOGGER, _JSON_LOGGING
if _LOGGER is not None:
_LOGGER.remove()
_LOGGER = None
_JSON_LOGGING = False
Generated
+6 -6
View File
@@ -755,14 +755,14 @@ wheels = [
[[package]]
name = "flash-attn"
version = "2.6.3+cu128torch2.10"
source = { url = "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.6.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl" }
version = "2.8.3+cu128torch2.10"
source = { url = "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.8.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl" }
dependencies = [
{ name = "einops" },
{ name = "torch" },
]
wheels = [
{ url = "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.6.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl", hash = "sha256:e883225b48075ea57790527ae3f653421a58c25d207375d00a1dfa9221b5bd43" },
{ url = "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.8.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl", hash = "sha256:5ef676dfd01d198eed36795d924eb6af4c87674896de6bd102390afa7f522bc0" },
]
[package.metadata]
@@ -2334,7 +2334,7 @@ requires-dist = [
{ name = "beartype", specifier = ">=0.21.0" },
{ name = "datasets", specifier = ">=4.0.0" },
{ name = "dion", git = "https://github.com/samsja/dion.git?rev=d891eeb" },
{ name = "flash-attn", marker = "extra == 'flash-attn'", url = "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.6.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl" },
{ name = "flash-attn", marker = "extra == 'flash-attn'", url = "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.16/flash_attn-2.8.3%2Bcu128torch2.10-cp312-cp312-linux_x86_64.whl" },
{ name = "flash-attn-3", marker = "extra == 'flash-attn-3'", url = "https://github.com/samsja/flash-attn-builds/releases/download/v0.1/flash_attn_3-3.0.0b1-cp39-abi3-linux_x86_64.whl" },
{ name = "flash-attn-cute", marker = "extra == 'flash-attn-cute'", git = "https://github.com/Dao-AILab/flash-attention.git?subdirectory=flash_attn%2Fcute&rev=main" },
{ name = "jaxtyping", specifier = ">=0.3.2" },
@@ -2358,7 +2358,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=786d300" },
{ name = "verifiers", git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=ad77074" },
{ name = "vllm", url = "https://github.com/vllm-project/vllm/releases/download/v0.16.0/vllm-0.16.0-cp38-abi3-manylinux_2_31_x86_64.whl" },
{ name = "wandb", specifier = ">=0.24.2" },
]
@@ -3687,7 +3687,7 @@ wheels = [
[[package]]
name = "verifiers"
version = "0.1.11.dev0"
source = { git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=786d300#786d300bf5aab105279fc542dda838beafcb025e" }
source = { git = "https://github.com/PrimeIntellect-ai/verifiers.git?rev=ad77074#ad77074e6e8585242425aabd598fc102584a0777" }
dependencies = [
{ name = "anthropic" },
{ name = "datasets" },