-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding FSDP Support to Training Library (#213)
Adds support for FSDP and FSDP w/ CPU Offloading. Introduces accelerate as a distributed backend abstraction (for FSDP/DeepSpeed) Also fixes mistral template and cleans up data processing. --------- Signed-off-by: aldo pareja-cardona <[email protected]> Signed-off-by: Oleg S <[email protected]> Signed-off-by: Mustafa Eyceoz <[email protected]> Co-authored-by: aldo pareja-cardona <[email protected]> Co-authored-by: Oleg S <[email protected]> Co-authored-by: Mustafa Eyceoz <[email protected]>
- Loading branch information
1 parent
b37c8ce
commit 7b7fa12
Showing
12 changed files
with
660 additions
and
333 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
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
13 changes: 7 additions & 6 deletions
13
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
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 |
---|---|---|
@@ -1,24 +1,39 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# First Party | ||
from instructlab.training.tokenizer_utils import SpecialTokens | ||
from instructlab.training.tokenizer_utils import SpecialTokens, TokenInfo | ||
|
||
SPECIAL_TOKENS = SpecialTokens( | ||
bos="<s>", | ||
eos="</s>", | ||
user="[INST]", | ||
assistant="[/INST]", | ||
bos=TokenInfo("<s>", add_to_tokenizer=True), | ||
eos=TokenInfo("</s>", add_to_tokenizer=True), | ||
user=TokenInfo("[INST]", add_to_tokenizer=False), | ||
assistant=TokenInfo("[/INST]", add_to_tokenizer=False), | ||
) | ||
|
||
CHAT_TEMPLATE = ( | ||
"{%- if messages[0]['role'] == 'system' %}" | ||
"{%- set system_message = messages[0]['content'] %}" | ||
"{%- set loop_messages = messages[1:] %}" | ||
"{%- else %}" | ||
"{%- set loop_messages = messages %}" | ||
"{%- endif %}" | ||
"{{ '<s>' }}" | ||
"{% for message in messages %}" | ||
"{% if message['role'] == 'pretraining' %}" | ||
"{{'<|pretrain|>' + message['content'] + '</s>' + '<|/pretrain|>'}}" | ||
"{% elif message['role'] == 'user' %}" | ||
"{{ '[INST] ' + message['content'] + ' [/INST]' }}" | ||
"{% elif message['role'] == 'assistant' %}" | ||
"{{ message['content'] + '</s>'}}" | ||
"{% endif %}" | ||
"{% endfor %}" | ||
"{%- for message in loop_messages %}" | ||
"{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}" | ||
"{{- raise_exception('After the optional system message, conversation roles must alternate user/assistant/user/assistant/...') }}" | ||
"{%- endif %}" | ||
"{%- if message['role'] == 'user' %}" | ||
"{%- if loop.first and system_message is defined %}" | ||
"{{- ' [INST] ' + system_message + '\n\n' + message['content'] + ' [/INST]' }}" | ||
"{%- else %}" | ||
"{{- ' [INST] ' + message['content'] + ' [/INST]' }}" | ||
"{%- endif %}" | ||
"{%- elif message['role'] == 'pretraining' %}" | ||
"{{- '<|pretrain|>' + message['content'] + '</s>' + '<|/pretrain|>' }}" | ||
"{%- elif message['role'] == 'assistant' %}" | ||
"{{- ' ' + message['content'] + '</s>'}}" | ||
"{%- else %}" | ||
"{{- raise_exception('Only user and assistant roles are supported, with the exception of an initial optional system message!') }}" | ||
"{%- 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
Oops, something went wrong.