Skip to content

Commit

Permalink
Update setup.py and add cli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
qgallouedec committed Nov 21, 2024
1 parent c77503a commit 66254d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@
],
url="https://github.com/huggingface/trl",
entry_points={
"console_scripts": ["trl=trl.commands.cli:main"],
"console_scripts": ["trl=trl.cli:main"],
},
include_package_data=True,
package_data={"trl": ["commands/scripts/config/*", "commands/scripts/*", "templates/*.md"]},
packages=find_packages(exclude={"tests"}),
package_data={"trl": ["commands/scripts/config/*", "commands/scripts/*", "templates/*.md", "examples/*"]},
packages=find_packages(exclude={"tests", "examples"}),
install_requires=REQUIRED_PKGS,
extras_require=EXTRAS,
python_requires=">=3.9",
Expand Down
27 changes: 27 additions & 0 deletions trl/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import argparse

from transformers import HfArgumentParser, TrainingArguments
import sys
from pathlib import Path

# Add the root of the project to the python path so that we can import examples scripts
path = Path(__file__).parent.parent
sys.path.append(str(path))


def main():
parser = argparse.ArgumentParser(prog="trl", description="A CLI tool for training and fine-tuning")
subparsers = parser.add_subparsers(dest="command", required=True, parser_class=HfArgumentParser)

# 'dpo' subcommand
dpo_parser = subparsers.add_parser("dpo", help="Run the DPO training process", dataclass_types=TrainingArguments)

args = parser.parse_args()
sys.argv = sys.argv[1:] # Remove 'trl' from sys.argv

if args.command == "dpo":
from examples.scripts.dpo import main as dpo_main

(training_args,) = dpo_parser.parse_args_into_dataclasses()
dpo_main(training_args)

0 comments on commit 66254d8

Please sign in to comment.