forked from pytorch/torchtune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chat dataset + SlimOrca refactor + more templates (pytorch#576)
- Loading branch information
Showing
24 changed files
with
1,014 additions
and
295 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ torchtune.datasets | |
alpaca_dataset | ||
grammar_dataset | ||
samsum_dataset | ||
SlimOrcaDataset | ||
slimorca_dataset |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from tests.test_utils import DummyTokenizer | ||
from torchtune.data import tokenize_prompt_and_response, truncate | ||
from torchtune.data._common import CROSS_ENTROPY_IGNORE_IDX | ||
|
||
|
||
def test_tokenize_prompt_and_response(): | ||
tokenizer = DummyTokenizer() | ||
prompt = "Instruction:\nThis is an instruction.\n\nInput:\nThis is an input.\n\nResponse: " | ||
response = "I always know what I'm doing, do you?" | ||
prompt_length = 11 | ||
expected_tokenized_prompt = [ | ||
12, | ||
4, | ||
2, | ||
2, | ||
12, | ||
6, | ||
4, | ||
2, | ||
2, | ||
6, | ||
9, | ||
1, | ||
6, | ||
4, | ||
4, | ||
3, | ||
6, | ||
2, | ||
4, | ||
] | ||
expected_tokenized_label = [CROSS_ENTROPY_IGNORE_IDX] * prompt_length + [ | ||
1, | ||
6, | ||
4, | ||
4, | ||
3, | ||
6, | ||
2, | ||
4, | ||
] | ||
|
||
tokenized_prompt, tokenized_label = tokenize_prompt_and_response( | ||
tokenizer, prompt, response | ||
) | ||
assert tokenized_prompt == expected_tokenized_prompt | ||
assert tokenized_label == expected_tokenized_label | ||
|
||
tokenized_prompt, tokenized_label = tokenize_prompt_and_response( | ||
tokenizer, prompt, response, train_on_input=True | ||
) | ||
assert tokenized_prompt == expected_tokenized_prompt | ||
assert tokenized_label == expected_tokenized_prompt | ||
|
||
|
||
def test_truncate(): | ||
prompt_tokens = [1, 2, 3, 4, -1] | ||
label_tokens = [1, 2, 3, 4, -1] | ||
|
||
# Test no truncation | ||
truncated_prompt_tokens, truncated_label_tokens = truncate( | ||
tokenizer=DummyTokenizer(), | ||
prompt_tokens=prompt_tokens, | ||
label_tokens=label_tokens, | ||
max_seq_len=5, | ||
) | ||
assert truncated_prompt_tokens == prompt_tokens | ||
assert truncated_label_tokens == label_tokens | ||
|
||
# Test truncated | ||
truncated_prompt_tokens, truncated_label_tokens = truncate( | ||
tokenizer=DummyTokenizer(), | ||
prompt_tokens=prompt_tokens, | ||
label_tokens=label_tokens, | ||
max_seq_len=4, | ||
) | ||
assert truncated_prompt_tokens == [1, 2, 3, -1] | ||
assert truncated_label_tokens == [1, 2, 3, -1] |
This file contains 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
This file contains 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
Oops, something went wrong.