THUDM / THUDM/slime

Unnecessary training on the final token in SFT

Open
#863 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.5k
Forks
1.3k
Avg merge
5h 36m
Merged PRs (30d)
22

Description

https://github.com/THUDM/slime/blob/70d65e06cf9fcfd8f9064a885ec88227b38f9949/slime/backends/megatron_utils/loss.py#L65

Existing behavior: the model receives all tokens, and the last token is sliced out after the forward is run, in the above line.

The correct way:

tokens, a tensor of length 100, is received from the dataset
inputs, a tensor of length 99, consisting of tokens[:-1], is received by the model
logits, a tensor of length 99, is produced by the model.

Then the model handles 100-1 tokens, saving 1 token of context length.

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

Read slime/backends/megatron_utils/loss.py at line 65 and compare the current forward inputs with the issue's 100-token and 99-token example. Trace how tokens and inputs reach the model, then verify that the model receives tokens[:-1], produces logits for the remaining positions, and avoids training on the final token.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.