lm-sys / lm-sys/FastChat

# "-2" is hardcoded for the Llama tokenizer to make the offset correct.?

Open
#2,670 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
39.5k
Forks
4.8k
PR merge metrics
No merged PRs in 30d

Description

In the main training file, I saw that you applied a -2 to the instruction length and the comment is that -2 is hardcoded for the right offset. Can you help me with the exact reason to do so?

I cross-checked with the llama-recipe library
https://github.com/facebookresearch/llama-recipes/blob/main/src/llama_recipes/datasets/alpaca_dataset.py

In the following codeblock, no offset was applied.

` def __getitem__(self, index):
IGNORE_INDEX = -100 # The default setting in CrossEntropyLoss

ann = self.ann[index]
if ann.get("input", "") == "":
prompt = PROMPT_DICT["prompt_no_input"].format_map(ann)
else:
prompt = PROMPT_DICT["prompt_input"].format_map(ann)
example = prompt + ann["output"]
prompt = torch.tensor(
self.tokenizer.encode(prompt), dtype=torch.int64
)
example = self.tokenizer.encode(example)
example.append(self.tokenizer.eos_token_id)
example = torch.tensor(
example, dtype=torch.int64
)
labels = copy.deepcopy(example)
labels[: len(prompt)] = -1
example_mask = example.ge(0)
label_mask = labels.ge(0)
example[~example_mask] = 0
labels[~label_mask] = IGNORE_INDEX

return {
"input_ids": example.tolist(),
"labels": labels.tolist(),
"attention_mas`

Contributor guide

No contributing guide indexed for this repository

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 in the main training file at the instruction-length calculation containing the hardcoded -2, then compare its tokenizer behavior with the linked llama-recipes alpaca_dataset.py implementation. Establish why the offset is needed and document that rationale, or record the evidence for removing it; the issue is complete when the offset behavior and its intended effect are clearly explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Documentation
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.