Skip to content
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

Merged
merged 14 commits into from
Mar 19, 2024
Merged

chat cli #1431

merged 14 commits into from
Mar 19, 2024

Conversation

lvwerra
Copy link
Member

@lvwerra lvwerra commented Mar 14, 2024

This is a first draft of a chat CLI

Try with:

python examples/scripts/chat.py  --model Qwen/Qwen1.5-0.5B-Chat --device mps

cc @younesbelkada

@HuggingFaceDocBuilderDev

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.

default=None,
metadata={
"help": (
"Override the default `torch.dtype` and load the model under this dtype. If `auto` is passed, the "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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 "

Copy link
Contributor

@younesbelkada younesbelkada left a 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!

Comment on lines 55 to 58
# 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove?

Copy link
Contributor

@younesbelkada younesbelkada left a 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?

@@ -0,0 +1,302 @@
import os
from threading import Thread
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, HfArgumentParser
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see:

if TRL_USE_RICH:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, fixed


current_args = copy.deepcopy(args)

with open(os.path.join(os.path.dirname(__file__), 'default_chat_config.yaml'), "r") as f:
Copy link
Contributor

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:

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(
Copy link
Contributor

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

Copy link
Member Author

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?).

Copy link
Contributor

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

@lvwerra lvwerra marked this pull request as ready for review March 18, 2024 20:36
Copy link
Contributor

@younesbelkada younesbelkada left a 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 !

from trl.trainer.utils import get_kbit_device_map, get_quantization_config


init_zero_verbose()
Copy link
Contributor

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:

# flake8: noqa

Comment on lines 55 to 58
# 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.

Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Member Author

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'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fixed it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@lvwerra lvwerra merged commit 4e622a9 into main Mar 19, 2024
9 checks passed
@lvwerra lvwerra deleted the chat-script branch March 19, 2024 11:37
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants