[Doc] Fold corrected TRL interoperability end-to-end section into trl_interop tutorial - #4161
[Doc] Fold corrected TRL interoperability end-to-end section into trl_interop tutorial#4161coder-jayp wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4161
Note: Links to docs will display an error until the docs builds have been completed. ❌ 4 New FailuresAs of commit d9d3a53 with merge base 60b1d01 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@torchrlbot reviewer @vmoens |
|
Requested review from @vmoens (requested by @coder-jayp). |
| if _has_trl: | ||
| # Enable TensorDict to store Python lists (strings) transparently. | ||
| # Scoped here so it only applies when trl is available. | ||
| set_list_to_stack(True).set() |
There was a problem hiding this comment.
set() changes TensorDict's process-global mode and LIST_TO_STACK. the change lasts for the rest of the process. can we scope it to buffer construction?
There was a problem hiding this comment.
Updated. Scoped using with set_list_to_stack(True): around the ReplayBuffer population loop so it doesn't leak globally
|
Can you rebase? |
24a4f32 to
8c59f65
Compare
|
Done @vmoens |
|
cc @vmoens |
vmoens
left a comment
There was a problem hiding this comment.
The real-TRL example is useful and fits the interoperability RFC, but the current tutorial does not yet demonstrate the user journey that motivates TorchRL.
It round-trips a static HF dataset through TorchRL, discards the prompt when constructing reward-model examples, skips the preference-pair creation step attributed to LLMCollector, and finally scores random tokens outside the canonical History/Tokens representation.
The real path is also skipped by both docs and tutorial CI. Could we either fold a corrected end-to-end section into the existing interop tutorial, or position this within a coherent LLM tutorial track, while preserving conversational context and exercising the actual TorchRL-to-TRL boundary?
| BATCH_SIZE = 8 | ||
| MODEL_NAME = "distilbert-base-uncased" | ||
|
|
||
| if _has_trl: |
There was a problem hiding this comment.
that's not amazing for a tutorial, how do we avoid that kind of guard and block?
|
|
||
| # %% | ||
| # 2. Bridging TorchRL → TRL with TorchRLBufferDataset | ||
| # ---------------------------------------------------- |
There was a problem hiding this comment.
| # ---------------------------------------------------- | |
| # --------------------------------------------------- |
|
@vmoens Removed the standalone file and folded a corrected end-to-end section (Part 4) into the existing trl_interop.py. Full prompt context included, LLMCollector shown as the production path, and HFRewardModelWrapper uses the canonical ("tokens", "full") / ("masks", "all_attention_mask") keys. Runs in CI with toy models only. |
|
Thanks for iterating on this. I pushed a small cleanup to make the scope and contracts accurate: At a higher level, I still think this raises an organizational question for TorchRL. This is useful as a focused recipe, but our LLM story is still forming and I would rather see it become part of a broader sequence covering collection/conversation state, preference construction, training, and scoring. In particular, a follow-up should explore how this composes with History and the existing conversational abstractions instead of establishing standalone string fields as the apparent workflow. I don’t think that necessarily needs to block this PR once CI is green, but I would like us to agree on that broader direction so this does not remain an isolated pattern. cc @theap06: we need and RFC on our LLM APIs to clean it up, make it more suitable for large scale training (incl. distributed APIs, titan/megatron integration, etc). One thing I'm particularly worried/thinking about is how do we guarantee that we have one way and only one way of doing things such that it's not confusing for users. I think the tutorials should be the last step of our LLM post training integration. |
|
@vmoens I completely agree. This tutorial serves as a focused recipe for bridging to TRL right now, but it makes total sense that it should eventually integrate with the History abstractions. Once the larger LLM API RFC is finalized (especially around distributed APIs and unified conversational state), we can revisit and update these tutorials so they demonstrate the single, canonical workflow. |
This PR extends the existing
trl_interop.pytutorial with a correctedend-to-end section (Part 4) that demonstrates the complete TorchRL ↔ TRL
user journey.
Specific changes:
trl_interop.pycovering the full preference-pair pipeline:collect (prompt + chosen + rejected) into a ReplayBuffer, bridge to a trl
trainer via TorchRLBufferDataset, and score rollouts with HFRewardModelWrapper
using the canonical ("tokens", "full") / ("masks", "all_attention_mask") keys.
coding_grpo_trl.pyfile.coding_grpo_trlentry fromindex.rstandllms.rst.Motivation and Context:
Addresses review feedback on the previous version. The new section:
Preserves full conversational context (prompt is no longer discarded).
Exercises the actual TorchRL-to-TRL boundary as described in the RFC.
Runs in CI using toy models only (no network access or GPU required).
I have raised an issue to propose this change (required for new features and bug fixes)
Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!