Lightning-AI / Lightning-AI/lit-llama
`PackedDatasetBuilder` does not separate with `sep_token`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6.1k
- Forks
- 517
- PR merge metrics
- No merged PRs in 30d
Description
I noticed that `PackedDatasetBuilder` does not separate the tokens with `sep_token`.
To illustrate, referencing https://github.com/Lightning-AI/lit-llama/blob/da71adea0970d6d950fb966d365cfb428aef8298/scripts/prepare_redpajama.py#L71
```py
builder = packed_dataset.PackedDatasetBuilder(
outdir=destination_path,
prefix=prefix,
chunk_size=chunk_size,
sep_token=tokenizer.bos_id,
dtype="auto",
vocab_size=tokenizer.vocab_size,
)
```
and https://github.com/Lightning-AI/lit-llama/blob/da71adea0970d6d950fb966d365cfb428aef8298/scripts/prepare_redpajama.py#L85
```py
text_ids = tokenizer.encode(text)
```
The minimal reproducible code is as follows:
```py
from pathlib import Path
import numpy as np
from lit_gpt.tokenizer import Tokenizer
from lit_gpt.packed_dataset import PackedDatasetBuilder
tokenizer = Tokenizer(Path('tokenizer'))
content = 'foo'
tokenized = tokenizer.encode(content)
print(tokenized)
# prints:
# tensor([7953, 2], dtype=torch.int32)
training_dataset_builder = PackedDatasetBuilder(
outdir='FOO',
# Use process_id to differentiate builders
prefix='BAR',
chunk_size=6,
sep_token=tokenizer.bos_id,
dtype="auto",
vocab_size=tokenizer.vocab_size,
)
training_dataset_builder.add_array(np.array(tokenized))
print(training_dataset_builder._arr)
# prints:
# [7953 2 1 1 1 1]
training_dataset_builder.add_array(np.array(tokenized))
print(training_dataset_builder._arr)
# prints:
# [7953 2 7953 2 1 1]
```
`1` represents the bos token.
`2` represents the eos token.
As you can see, this translates to:
```
foofoo
```
Shouldn't the foo's be wrapped in bos and eos tokens, like this?
```
# Tensor
[1 7953 2 1 7953 2 ]
# Plain text
foofoo
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PackedDatasetBuilder implementation imported from lit_gpt.packed_dataset.py and reproduce the reported _arr output using the minimal example. Compare the builder's handling of sep_token with the expected BOS/EOS sequence, then add or update coverage for consecutive arrays and run the relevant dataset tests. Done means each added item is separated as described without changing chunk behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100