Lightning-AI / Lightning-AI/litgpt

Llama3 finetuning and generation: Double begin_of_text, no eot_id

Open
#1,682 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted waiting on author
Dominant language
Python
Stars
13.7k
Forks
1.5k
Avg merge
15h 37m
Merged PRs (30d)
1

Description

### Bug description

When finetuning Llama3, the encoded data has:
* Duplicate <|begin_of_text|> at the start
* Tracked down to template + hf tokenizer both adding one.
* No <|eot_id|> at the end in training -> #1694

Seems related to #1565, but may be more widespread across models.

Going by the example which downloads alpaca finance:
```
litgpt finetune_full meta-llama/Meta-Llama-3.1-8B-Instruct \
--config configs/llama31-8b.yaml \
--data JSON \
--data.json_path my_custom_dataset.json \
--data.mask_prompt True \
--data.prompt_style llama3 \
--data.val_split_fraction 0.05
```
and adding this to full.py along with support for `skip_special_tokens=False`
```
if fabric.global_rank == 0 and state["iter_num"] == 1:
non_pad_ids = input_ids[0][input_ids[0] != 0] # assume pad token id is 0
fabric.print(f"First row of input ids with total shape {input_ids.shape}: {non_pad_ids}")
fabric.print(f"Detokenized: {tokenizer.decode(non_pad_ids, skip_special_tokens=False)}")
```
gives
```
First row of input ids with total shape torch.Size([4, 765]): tensor([128000, 128000, 128006, 9125, 128007, 271, 264, [...] 459, 9341, 13]
Detokenized: <|begin_of_text|><|begin_of_text|><|start_header_id|> [..] accurate valuation of an investment.
```

### What operating system are you using?

Unknown

### LitGPT Version

(close to) main

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported full.py logging and reproduce the Llama 3.1 command using the alpaca finance example. Trace how the llama3 prompt style and HF tokenizer add special tokens, including the relationship to #1565 and #1694. Done means training inputs no longer contain duplicate begin_of_text tokens and include eot_id at the end.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.