# Error using SFTTrainer: Make sure that your dataset has enough samples to at least yield one packed sequence

**URL:** <https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731>\
**Category:** Beginners\
**Created:** [February 18, 2024, 7:36pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731 "2024-02-18T19:36:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![celsowm](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/celsowm/32/50357_2.png) [@celsowm](https://discuss.huggingface.co/u/celsowm)\
**Post date:** [February 18, 2024, 7:36pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/1 "2024-02-18T19:36:50Z")

</div>

Hi, I create a small dataset to mimic the format (oai) recommended by STFTrainer doc page:

```python

from datasets import load_dataset
from trl import SFTTrainer
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, TrainingArguments
from peft import LoraConfig
import torch, sys

dataset = load_dataset("celsowm/auryn", split="train", download_mode="force_redownload")

# Specify the model
model_name = 'recogna-nlp/bode-7b-alpaca-pt-br-no-peft'

# Load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)

# BitsAndBytesConfig int-4 config
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    quantization_config=bnb_config,
    use_cache=False,
    device_map="auto",
    torch_dtype=torch.float16
)

peft_config = LoraConfig(
    lora_alpha=16,
    lora_dropout=0.1,
    r=64,
    bias="none",
    task_type="CAUSAL_LM",
)

training_args = TrainingArguments(
    output_dir='outputs/summarize',
    num_train_epochs=3,
    per_device_train_batch_size=1, 
    per_device_eval_batch_size=1,
    gradient_accumulation_steps=4, # Increase gradient accumulation to compensate for small batch size
    gradient_checkpointing=True,
    bf16=True,
    optim="adamw_bnb_8bit",
    #warmup_steps=500,
    weight_decay=0.01,
    #save_steps=500, # Save the model every 500 steps
    save_total_limit=3, # Keep only the last 3 models
)

trainer = SFTTrainer(
    model=model,
    peft_config=peft_config,
    args=training_args,
    train_dataset=dataset,
    packing=True,
    max_seq_length=2048
)

```

But I got this error:

`Make sure that your dataset has enough samples to at least yield one packed sequence`

Any hints?

---

<div class="post-metadata">

**Author:** ![sheeyor](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@sheeyor](https://discuss.huggingface.co/u/sheeyor)\
**Post date:** [March 13, 2024, 4:43pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/2 "2024-03-13T16:43:56Z")

</div>

I got the same error.

---

<div class="post-metadata">

**Author:** ![mesbahuddin1989](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@mesbahuddin1989](https://discuss.huggingface.co/u/mesbahuddin1989)\
**Post date:** [March 27, 2024, 4:10pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/3 "2024-03-27T16:10:55Z")

</div>

Did you get this solved? I am also getting the same problem.

---

<div class="post-metadata">

**Author:** ![ERDAG](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/erdag/32/25486_2.png) [@ERDAG](https://discuss.huggingface.co/u/ERDAG)\
**Post date:** [April 4, 2024, 8:40pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/4 "2024-04-04T20:40:40Z")

</div>

Any update on this? 2000 sample is not enough?

autotrain.trainers.common:wrapper:116 - Error occurred while packing the dataset. Make sure that your dataset has enough samples to at least yield one packed sequence.

---

<div class="post-metadata">

**Author:** ![PedramR](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@PedramR](https://discuss.huggingface.co/u/PedramR)\
**Post date:** [April 14, 2024, 4:44pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/5 "2024-04-14T16:44:15Z")

</div>

I had the same problem. In my case, passing the ‘train’ subset of the dataset to the `SFTTrainer`’s `train_dataset` solved the issue.

---

<div class="post-metadata">

**Author:** ![mikailokyy](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mikailokyy](https://discuss.huggingface.co/u/mikailokyy)\
**Post date:** [April 17, 2024, 12:28pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/6 "2024-04-17T12:28:44Z")

</div>

I had the same problem on my private dataset. In my case, dropping NaN values solved my the issue.

```auto
import pandas as pd
from datasets import Dataset

def create_conversation(sample):
  return {
    "messages": [
      {"role": "system", "content": system_message.format(schema=sample["context"])},
      {"role": "user", "content": sample["question"]},
      {"role": "assistant", "content": sample["answer"]}
    ]
  }

train_df = pd.read_csv('private.csv', lineterminator='\n')
train_df.dropna(inplace=True)

dataset_hf = Dataset.from_pandas(train_df)
train_dataset = dataset_hf.map(create_conversation, batched=False)

trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    peft_config=peft_config,
    args=training_args,
    train_dataset=train_dataset,
    packing=True,
    max_seq_length=2048
)

```

---

<div class="post-metadata">

**Author:** ![sc4r3cr0w](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sc4r3cr0w/32/26797_2.png) [@sc4r3cr0w](https://discuss.huggingface.co/u/sc4r3cr0w)\
**Post date:** [May 9, 2024, 12:57pm UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/7 "2024-05-09T12:57:46Z")

</div>

> [@celsowm](#):
>
> `packing=True,`

Just remove the packing=True argument from the SFTTrainer

---

<div class="post-metadata">

**Author:** ![free-x](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/free-x/32/29872_2.png) [@free-x](https://discuss.huggingface.co/u/free-x)\
**Post date:** [July 26, 2024, 11:15am UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/8 "2024-07-26T11:15:15Z")

</div>

padding=left Solved my problem

---

<div class="post-metadata">

**Author:** ![Amitontheweb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/amitontheweb/32/30595_2.png) [@Amitontheweb](https://discuss.huggingface.co/u/Amitontheweb)\
**Post date:** [September 17, 2024, 6:51am UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/9 "2024-09-17T06:51:25Z")

</div>

Hi, where can I do this in Autotrain? I am using the ‘train’ subset anyway.

---

<div class="post-metadata">

**Author:** ![faridariai](https://avatars.discourse-cdn.com/v4/letter/f/c89c15/32.png) [@faridariai](https://discuss.huggingface.co/u/faridariai)\
**Post date:** [November 1, 2024, 5:24am UTC](https://discuss.huggingface.co/t/error-using-sfttrainer-make-sure-that-your-dataset-has-enough-samples-to-at-least-yield-one-packed-sequence/73731/10 "2024-11-01T05:24:40Z")

</div>

It worked for me.
