Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3925d27f4f | ||
|
|
7a630865ca | ||
|
|
bbbe9cb1bf | ||
|
|
6afa65111a | ||
|
|
dd72f0f97c |
@@ -29,7 +29,7 @@ class ServerConfig(BaseConfig):
|
||||
# not depend on vLLM, and importing it costs seconds in every config-parsing process.
|
||||
VALID_VLLM_LORA_RANKS = (8, 16, 32, 64, 128, 256, 320, 512)
|
||||
|
||||
QuantizationType = Literal["fp8_per_block"]
|
||||
QuantizationType = Literal["fp8_per_block", "mxfp8"]
|
||||
|
||||
|
||||
class VllmConfig(BaseConfig):
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "prime-rl"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
description = "Async RL Training at Scale"
|
||||
readme = "README.md"
|
||||
requires-python = "~=3.12.0"
|
||||
|
||||
@@ -14,6 +14,7 @@ def apply_shared_vllm_patches():
|
||||
|
||||
patch_gpt_oss_weight_loading()
|
||||
patch_qwen38_weight_loading()
|
||||
monkey_patch_shm_buffer_ownership()
|
||||
_patch_lora_key_prefix()
|
||||
_patch_qwen35_moe_lora_format()
|
||||
monkey_patch_nano_v3_reasoning_parser()
|
||||
@@ -32,6 +33,65 @@ def apply_shared_vllm_patches():
|
||||
monkey_patch_deepseek_v4_attn_sink_loading()
|
||||
|
||||
|
||||
def monkey_patch_shm_buffer_ownership():
|
||||
"""Own out-of-band buffers before releasing a reusable vLLM SHM slot."""
|
||||
import pickle
|
||||
|
||||
import zmq
|
||||
from vllm.distributed.device_communicators import shm_broadcast
|
||||
|
||||
# Backport https://github.com/vllm-project/vllm/pull/61000; remove when our
|
||||
# minimum vLLM version includes it. Retained routed-expert arrays otherwise
|
||||
# alias ring slots that subsequent messages can overwrite.
|
||||
MessageQueue = shm_broadcast.MessageQueue
|
||||
if getattr(MessageQueue.dequeue, "_prime_rl_owns_shm_buffers", False):
|
||||
return
|
||||
|
||||
def dequeue(self, timeout: float | None = None, indefinite: bool = False):
|
||||
if self._is_local_reader:
|
||||
with self.acquire_read(timeout, indefinite) as buf:
|
||||
overflow = buf[0] == 1
|
||||
if not overflow:
|
||||
offset = 3
|
||||
buf_count = shm_broadcast.from_bytes_big(buf[1:offset])
|
||||
all_buffers = []
|
||||
for i in range(buf_count):
|
||||
buf_offset = offset + 4
|
||||
buf_len = shm_broadcast.from_bytes_big(buf[offset:buf_offset])
|
||||
offset = buf_offset + buf_len
|
||||
buffer = buf[buf_offset:offset]
|
||||
all_buffers.append(buffer if i == 0 else bytearray(buffer))
|
||||
obj = pickle.loads(all_buffers[0], buffers=all_buffers[1:])
|
||||
if overflow:
|
||||
obj = MessageQueue.recv(self.local_socket, timeout)
|
||||
elif self._is_remote_reader:
|
||||
obj = MessageQueue.recv(self.remote_socket, timeout)
|
||||
else:
|
||||
raise RuntimeError("Only readers can dequeue")
|
||||
return obj
|
||||
|
||||
def _rebuild_tensor(buf, shape: tuple[int, ...], dtype_str: str) -> torch.Tensor:
|
||||
dtype = getattr(torch, dtype_str)
|
||||
assert isinstance(dtype, torch.dtype)
|
||||
if isinstance(buf, zmq.Frame):
|
||||
try:
|
||||
return torch.frombuffer(buf, dtype=torch.uint8).view(dtype).view(shape)
|
||||
except ValueError:
|
||||
pass
|
||||
raw = buf if isinstance(buf, bytearray) else bytearray(buf)
|
||||
if not raw:
|
||||
assert 0 in shape
|
||||
return torch.empty(shape, dtype=dtype)
|
||||
return torch.frombuffer(raw, dtype=torch.uint8).view(dtype).view(shape)
|
||||
|
||||
# Pickle resolves this reducer by its module and name in receiving processes.
|
||||
_rebuild_tensor.__module__ = shm_broadcast.__name__
|
||||
_rebuild_tensor.__qualname__ = "_rebuild_tensor"
|
||||
dequeue._prime_rl_owns_shm_buffers = True
|
||||
shm_broadcast._rebuild_tensor = _rebuild_tensor
|
||||
MessageQueue.dequeue = dequeue
|
||||
|
||||
|
||||
def monkey_patch_deepseek_v4_allowed_layer_types():
|
||||
"""Let vLLM's `DeepseekV4Config` construct under a transformers pin below 5.15.
|
||||
|
||||
|
||||
@@ -152,14 +152,6 @@ class AppState(Stateful):
|
||||
for key, value in state_dict["progress"].items():
|
||||
setattr(self.progress, key, value)
|
||||
|
||||
# state_dict is the same dict object that dcp_load held internally; clearing
|
||||
# it drops the last references to the loaded tensor wrappers so the cuda
|
||||
# allocator can release whatever blocks it cached during the read.
|
||||
if has_cpu_offload:
|
||||
state_dict.clear()
|
||||
gc.collect()
|
||||
torch.cuda.empty_cache()
|
||||
|
||||
|
||||
class CheckpointManager:
|
||||
"""Utility class to save and load trainer checkpoints to resume SFT and RL training."""
|
||||
@@ -230,6 +222,11 @@ class CheckpointManager:
|
||||
app_state = AppState(model, optimizers if not self.skip_optimizer else [], scheduler, progress)
|
||||
state_dict = {"app": app_state}
|
||||
dcp_load(state_dict=state_dict, checkpoint_id=path, process_group=get_dcp_group())
|
||||
# DCP materializes the optimizer state with a zero-grad step, which allocates a full set of
|
||||
# gradients. Left in the allocator cache, those blocks fragment the pool and the first step
|
||||
# reserves on top of them instead of reusing them.
|
||||
gc.collect()
|
||||
torch.cuda.empty_cache()
|
||||
if self.skip_optimizer:
|
||||
for optimizer in optimizers:
|
||||
if isinstance(optimizer, OffloadOptimizer):
|
||||
|
||||
@@ -105,7 +105,7 @@ class FakeDataset(StatefulIterableDataset):
|
||||
else self.seq_len
|
||||
)
|
||||
random_input_ids = (
|
||||
torch.randint(0, self.vocab_size, (self.seq_len + 1,), generator=generator).long().tolist()
|
||||
torch.randint(0, self.vocab_size, (seq_len + 1,), generator=generator).long().tolist()
|
||||
if self.input_ids == "random"
|
||||
else None
|
||||
)
|
||||
@@ -144,7 +144,7 @@ class FakeDataset(StatefulIterableDataset):
|
||||
"mm_token_type_ids": None,
|
||||
}
|
||||
self.num_samples["fake"] += 1
|
||||
self.num_tokens["fake"] += len(input_ids)
|
||||
self.num_tokens["fake"] += seq_len
|
||||
yield fake_sample
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,20 @@ def test_fake_dataset_state():
|
||||
assert dataset.state_dict() == {"step": 4, "epoch": 0}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("length", ["fixed", "variable"])
|
||||
@pytest.mark.parametrize("input_ids", ["increasing", "random"])
|
||||
def test_fake_dataset_sample_lengths(length: str, input_ids: str):
|
||||
dataset = FakeDataset(vocab_size=10000, seq_len=128, length=length, input_ids=input_ids)
|
||||
dataiter = iter(dataset)
|
||||
for _ in range(20):
|
||||
sample = next(dataiter)
|
||||
seq_len = len(sample["input_ids"])
|
||||
assert len(sample["target_ids"]) == seq_len
|
||||
assert len(sample["position_ids"]) == seq_len
|
||||
assert len(sample["loss_mask"]) == seq_len
|
||||
assert sum(sample["seq_lens"]) == seq_len
|
||||
|
||||
|
||||
@pytest.mark.parametrize("length", ["fixed", "variable"])
|
||||
@pytest.mark.parametrize("data_world_size", [1, 2, 3])
|
||||
def test_fake_dataset_random_resume(length: str, data_world_size: int):
|
||||
|
||||
Reference in New Issue
Block a user