Repository navigation
fix(training): pickle AgentEnv.factory's classes so TRL's AsyncGRPO can use them - #373
Merged
earakely-scale merged 3 commits intoOct 28, 2026
Merged
Conversation
…out process needs AsyncGRPO pickles environment_factory into a spawned process, and a class built at runtime can't be found by name there. The factory's classes now pickle as the toolset and server they're built from, and the spawned process rebuilds them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing its overrides Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… pickle opened Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
deleted the
edgararakelyan/fd-4442-asyncgrpo-picklable-factory
branch
October 28, 2026 21:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
AgentEnv.factory's classes now pickle, so TRL's AsyncGRPO can use them.AsyncGRPO pickles
environment_factoryinto the rollout process it spawns. The factory's classes are built at runtime, so pickle couldn't find them by name andtrainer.train()failed:_EnvironmentClass, registered withcopyreg. A class pickles as the toolset (the listed tools) and the server it was built from. The spawned process rebuilds it from those, without probing the server again.AgentEnvis closed byAgentEnv.close()like the original. Each toolset's shared settings carry a key that survives pickling, so a rebuilt class matches theAgentEnvit came from, and only that one.GRPOTrainer, which calls the factory in process.Tests
tst/unit/training/trl_test.py::test_the_factory_pickles_and_plays_in_a_spawned_process_as_asyncgrpos_rollout_process_does. It does what AsyncGRPO's rollout process does: it builds an environment from the factory in a spawned process and plays and scores a rollout. It also checks that a runtime subclass fails to pickle by name. Run againstmain, it fails with thePicklingErrorabove.Verified on GPUs
Both trainers ran on the PortSim training pack (
portsim-dock-v1) served bybuild_appon one 4× L40S box, with Qwen3-4B (LoRA r=16) and the framework at this branch's head.AsyncGRPO (vLLM server on GPU 0, trainer on GPU 1):
rewards/portsim-dock-v1);GRPOTrainer (vLLM colocated on GPU 2):
Teardown: no episode containers were left after either run ended normally. When the trainer was killed mid-run, the server tore down its 28 live episodes within 30 s.
Install: installing
agentenv-framework[trl]on top oftrl[vllm,peft,kernels]==1.16.0,vllm==0.29.*andtransformers==5.17.*leaves trl, vllm, transformers, torch, peft, accelerate and datasets where they were. It does move four other packages down:vLLM 0.29 runs with all four.
What the docs should say about AsyncGRPO
Found while running it:
if __name__ == "__main__":, since the rollout process imports it again.kernels-community/flash-attn3Hub kernel. It's built for compute capability 8.0 and 9.0a, so it runs on A100, L40S, A10G, L4 and H100, but not on Blackwell (RTX PRO 6000, B200).max_completion_lengthnew tokens on every turn, however long the conversation has grown. A multi-turn rollout that passesmax-model-lenminus that gets a 400, which it retries 30 times before failing the run. So the server's--max-model-lenhas to cover the longest conversation plusmax_completion_length. For PortSim's dock tasks,--max-model-len 32768withmax_completion_length=2048andmax_tool_calling_iterations=8worked.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; the previous cleanup issue is fixed and no new blocking issues were found.Summary
Makes
AgentEnv.factoryclasses pickleable for AsyncGRPO’s spawned rollout process.AgentEnv.factory.The previous cleanup finding is fixed. No new actionable issues were found. Tests were inspected, not run.
Reviews (2) · Last reviewed commit: "fix(training): AgentEnv.close also close..." · Reviewed by Greptile