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

DataCollatorForCompletionOnlyLM is not able to find instruction prompt in utrachat dataset #978

Closed
anandsarth opened this issue Nov 10, 2023 · 2 comments

Comments

@anandsarth
Copy link

anandsarth commented Nov 10, 2023

from datasets import load_dataset
dataset_name = "stingning/ultrachat"
dataset = load_dataset(dataset_name, split="train[:1000]")
dataset = dataset.train_test_split(test_size=0.1,seed=42)

model_name = "mistralai/Mistral-7B-v0.1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
                             model_name, device_map=device_map,torch_dtype=torch_dtype,)

instruction_template = "<|user|>\n"
response_template = '<|assistant|>\n'
collator = DataCollatorForCompletionOnlyLM(instruction_template=instruction_template, response_template=response_template, tokenizer=tokenizer, mlm=False)

trainer = SFTTrainer(
    model=model,
    args=training_args,
    max_seq_length=seq_length,
    train_dataset=dataset["train"],
    eval_dataset=dataset["test"],
    dataset_text_field="text",
    peft_config=peft_config,
    data_collator=collator,
)

trainer.train()

But with collator i get 0 loss and the all the input sample are not able to compute loss
Screenshot 2023-11-10 at 14 02 56
trl=='0.7.4'

@younesbelkada
Copy link
Contributor

Hi @anandsarth

I am not an expert of ultra chat dataset (perhaps @lewtun @edbeeching ) but looking at the dataset it looks like you need to manually format the prompts

Screenshot 2023-11-10 at 15 12 26

You can achieve that with SFTTrainer, please have a look at this section of the docs: https://huggingface.co/docs/trl/sft_trainer#format-your-input-prompts

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

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

No branches or pull requests

2 participants