Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/llm/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
_CUSTOM_MODEL_FAMILY_KEYWORDS,
add_chat_template,
ContentBase,
history_default_spec,
)
from torchrl.data.llm.topk import TopKRewardSelector
from torchrl.modules.llm.policies.common import _extract_responses_from_full_histories
Expand Down Expand Up @@ -300,6 +301,11 @@ def test_history_spec(self):
assert isinstance(r, History)
assert spec.is_in(r)
assert spec.is_in(history)
# The free function is the canonical API now that History lives in
# tensordict; the classmethod above is kept for backward compatibility.
spec_fn = history_default_spec()
assert spec_fn.is_in(history)
assert spec_fn.is_in(r)

def test_content_base(self):
from transformers import AutoProcessor
Expand Down
3 changes: 2 additions & 1 deletion torchrl/data/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
TensorDictTokenizer,
TokenizedDatasetLoader,
)
from .history import add_chat_template, ContentBase, History
from .history import add_chat_template, ContentBase, History, history_default_spec
from .prompt import PromptData, PromptTensorDictTokenizer
from .reward import PairwiseDataset, RewardData
from .topk import TopKRewardSelector
Expand All @@ -30,5 +30,6 @@
"TokenizedDatasetLoader",
"create_infinite_iterator",
"get_dataloader",
"history_default_spec",
"TopKRewardSelector",
]
Loading
Loading