Rollout Models support recording experience data#591
Open
pan-x-c wants to merge 87 commits into
Open
Conversation
…th legacy) Refactor experience production so heavy data (tokens/logprobs/routed_experts) no longer rides runner->scheduler->coordinator as serialized bytes. The vLLM recorder now captures it in-process into a MemoryStore keyed by task_id, and the coordinator pulls it at finalize time via /records/consume_task. Runners ship only a small reward map. Both paths coexist behind `explorer.use_recorded_experience` (default off = legacy). Recording module (trinity/common/models/vllm_patch/recording/): - store: drop SqlStore; MemoryStore.update_reward_by_task_id stamps reward/run/task on a whole task-id group, pops and returns it (the in-memory replacement for the SQL HistoryRecorder join). - recorder: track in-flight record tasks; add flush() (await pending + queue.join) so a consume sees a quiesced store; honor skip_recording_ctx. - models: build_experience emits one Experience per completion (n>1) with info["sample_index"]; eid.suffix=request_id kept for traceability. - context: add skip_recording_ctx; task_id already flows via api_key (RecordingIdentityMiddleware) and now also via VLLMModel.chat (Ray entry). - query: POST /records/consume_task (flush -> update_reward_by_task_id -> serialize_many); drop the SqlStore 503 branch. - config/server: remove RecordingConfig entirely; the logprob width is a recorder-internal constant (we store only the chosen token, which vLLM force-includes at logprobs=1). No static config threaded through launch. task_id propagation (Ray entry, same contextvar as the HTTP middleware): - vllm_model: chat/generate accept task_id_key, set task_id_ctx around _generate_internal; logprobs sets skip_recording_ctx (auxiliary forward). - model: ModelWrapper.chat/chat_async forward task_id_key; SGLang.chat accepts-and-ignores it (recording is vLLM-only). Coordinator + runner + workflow: - rollout_coordinator: _resolve_rank_urls (ray.get_actor per engine) and a recording-mode finalize that fans out /records/consume_task per engine, deserializes, and feeds objects to the pipeline (no re-serialization). - experience_pipeline: process_experiences(exps) public object entry. - workflow_runner: recording mode returns a pickled reward map keyed by the per-sample task_id_key the workflow stamped; legacy path unchanged. - workflow: SimpleWorkflow/AsyncSimpleWorkflow run a per-sample n=1 loop in recording mode (distinct task_id_key per sample == reward unit for GRPO), legacy n=repeat_times single-call path unchanged. - config: ExplorerConfig.use_recorded_experience flag. SQL path removal (MemoryStore only): - delete proxy/recorder.py (HistoryRecorder) and proxy_test.py; proxy service/app drop /feedback, /commit, record_feedback, submit_experiences, ready_experiences (keep allocate_model + weight sync); allocator no longer fills record_db_url; drop InferenceModelConfig.record_db_url and the dead ExplorerConfig.db_url field; RecordingConfig deleted. Serve-mode external reward reporting is intentionally left unimplemented this version (proxy /feedback//commit removed); the affected serve integration tests (TestServeWithTrainer, ServeTest) are skipped with a pointer to the recording refactor plan. convert_messages_to_experience redirect (multi-turn) is deferred with TODOs at its call sites. Co-Authored-By: Claude Fable 5 <[email protected]>
…-x-c/Trinity-RFT into feature/model_self_record_experience
chenyushuo
reviewed
Jul 1, 2026
chenyushuo
reviewed
Jul 1, 2026
chenyushuo
reviewed
Jul 1, 2026
chenyushuo
reviewed
Jul 1, 2026
Comment on lines
+154
to
155
| response_text: str = "" # Text of the response | ||
| prompt_text: Optional[str] = None # Text of the prompt |
Collaborator
There was a problem hiding this comment.
Can response_text and prompt_text be the same default value
c85db9e to
740805a
Compare
Collaborator
Author
|
/unittest-module-trainer |
unittest: Run #1803
🎉 All tests passed!Github Test Reporter by CTRF 💚 |
Collaborator
Author
|
/unittest-all |
unittest: Run #1805
❌ Some tests failed!
Github Test Reporter by CTRF 💚 |
Collaborator
Author
|
/unittest-module-utils |
Collaborator
Author
|
/unittest-pattern-TestConcurrentWorkflowRunner |
unittest: Run #1806
❌ Some tests failed!
Github Test Reporter by CTRF 💚 |
unittest: Run #1807
🎉 All tests passed!Github Test Reporter by CTRF 💚 |
Collaborator
Author
|
/unittest-pattern-test_dynamic_import |
unittest: Run #1808
🎉 All tests passed!Github Test Reporter by CTRF 💚 |
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.
Description
This PR introduces a new Experience generation and collection flow. The main goal is to let the Rollout Model record
Experiencedata during inference, while updating the Workflow / Scheduler / WorkflowRunner interfaces to support this model-side recording mode.The PR focuses on two major changes:
Key Changes
Rollout Model-side Experience Recording
Rollout Models can now convert finished generation requests into
Experienceobjects and store them inside the model process.Experiences are recorded by key in the format
<batch_id>/<task_id>/<run_id>. They are later drained by the Scheduler / RolloutCoordinator instead of being returned directly from WorkflowRunner.This PR adds the
RecordStoreinterface and an in-memoryMemoryStoreimplementation to support model-side Experience storage, update, overwrite, deletion, and prefix-based draining. Workflows can also patch reward / info back into recorded Experiences after task execution.The recording path is integrated for vLLM, SGLang, and Tinker rollout models.
New Workflow Interface for Recording-based Workflows
This PR adds
WorkflowBaseandWorkflowWithRecordingto support workflows that rely on rollout-model recording.WorkflowWithRecordingexposes:base_urlapi_keymodel_nameupdate_reward(...)A workflow can call the rollout model through an OpenAI-compatible API. The model records the generated Experience automatically, while the workflow only needs to run the task, compute reward, and write the reward back with
update_reward.The workflow execution result is normalized into
Status, which reports completion state, metrics, and successful record keys.The legacy
Workflowinterface is still kept for simple workflows that manually construct and returnExperienceobjects.Scheduler and WorkflowRunner Data Flow Update
WorkflowRunnerno longer returns serialized Experience payloads directly. It now returns only execution status.The Scheduler consumes successful record keys from
Statusand actively drains recorded Experiences from the corresponding Rollout Model actor.This separates responsibilities more clearly:
WorkflowRunner: executes workflows and returnsStatusRollout Model: records and maintains ExperiencesScheduler: drains Experiences from rollout actorsRolloutCoordinator: handles batch finalization, cleanup, and pipeline submissionChecklist
Please check the following items before code is ready to be reviewed.