-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Train on responses only does not work with TinyLlama-chat #1015
Comments
I am getting the same error.
|
Oh whoops ok just saw your other issue @LostRuins as well - will definitely investigate this - sorry about this! |
Get the same error using train on responses only, but with ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[<ipython-input-15-eec2c571abe8>](https://localhost:8080/#) in <cell line: 2>()
1 from unsloth.chat_templates import train_on_responses_only
----> 2 trainer = train_on_responses_only(
3 trainer,
4 instruction_part = "<|im_start|>user\n",
5 response_part = "<|im_start|>assistant\n",
2 frames
[/usr/local/lib/python3.10/dist-packages/unsloth/chat_templates.py](https://localhost:8080/#) in <listcomp>(.0)
1864 substring = _longest_common_substring([str(x + [0]) for x in all_input_ids])
1865 substring = substring.split(", ")[:-1]
-> 1866 substring = [int(x) for x in substring]
1867
1868 # Also get rest of tokenized string
ValueError: invalid literal for int() with base 10: '' |
@NazimHAli Ok apologies I kinda forgot about this issue :( I will escalate this! Sorry on this! |
No worries man, there are tons of open issues and you can't fix all of them yourself! If I understood the logic here, would fix it myself 😅 |
As suggested here, how about directly using from trl import SFTTrainer, DataCollatorForCompletionOnlyLM
from transformers import TrainingArguments, DataCollatorForSeq2Seq
from unsloth import is_bfloat16_supported
response_template_with_context = "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
response_template_ids = tokenizer.encode(response_template_with_context, add_special_tokens=False)[2:]
collator = DataCollatorForCompletionOnlyLM(response_template_ids, tokenizer=tokenizer)
trainer = SFTTrainer(
model = model,
tokenizer = tokenizer,
train_dataset = dataset,
dataset_text_field = "text",
max_seq_length = max_seq_length,
# data_collator = DataCollatorForSeq2Seq(tokenizer = tokenizer),
data_collator = collator,
dataset_num_proc = 2,
packing = False, # Can make training 5x faster for short sequences.
args = TrainingArguments(
per_device_train_batch_size = 2,
gradient_accumulation_steps = 4,
warmup_steps = 5,
# num_train_epochs = 1, # Set this for 1 full training run.
max_steps = 60,
learning_rate = 2e-4,
fp16 = not is_bfloat16_supported(),
bf16 = is_bfloat16_supported(),
logging_steps = 1,
optim = "adamw_8bit",
weight_decay = 0.01,
lr_scheduler_type = "linear",
seed = 3407,
output_dir = "outputs",
),
) I verified that this works. |
The following error occurs while using
train_on_responses_only
on theunsloth/tinyllama-chat-bnb-4bit
model.Link to the test notebook: https://colab.research.google.com/gist/akhlakm/c7c40b0c29d112f2544168be42d3410b/llama-3-1-8b-conversational-unsloth-2x-faster-finetuning.ipynb
Also, when the chat template defined in the
tokenizer_config.json
file is used, I get the following error iftrain_on_responses_only
is used.The text was updated successfully, but these errors were encountered: