deepspeedai / deepspeedai/DeepSpeedExamples

Tokenization extremely inefficient -- 1 example at a time appended to python list

Open
#649 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
6.8k
Forks
1.1k
Avg merge
2d 16h
Merged PRs (30d)
1

Description

I was trying to finetune on a large dataset (>1m examples), and I was noticing that my entire machine was running out of RAM and resources. I did some digging, and I think I identified the bottleneck:

https://github.com/microsoft/DeepSpeedExamples/blob/811683a4e99c424326b38f91857456401c04161c/applications/DeepSpeed-Chat/training/utils/data/data_utils.py#L162C26-L162C26

In my understanding, this is extremely inefficient. Ideally, this should be using native datasets object (i.e. call Dataset.map, and saving the tokenized items to pytorch tensors, instead of a native python list. As it it currently written, you can only perform SFT on a small amount of examples, otherwise the script will take too long.

Let me know if this understanding is correct. If so, I believe it should be in scope for later development to refactor it.

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

Read applications/DeepSpeed-Chat/training/utils/data/data_utils.py around line 162 and trace the SFT dataset preprocessing path. Reproduce the tokenization behavior with a large dataset of over 1 million examples, then compare memory use and runtime with the proposed Dataset.map and tensor-backed approach. Done means large-dataset SFT no longer exhausts machine resources or becomes impractically slow.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
data-engineering, machine-learning
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.