Repository navigation
Offload finalized training publication calculations from the event loop #3811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3794ce4
2680aa4
c7c71dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import asyncio | ||
| import ctypes | ||
| import gc | ||
| import logging | ||
| import math | ||
| from concurrent.futures import ThreadPoolExecutor | ||
|
|
@@ -85,9 +84,16 @@ def set_default_executor(max_workers: int = 64) -> None: | |
| asyncio.get_event_loop().set_default_executor(ThreadPoolExecutor(max_workers=max_workers)) | ||
|
|
||
|
|
||
| def release_and_trim(*containers: list) -> None: | ||
| """Release shipped lists incrementally, then trim process memory.""" | ||
| for items in containers: | ||
| while items: | ||
| items.pop() | ||
| trim_process_memory() | ||
|
|
||
|
|
||
| def trim_process_memory() -> None: | ||
| """Return freed heap pages to the OS on glibc systems.""" | ||
| gc.collect() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved offline |
||
| try: | ||
| ctypes.CDLL("libc.so.6").malloc_trim(0) | ||
| except Exception as exc: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from pathlib import Path | ||
|
|
||
| import msgspec | ||
| import pytest | ||
|
|
||
| from prime_rl.transports.batch.base import BatchSender | ||
| from prime_rl.transports.batch.types import MicroBatch, RoutedExperts | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sender(tmp_path): | ||
| class Sender(BatchSender): | ||
| async def send(self, micro_batch_grid: list[list[MicroBatch]]) -> None: | ||
| raise NotImplementedError | ||
|
|
||
| return Sender(Path(tmp_path), data_world_size=1) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("count", [0, 1, 2, 15, 16, 255, 65535, 65536]) | ||
| @pytest.mark.parametrize("with_routing", [False, True]) | ||
| def test_batch_encode_preserves_wire_bytes(sender, count, with_routing): | ||
| batch = MicroBatch( | ||
| input_ids=[1, 2], | ||
| loss_mask=[False, True], | ||
| advantages=[0.0, 1.0], | ||
| inference_logprobs=[-0.1, -0.2], | ||
| position_ids=[0, 1], | ||
| sequence_lengths=[2], | ||
| temperatures=[1.0, 1.0], | ||
| env_names=["travel"], | ||
| seq_lens=[2], | ||
| routed_experts=RoutedExperts(b"\x00\x01\x02\x03", [2, 1, 2], "uint8") if with_routing else None, | ||
| ) | ||
| micro_batches = [batch] * count | ||
| encoded = sender.encode(micro_batches) | ||
|
|
||
| assert isinstance(encoded, bytes) | ||
| assert encoded == msgspec.msgpack.encode(micro_batches) | ||
| assert msgspec.msgpack.decode(encoded, type=list[MicroBatch]) == micro_batches |
Uh oh!
There was an error while loading. Please reload this page.