-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chat cli #1431
chat cli #1431
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
examples/scripts/chat.py
Outdated
default=None, | ||
metadata={ | ||
"help": ( | ||
"Override the default `torch.dtype` and load the model under this dtype. If `auto` is passed, the " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Override the default `torch.dtype` and load the model under this dtype. If `auto` is passed, the " | |
"Override the default `torch_dtype` and load the model under this dtype. If `auto` is passed, the " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice ! I did a first pass looks all clean on my end and I can adapt it on my CLI PR to extend it for chat!
examples/scripts/chat.py
Outdated
# TODO: attribute fastchat | ||
# TODO(suquark): the console flickers when there is a code block | ||
# above it. We need to cut off "live" when a code block is done. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# TODO: attribute fastchat | |
# TODO(suquark): the console flickers when there is a code block | |
# above it. We need to cut off "live" when a code block is done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! I left small comments about the parser and the zero verbose - wdyt?
examples/scripts/chat.py
Outdated
@@ -0,0 +1,302 @@ | |||
import os | |||
from threading import Thread | |||
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, HfArgumentParser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can first import here zero_verbose_init
from trl.command.cli_utils
to remove all verbose and make sure the interface is clear at init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see:
Line 55 in 6cfa5cf
if TRL_USE_RICH: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes, fixed
examples/scripts/chat.py
Outdated
|
||
current_args = copy.deepcopy(args) | ||
|
||
with open(os.path.join(os.path.dirname(__file__), 'default_chat_config.yaml'), "r") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not using the TrlParser
above and use parser.parse_args_and_config
:
Line 85 in 6cfa5cf
args, training_args, model_config = parser.parse_args_and_config() |
top_p: float = field(default=1.0, metadata={"help": "Value of p for nucleus sampling"}) | ||
repetition_penalty: float = field(default=1.0, metadata={"help": "Repetition penalty"}) | ||
# model loading | ||
model_revision: str = field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for all the arguments below you could leverage ModelConfig
from trl instead and on the script above declare a TrlParser
with ChatArguments
and ModelConfig
- see: https://github.com/huggingface/trl/blob/main/examples/scripts/sft.py#L85-L101
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering the same, but it contains also a lot of args that are only relevant to training which i think is confusing (and would show up with help, no?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes good point ! then i think all good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great thanks ! I added few nits but overall ready to merge for me !
examples/scripts/chat.py
Outdated
from trl.trainer.utils import get_kbit_device_map, get_quantization_config | ||
|
||
|
||
init_zero_verbose() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to import that before transformers and call it before any transformers import - make sure to put a # flake8: noqa
at the top of the file to make the CI happy:
Line 1 in 6cfa5cf
# flake8: noqa |
examples/scripts/chat.py
Outdated
# TODO: attribute fastchat | ||
# TODO(suquark): the console flickers when there is a code block | ||
# above it. We need to cut off "live" when a code block is done. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to remove?
@@ -104,9 +104,9 @@ | |||
entry_points={ | |||
"console_scripts": ["trl=trl.commands.cli:main"], | |||
}, | |||
package_data={"trl": ["commands/scripts/*"]}, | |||
packages=find_packages(), | |||
include_package_data=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not break anything with SFT / DPO CLI right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, since they are python files in subdirectories they are already included:
adding 'trl/commands/__init__.py'
adding 'trl/commands/cli.py'
adding 'trl/commands/cli_utils.py'
adding 'trl/commands/scripts/chat.py'
adding 'trl/commands/scripts/ddpo.py'
adding 'trl/commands/scripts/dpo.py'
adding 'trl/commands/scripts/kto.py'
adding 'trl/commands/scripts/ppo.py'
adding 'trl/commands/scripts/ppo_multi_adapter.py'
adding 'trl/commands/scripts/reward_modeling.py'
adding 'trl/commands/scripts/sft.py'
adding 'trl/commands/scripts/config/default_chat_config.yaml'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok fixed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
* first draft * move chat to cli * fix makefile * make script less verbose * fix parsing * fix style * add more examples * fix setup.py * add copyright * fix verbose init * attribute FastChat * add docs
This is a first draft of a chat CLI
Try with:
cc @younesbelkada