Skip to content

[Refactor] Re-export History from tensordict.llm#3862

Draft
vmoens wants to merge 2 commits into
mainfrom
history-reexport-tensordict
Draft

[Refactor] Re-export History from tensordict.llm#3862
vmoens wants to merge 2 commits into
mainfrom
history-reexport-tensordict

Conversation

@vmoens

@vmoens vmoens commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Description

History, ContentBase, add_chat_template and the base chat templates moved to tensordict.llm (pytorch/tensordict#1724), which is now their canonical home. This PR turns torchrl/data/llm/history.py into a backward-compatibility shim that re-exports the public symbols plus the private template registries (_CHAT_TEMPLATES, _CUSTOM_INVERSE_PARSERS, _CUSTOM_MODEL_FAMILY_KEYWORDS) and mask helpers, so:

  • all existing torchrl.data.llm.history / torchrl.data.llm / torchrl.data import paths keep working;
  • class identity is shared (torchrl.data.llm.History is tensordict.llm.History);
  • template registry mutations are visible through both paths.

History.default_spec() keeps working unchanged: the tensordict implementation lazily imports the Composite/NonTensor specs from torchrl.

No deprecation warning is emitted for now — the path has many internal callers; new code should import from tensordict.llm directly.

Dependencies

Draft until pytorch/tensordict#1724 merges and is available in the tensordict build used by CI. At release time the tensordict floor in pyproject.toml should be bumped to the first version that ships tensordict.llm.

Tests

test/llm/test_data.py::TestHistory exercises the shim unchanged; verified locally that the import paths resolve to the tensordict classes and the History construction/completion/template tests pass.

🤖 Generated with Claude Code

History, ContentBase, add_chat_template and the base chat templates
moved to tensordict.llm (pytorch/tensordict#1724), which is now their
canonical home. torchrl/data/llm/history.py becomes a
backward-compatibility shim re-exporting the public symbols and the
private template registries, so all existing torchrl.data.llm.history
import paths keep working and class identity is shared with
tensordict.llm.

No warning is emitted on import for now, as the path is used widely
internally; new code should import from tensordict.llm directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pytorch-bot

pytorch-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3862

Note: Links to docs will display an error until the docs builds have been completed.

❌ 41 New Failures, 15 Unclassified Failures

As of commit 5021c1c with merge base 393042c (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions github-actions Bot added Refactoring Refactoring of an existing feature llm/ LLM-related PR, triggers LLM CI tests labels Jun 12, 2026
tensordict cannot depend on torchrl's spec classes, so the spec side of
the History move stays here:

- history_default_spec() free function in the re-export shim is the
  canonical way to build a Composite spec for History objects; exported
  from torchrl.data.llm.
- History.default_spec is attached to the class in the shim so the
  established classmethod API (mirroring ChatHistory/Text/Tokens) keeps
  working unchanged for existing callers.
- Internal call sites (mlgym, policies.common) migrate to the free
  function; test_history_spec covers both paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Integrations/torch_geometric Integrations llm/ LLM-related PR, triggers LLM CI tests Modules Refactoring Refactoring of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant