# SFTTrainer for Llama-2

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsfttrainer-for-llama-2%2F100704%3E%5C
**Category:** Intermediate\
**Created:** [August 3, 2024, 10:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsfttrainer-for-llama-2%2F100704 "2024-08-03T10:59:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arindam1975](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@Arindam1975](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FArindam1975)%5C
**Post date:** [August 3, 2024, 10:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsfttrainer-for-llama-2%2F100704%2F1 "2024-08-03T10:59:35Z")

</div>

I am a bit confused with the way SFFTrainer is used for finetuning a LLM. Take for example Llama-2.

**Approach-1** [Link](https://colab.research.google.com/drive/1p68M5E5fZ7kSa7nA-e-20489nuFSXVp2?usp=sharing#scrollTo=OJXpOgBFuSrc)

```auto
model_id= "NousResearch/Llama-2-7b-hf"
dataset = load_dataset("mlabonne/mini-platypus", split="train")

```

The dataset has two fields [‘instruction’, ‘output’]. The instruction is formatted text as …

> ### Instruction:
> 
> Text
> 
> ### Response:

And the output is just the required textual response. When the SFTTrainer is instantiated, there is only reference to the **instruction** field

```auto
trainer = SFTTrainer(
    model=model,
    train_dataset=dataset,
    eval_dataset=dataset,
    peft_config=peft_config,
    dataset_text_field="instruction",
    max_seq_length=512,
    tokenizer=tokenizer,
    args=training_arguments,
)

```

there is no train eval split in the dataset , still the author feeds the same dataset in train\_dataset and eval\_dataset attributes.

**Approach-2** [Link](https://mlabonne.github.io/blog/posts/Fine_Tune_Your_Own_Llama_2_Model_in_a_Colab_Notebook.html)

```auto
model_id = "NousResearch/llama-2-7b-chat-hf"
dataset_name = "mlabonne/guanaco-llama2-1k"

```

In this case the dataset has only one filed **text** and it is formatted as

![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/8/c/8ce9b48be249e905c897dbc2d55a7d59abbb33fa.png)

This time when the SFTTrainer is instantiated , there’s reference only to the text field.

```auto
trainer = SFTTrainer(
    model=model,
    train_dataset=dataset,
    peft_config=peft_config,
    dataset_text_field="text",
    max_seq_length=max_seq_length,
    tokenizer=tokenizer,
    args=training_arguments,
    packing=packing,
)

```

So the question is , how does the trainer know to look for the “output” field in the first case and how does the trainer know , that the entire data is in “text” field.
