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

Update sft_llama2.py to work with the latest API #1637

Merged
merged 3 commits into from
May 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update sft_llama2.py to work with the latest API
SFTTrainer now takes a STFConfig argument
  • Loading branch information
xianbaoqian authored May 10, 2024
commit d2e95580835cef99a1db6f6672250f8983e8ad1e
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
set_seed,
)

from trl import SFTTrainer
from trl import SFTTrainer, SFTConfig
from trl.import_utils import is_npu_available, is_xpu_available
from trl.trainer import ConstantLengthDataset

Expand All @@ -33,7 +33,6 @@ class ScriptArguments:
shuffle_buffer: Optional[int] = field(default=5000, metadata={"help": "the shuffle buffer size"})
seq_length: Optional[int] = field(default=1024, metadata={"help": "the sequence length"})
num_workers: Optional[int] = field(default=4, metadata={"help": "the number of workers"})
packing: Optional[bool] = field(default=True, metadata={"help": "whether to use packing for SFTTrainer"})
use_bnb: Optional[bool] = field(default=True, metadata={"help": "whether to use BitsAndBytes"})

# LoraConfig
Expand All @@ -42,7 +41,7 @@ class ScriptArguments:
lora_r: Optional[int] = field(default=8, metadata={"help": "the lora r parameter"})


parser = HfArgumentParser((ScriptArguments, TrainingArguments))
parser = HfArgumentParser((ScriptArguments, SFTConfig))
script_args, training_args = parser.parse_args_into_dataclasses()
peft_config = LoraConfig(
r=script_args.lora_r,
Expand All @@ -53,7 +52,7 @@ class ScriptArguments:
task_type="CAUSAL_LM",
)

if training_args.group_by_length and script_args.packing:
if training_args.group_by_length and training_args.packing:
raise ValueError("Cannot use both packing and group by length")

# `gradient_checkpointing` was True by default until `1f3314`, but it's actually not used.
Expand Down Expand Up @@ -172,8 +171,8 @@ def create_datasets(tokenizer, args, seed=None):
train_dataset=train_dataset,
eval_dataset=eval_dataset,
peft_config=peft_config,
packing=script_args.packing,
max_seq_length=None,
formatting_func=prepare_sample_text,
tokenizer=tokenizer,
args=training_args,
)
Expand Down
Loading