-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding custom chat template / special token support (#54)
To support more than just the currently hard-coded IBM generic special tokens / chat template. --------- Signed-off-by: Mustafa Eyceoz <[email protected]>
- Loading branch information
1 parent
4ff2b4d
commit 08647d7
Showing
7 changed files
with
119 additions
and
52 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/instructlab/training/chat_templates/ibm_generic_tmpl.py
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,24 @@ | ||
# First Party | ||
from instructlab.training.tokenizer_utils import SpecialTokens | ||
|
||
SPECIAL_TOKENS = SpecialTokens( | ||
system="<|system|>", | ||
user="<|user|>", | ||
assistant="<|assistant|>", | ||
eos="<|endoftext|>", | ||
pad="<|pad|>", | ||
) | ||
|
||
CHAT_TEMPLATE = ( | ||
"{% for message in messages %}" | ||
"{% if message['role'] == 'pretraining' %}" | ||
"{{'<|endoftext|>' + message['content'] + '<|endoftext|>'}}" | ||
"{% elif message['role'] == 'system' %}" | ||
"{{'<|system|>'+ '\n' + message['content'] + '\n'}}" | ||
"{% elif message['role'] == 'user' %}" | ||
"{{'<|user|>' + '\n' + message['content'] + '\n'}}" | ||
"{% elif message['role'] == 'assistant' %}" | ||
"{{'<|assistant|>' + '\n' + message['content'] + '<|endoftext|>' + ('' if loop.last else '\n')}}" | ||
"{% endif %}" | ||
"{% endfor %}" | ||
) |
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,22 @@ | ||
# First Party | ||
from instructlab.training.tokenizer_utils import SpecialTokens | ||
|
||
SPECIAL_TOKENS = SpecialTokens( | ||
bos="<s>", | ||
eos="</s>", | ||
user="[INST]", | ||
assistant="[/INST]", | ||
) | ||
|
||
CHAT_TEMPLATE = ( | ||
"{{ '<s>' }}" | ||
"{% for message in messages %}" | ||
"{% if message['role'] == 'pretraining' %}" | ||
"{{ message['content'] + '</s>' }}" | ||
"{% elif message['role'] == 'user' %}" | ||
"{{ '[INST] ' + message['content'] + ' [/INST]' }}" | ||
"{% elif message['role'] == 'assistant' %}" | ||
"{{ message['content'] + '</s>'}}" | ||
"{% endif %}" | ||
"{% endfor %}" | ||
) |
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
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