Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8da21f16b8 | ||
|
|
ae37b35a34 | ||
|
|
77788ba020 | ||
|
|
ab85b3b369 | ||
|
|
de5cdb8bae |
@@ -137,6 +137,10 @@ RUN --mount=type=cache,target=/usr/local/share/uv/cache \
|
||||
&& \
|
||||
/app/.venv/bin/python -c 'from importlib.metadata import version; [version(name) for name in ("deep-ep", "deep-gemm", "mamba-ssm", "nixl", "prime-kernels", "quack-kernels", "vllm", "vllm-router")]'
|
||||
|
||||
# Needed for private environments hub auth
|
||||
RUN --mount=type=cache,target=/usr/local/share/uv/cache \
|
||||
VIRTUAL_ENV=/app/.venv uv pip install 'prime>=0.7'
|
||||
|
||||
# Optional: build NIXL from source against the UCX 1.19 baked above. The PyPI
|
||||
# nixl wheel ships its own UCX which segfaults on prefill→decode KV transfer
|
||||
# (#2883); rebuilding against our UCX is the documented fix. Only needed for
|
||||
|
||||
Vendored
+1
-1
Submodule deps/verifiers updated: ceecc4d422...c000747821
@@ -21,6 +21,11 @@ class ServedEvalConfig(EvalSourcesConfig):
|
||||
"""Adaptive in-flight episode concurrency, sized by the same controller as
|
||||
``[orchestrator.concurrency]``. Set ``min_inflight = max_inflight`` to pin it."""
|
||||
|
||||
tasks_per_minute: int | None = Field(None, ge=1)
|
||||
"""Global rate limit on episode dispatch, in tasks per minute. Use it for
|
||||
sandbox-backed environments to pace provisioning during autoscaling. None disables
|
||||
rate limiting."""
|
||||
|
||||
@property
|
||||
def env_addresses(self) -> dict[tuple[str, str], str | None]:
|
||||
"""Where each eval source's env server lives, keyed by ``("eval", resolved_name)``.
|
||||
|
||||
@@ -114,7 +114,7 @@ class EvalRunner:
|
||||
progress=None,
|
||||
initial_max_inflight=self.concurrency.max_inflight,
|
||||
max_inflight_ceiling=config.concurrency.max_inflight,
|
||||
tasks_per_minute=None,
|
||||
tasks_per_minute=config.tasks_per_minute,
|
||||
max_off_policy_steps=0,
|
||||
run_id=self.run_id,
|
||||
run_name=self.run_name,
|
||||
|
||||
@@ -50,7 +50,9 @@ def summarize_episode(line: int, rec: dict, offset: int | None = None) -> dict:
|
||||
``line`` numbers the episode within the stream from 1, so the last of n reads as
|
||||
n — it is what a reader sees and what addresses the episode."""
|
||||
rewards, advantages = [], []
|
||||
input_tokens = output_tokens = turns = branches = 0
|
||||
input_tokens = rec.get("num_input_tokens")
|
||||
output_tokens = rec.get("num_output_tokens")
|
||||
turns = branches = 0
|
||||
stop_condition = None
|
||||
truncated = False
|
||||
reward_parts: dict[str, list[float]] = {}
|
||||
@@ -86,20 +88,10 @@ def summarize_episode(line: int, rec: dict, offset: int | None = None) -> dict:
|
||||
if advantage is not None:
|
||||
advantages.append(advantage)
|
||||
for node in nodes:
|
||||
n_tokens = len(node.get("token_ids") or [])
|
||||
if node.get("sampled"):
|
||||
output_tokens += n_tokens
|
||||
else:
|
||||
input_tokens += n_tokens
|
||||
if (node.get("message") or {}).get("role") == "assistant":
|
||||
turns += 1
|
||||
stop_condition = trace.get("stop_condition", stop_condition)
|
||||
truncated = truncated or trace_truncated(trace)
|
||||
if input_tokens == 0 and output_tokens == 0: # some eval traces carry no token arrays
|
||||
for call in trace.get("calls") or []:
|
||||
usage = call.get("usage") or {}
|
||||
input_tokens += usage.get("prompt_tokens") or 0
|
||||
output_tokens += usage.get("completion_tokens") or 0
|
||||
first_info = ((rec.get("traces") or [{}])[0].get("info")) or {}
|
||||
return {
|
||||
"rewards": {name: sum(v) / len(v) for name, v in reward_parts.items()},
|
||||
|
||||
@@ -176,31 +176,31 @@ def message_text(message: dict[str, Any]) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def trace_row(trace: dict[str, Any]) -> dict[str, Any]:
|
||||
def trace_row(record: dict[str, Any]) -> dict[str, Any]:
|
||||
"""The live table's view of one trace: phase, turns, tokens, cost, last message."""
|
||||
calls = trace.get("calls") or []
|
||||
calls = record.get("calls") or []
|
||||
usage = [call.get("usage") or {} for call in calls]
|
||||
# The newest node is usually a tool result; the assistant's latest words say more.
|
||||
last = ""
|
||||
for node in reversed(trace.get("nodes") or []):
|
||||
for node in reversed(record.get("nodes") or []):
|
||||
message = node.get("message") or {}
|
||||
if message.get("role") == "assistant" and (last := " ".join(message_text(message).split())):
|
||||
break
|
||||
costs = [u["cost"] for u in usage if u.get("cost") is not None]
|
||||
nodes = trace.get("nodes") or []
|
||||
nodes = record.get("nodes") or []
|
||||
parents = {node.get("parent") for node in nodes if node.get("parent") is not None}
|
||||
return {
|
||||
"trace": trace.get("id"),
|
||||
"agent": (trace.get("agent") or {}).get("name", "agent"),
|
||||
"stage": stage(trace),
|
||||
"trace": record.get("id"),
|
||||
"agent": (record.get("agent") or {}).get("name", "agent"),
|
||||
"stage": stage(record),
|
||||
"turns": len(calls),
|
||||
"branches": sum(1 for index in range(len(nodes)) if index not in parents),
|
||||
"input_tokens": sum(u.get("prompt_tokens") or 0 for u in usage),
|
||||
"output_tokens": sum(u.get("completion_tokens") or 0 for u in usage),
|
||||
"input_tokens": record.get("num_input_tokens"),
|
||||
"output_tokens": record.get("num_output_tokens"),
|
||||
"cost": sum(costs) if costs else None,
|
||||
"stop_condition": trace.get("stop_condition"),
|
||||
"errors": len(trace.get("errors") or []),
|
||||
"pending": len(trace.get("pending") or []),
|
||||
"stop_condition": record.get("stop_condition"),
|
||||
"errors": len(record.get("errors") or []),
|
||||
"pending": len(record.get("pending") or []),
|
||||
"last": last[:SNIPPET_CHARS],
|
||||
}
|
||||
|
||||
|
||||
@@ -520,6 +520,8 @@ def setup_fsdp(model: nn.Module, config: ModelConfig, parallel_dims: ParallelDim
|
||||
reshard_after_forward=config.reshard_after_forward,
|
||||
shard_placement_fn=shard_placement_fn,
|
||||
)
|
||||
# Keep the router reduction from waiting for the expert reduction's input buffer.
|
||||
block_mlp.router.set_reduce_scatter_max_input_buffers(2)
|
||||
|
||||
fully_shard(
|
||||
transformer_block,
|
||||
|
||||
@@ -6,7 +6,8 @@ import torch
|
||||
import triton
|
||||
import triton.language as tl
|
||||
|
||||
FP8_MAX = 448.0
|
||||
FP8_MAX = tl.constexpr(448.0)
|
||||
FP8_MIN = tl.constexpr(-448.0)
|
||||
MIN_SCALE = 1e-4
|
||||
GROUP_ALIGNMENT = 128
|
||||
|
||||
@@ -188,11 +189,11 @@ def _per_token_fp8_kernel(
|
||||
mask=mask,
|
||||
other=0.0,
|
||||
).to(tl.float32)
|
||||
amax = tl.max(tl.abs(x), axis=1)
|
||||
scale = tl.maximum(amax / 448.0, 1e-4)
|
||||
amax = tl.maximum(tl.max(tl.abs(x), axis=1), 1e-10)
|
||||
scale = tl.math.div_rn(amax, FP8_MAX)
|
||||
if USE_UE8M0:
|
||||
scale = tl.exp2(tl.ceil(tl.log2(scale)))
|
||||
y = x / scale[:, None]
|
||||
y = tl.clamp(tl.math.div_rn(x, scale[:, None]), FP8_MIN, FP8_MAX)
|
||||
tl.store(
|
||||
out_ptr + row_offsets_i64[:, None] * stride_ym + col_offsets_i64[None, :] * stride_yn,
|
||||
y.to(tl.float8e4nv),
|
||||
@@ -242,11 +243,11 @@ def _grouped_per_token_fp8_kernel(
|
||||
mask=valid_rows[:, None] & valid_cols[None, :],
|
||||
other=0.0,
|
||||
).to(tl.float32)
|
||||
amax = tl.max(tl.abs(x), axis=1)
|
||||
scale = tl.maximum(amax / 448.0, 1e-4)
|
||||
amax = tl.maximum(tl.max(tl.abs(x), axis=1), 1e-10)
|
||||
scale = tl.math.div_rn(amax, FP8_MAX)
|
||||
if USE_UE8M0:
|
||||
scale = tl.exp2(tl.ceil(tl.log2(scale)))
|
||||
y = x / scale[:, None]
|
||||
y = tl.clamp(tl.math.div_rn(x, scale[:, None]), FP8_MIN, FP8_MAX)
|
||||
tl.store(
|
||||
out_ptr + dst_rows_i64[:, None] * stride_ym + col_offsets_i64[None, :] * stride_yn,
|
||||
y.to(tl.float8e4nv),
|
||||
@@ -295,11 +296,11 @@ def _grouped_per_channel_fp8_kernel(
|
||||
mask=valid_rows[:, None] & valid_cols[None, :],
|
||||
other=0.0,
|
||||
).to(tl.float32)
|
||||
amax = tl.max(tl.abs(x), axis=0)
|
||||
scale = tl.maximum(amax / 448.0, 1e-4)
|
||||
amax = tl.maximum(tl.max(tl.abs(x), axis=0), 1e-10)
|
||||
scale = tl.math.div_rn(amax, FP8_MAX)
|
||||
if USE_UE8M0:
|
||||
scale = tl.exp2(tl.ceil(tl.log2(scale)))
|
||||
y = x / scale[None, :]
|
||||
y = tl.clamp(tl.math.div_rn(x, scale[None, :]), FP8_MIN, FP8_MAX)
|
||||
flat_base = block_start.to(tl.int64) * BLOCK_K * cols
|
||||
if K_MAJOR:
|
||||
out_ptrs = out_ptr + flat_base + col_offsets_i64[:, None] * aligned_m + row_offsets_i64[None, :]
|
||||
@@ -355,7 +356,7 @@ def _grouped_per_block_fp8_kernel(
|
||||
other=0.0,
|
||||
).to(tl.float32)
|
||||
amax = tl.max(tl.abs(x))
|
||||
scale = tl.maximum(amax / 448.0, 1e-4)
|
||||
scale = tl.maximum(amax / FP8_MAX, 1e-4)
|
||||
if USE_UE8M0:
|
||||
scale = tl.exp2(tl.ceil(tl.log2(scale)))
|
||||
y = x / scale
|
||||
@@ -426,7 +427,7 @@ def per_token_cast_to_fp8_triton(
|
||||
sf.stride(0),
|
||||
sf.stride(1),
|
||||
USE_UE8M0=use_ue8m0,
|
||||
BLOCK_M=8,
|
||||
BLOCK_M=32,
|
||||
BLOCK_K=gran_k,
|
||||
num_warps=4,
|
||||
)
|
||||
@@ -453,7 +454,7 @@ def grouped_per_token_cast_to_fp8_triton(
|
||||
)
|
||||
if block_to_group.numel() == 0:
|
||||
return out, sf
|
||||
grid = (block_to_group.numel(), GROUP_ALIGNMENT // 8, ceil_div(x.size(1), gran_k))
|
||||
grid = (block_to_group.numel(), GROUP_ALIGNMENT // 32, ceil_div(x.size(1), gran_k))
|
||||
_grouped_per_token_fp8_kernel[grid](
|
||||
x,
|
||||
block_to_group,
|
||||
@@ -470,7 +471,7 @@ def grouped_per_token_cast_to_fp8_triton(
|
||||
sf.stride(0),
|
||||
sf.stride(1),
|
||||
USE_UE8M0=use_ue8m0,
|
||||
BLOCK_M=8,
|
||||
BLOCK_M=32,
|
||||
BLOCK_K=gran_k,
|
||||
GROUP_BLOCK_M=GROUP_ALIGNMENT,
|
||||
num_warps=4,
|
||||
@@ -496,7 +497,8 @@ def grouped_per_channel_cast_to_fp8_sm90_kmajor_triton(
|
||||
sf = torch.empty((total_blocks, x.size(1)), device=x.device, dtype=torch.float32)
|
||||
if block_to_group.numel() == 0:
|
||||
return out, sf.T
|
||||
grid = (block_to_group.numel(), ceil_div(x.size(1), 128))
|
||||
block_n = 16
|
||||
grid = (block_to_group.numel(), ceil_div(x.size(1), block_n))
|
||||
_grouped_per_channel_fp8_kernel[grid](
|
||||
x,
|
||||
block_to_group,
|
||||
@@ -514,8 +516,8 @@ def grouped_per_channel_cast_to_fp8_sm90_kmajor_triton(
|
||||
USE_UE8M0=use_ue8m0,
|
||||
K_MAJOR=True,
|
||||
BLOCK_K=gran_k,
|
||||
BLOCK_N=128,
|
||||
num_warps=4,
|
||||
BLOCK_N=block_n,
|
||||
num_warps=2,
|
||||
)
|
||||
return out, sf.T
|
||||
|
||||
@@ -538,7 +540,8 @@ def grouped_per_channel_cast_to_fp8_rowmajor_triton(
|
||||
sf = torch.empty((total_blocks, x.size(1)), device=x.device, dtype=torch.float32)
|
||||
if block_to_group.numel() == 0:
|
||||
return out, sf
|
||||
grid = (block_to_group.numel(), ceil_div(x.size(1), 128))
|
||||
block_n = 64
|
||||
grid = (block_to_group.numel(), ceil_div(x.size(1), block_n))
|
||||
_grouped_per_channel_fp8_kernel[grid](
|
||||
x,
|
||||
block_to_group,
|
||||
@@ -556,7 +559,7 @@ def grouped_per_channel_cast_to_fp8_rowmajor_triton(
|
||||
USE_UE8M0=use_ue8m0,
|
||||
K_MAJOR=False,
|
||||
BLOCK_K=gran_k,
|
||||
BLOCK_N=128,
|
||||
BLOCK_N=block_n,
|
||||
num_warps=4,
|
||||
)
|
||||
return out, sf
|
||||
@@ -672,7 +675,7 @@ def per_token_cast_to_fp8_tp_triton(
|
||||
sf.stride(0),
|
||||
sf.stride(1),
|
||||
USE_UE8M0=use_ue8m0,
|
||||
BLOCK_M=8,
|
||||
BLOCK_M=32,
|
||||
BLOCK_K=gran_k,
|
||||
num_warps=4,
|
||||
)
|
||||
|
||||
@@ -47,3 +47,25 @@ def test_token_tp_cast_matches_materialized_transpose(rows, cols):
|
||||
assert tp_q.is_contiguous()
|
||||
assert torch.equal(tp_q.view(torch.uint8), ref_q.view(torch.uint8))
|
||||
assert torch.equal(tp_s, ref_s)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"rows,cols,input_scale",
|
||||
[(256, 256, 1.0), (256, 512, 0.3), (512, 256, 0.02), (1024, 768, 0.02), (384, 128, 0.005)],
|
||||
)
|
||||
def test_token_cast_matches_vllm_cuda_quant(rows, cols, input_scale):
|
||||
"""The per-token cast is *bit-identical* to vLLM's production CUDA quantizer."""
|
||||
pytest.importorskip("vllm")
|
||||
from vllm.model_executor.layers.quantization.utils.fp8_utils import per_token_group_quant_fp8
|
||||
|
||||
torch.manual_seed(rows + cols)
|
||||
x = torch.randn(rows, cols, device="cuda", dtype=torch.bfloat16) * input_scale
|
||||
assert x.is_contiguous()
|
||||
|
||||
ref_q, ref_s = per_token_group_quant_fp8(x, 128, use_ue8m0=False)
|
||||
q, s = per_token_cast_to_fp8_triton(x, False)
|
||||
|
||||
assert q.shape == ref_q.shape == (rows, cols)
|
||||
assert s.shape == ref_s.shape == (rows, cols // 128)
|
||||
assert torch.equal(s, ref_s)
|
||||
assert torch.equal(q.view(torch.uint8), ref_q.view(torch.uint8))
|
||||
|
||||
Reference in New Issue
Block a user