princeton-nlp / ProLong

Homepage for ProLong (Princeton long-context language models) and paper "How to Train Long-Context Language Models (Effectively)"
MIT License
102 stars 1 forks source link

ProLong

[Paper] [HF Page]

This is the homepage for ProLong (Princeton long-context language models).

ProLong is a family of long-context models that are continued trained and supervised fine-tuned from Llama-3-8B, with a maximum context window of 512K tokens. Our main ProLong model is one of the best-performing long-context models at the 10B scale (evaluated by HELMET).

To train this strong long-context model, we conduct thorough ablations on the long-context pre-training data, SFT data, and numerous other design choices. We demonstrate our findings in our paper, How to Train Long-Context Language Models (Effectively).

Authors: Tianyu Gao*, Alexander Wettig*, Howard Yen, Danqi Chen (* equal contribution)

Release Progress

Model card

Here are some quick facts about our main ProLong model: princeton-nlp/Llama-3-8B-ProLong-512k-Instruct.

image

ProLong performance on HELMET averaged over 32K, 64K, and 128K lengths. All models are instruct models.

Download the models and packed data

All ProLong models are available on Hugging Face. All the models are based on Llama-3-8B, so any code that supports Llama-3-8B is also compatible with ProLong models.

Model HF Link
ProLong-64k-Base princeton-nlp/Llama-3-8B-ProLong-64k-Base
ProLong-64k-Instruct princeton-nlp/Llama-3-8B-ProLong-64k-Instruct
ProLong-512k-Base princeton-nlp/Llama-3-8B-ProLong-512k-Base
⭐ ProLong-512k-Instruct princeton-nlp/Llama-3-8B-ProLong-512k-Instruct

Our training data (packed and sampled version) are also available on Hugging Face (in mosaicml-streaming format).

Data HF Link
Stage 1: 64K training data (40B tokens) princeton-nlp/prolong-data-64K
Stage 2: 512K training data (40B tokens) princeton-nlp/prolong-data-512K
SFT: UltraChat (1B tokens) princeton-nlp/prolong-ultrachat-64K

Download and prepare raw data

If you want to experiment with different data lengths or data mixtures, We also provide the (unpacked, unfiltered, but tokenized) raw data from each domain below. Due to the large size of the raw data, we store it on AWS S3. To download the data, you need to have an AWS account (with an access key and a secret key). Note that data downloading will incur a charge on your AWS account. According to this S3 document, each GB of data downloaded incurs $0.09 and the first 100GB is free. You can download the data using the following commands:

# Install AWS CLI if you haven't already
pip install awscli

# Configure AWS CLI with your credentials (you will need an access key and a secret key from your AWS account)
aws configure

# Download the raw code repo data (concatenated by repo names from the stack v1) 
aws s3 sync s3://princeton-prolong/data_before_packing/code_repos/ /target/path/ --request-payer requester

Below is the available unpacked raw data (tokenized with the Llama-3 tokenizer). All data is in the mosaicml-streaming format, with three fields: domain (str), input_ids (int32 numpy array, the Llama-3 tokenized document with no BOS/EOS), and length (int32, number of tokens).

Data Size S3 path
Code repos 689 GB s3://princeton-prolong/data_before_packing/code_repos/
Books (SlimPajama) 180 GB s3://princeton-prolong/data_before_packing/books/
FineWeb (sampled) 864 GB s3://princeton-prolong/data_before_packing/fineweb-2023-50/
FineWeb-edu (sampled) 365 GB s3://princeton-prolong/data_before_packing/fineweb-edu-100B/
OpenWebMath 48 GB s3://princeton-prolong/data_before_packing/openwebmath/
Wikipedia (Dolma) 14 GB s3://princeton-prolong/data_before_packing/wikipedia/
Textbooks 1 GB s3://princeton-prolong/data_before_packing/textbooks/
Tulu-v2 1 GB s3://princeton-prolong/data_before_packing/tuluv2/
StackExchange (SlimPajama) 135 GB s3://princeton-prolong/data_before_packing/stackexchange/
ArXiv (SlimPajama) 210 GB s3://princeton-prolong/data_before_packing/arxiv/
A quick guide of mosaicml-streaming Full documentation and installation guide can be found [here](https://docs.mosaicml.com/projects/streaming/en/stable/index.html).
>>> from streaming import LocalDataset
>>> dataset = LocalDataset("path/to/dataset")
>>> len(dataset) # number of samples
>>> dataset[0] # allow random access, use like a dictionary/JSON
{'domain': 'book', 'input_ids': array([ 1038, 19017,  2041, ...,   271, 12488,   220], dtype=uint32), 'length': 111200}

How to filter and pack data

We use our own datatools (created by Alex and Tianyu) to filter (by lengths) and pack data. datatools is a versatile repo that supports tokenization/packing/filtering from various raw formats (json, jsonl, hugging face, mosaicml-streaming, etc) and outputs the data in the mosaicml-streaming format.

How to train ProLong

image

ProLong training recipe.

Our training code is built on top of Hugging Face's Transformers. Compared to the original codebase, we make the following changes:

File structures

All our code is under training:

Preparation

  1. Download all the data to datasets/

    git clone https://huggingface.co/datasets/princeton-nlp/prolong-data-64K datasets/long-context-65536
    git clone https://huggingface.co/datasets/princeton-nlp/prolong-data-512K datasets/long-context-524288
    git clone https://huggingface.co/datasets/princeton-nlp/prolong-ultrachat-64K datasets/prolong-ultrachat-64K
  2. Install dependencies

    pip install -r requirements.txt

Training

We provide the scripts for 64K training (train_64K.sh), 512K training (train_512K.sh), and the final SFT training (train_sft.sh). The scripts require at least 8 GPUs (each with at least 80GB memory) to run. To run it on a local machine, simply do bash {script_name}.sh. If you are using SLURM in a cluster environment, you can submit the job by sbatch {script_name}.sh. To submit a resume-from-checkpoint job, the same script will work too.

Customization

You can read the comments in the scripts to see what customized training arguments we used. Here is a brief explanation of them (we skip all that are already defined in Hugging Face):

There are more options regarding FSDP, gradient checkpointing, etc. Please refer to the scripts for more details.

Contact

Please email Tianyu (tianyug@princeton.edu) or Alex (awettig@princeton.edu) if you have any questions. If you encounter any issues with the code, models, or data, please open an issue on GitHub.

Citation

@article{gao2024prolong,
  title={How to Train Long-Context Language Models (Effectively)},
  author={Gao, Tianyu and Wettig, Alexander and Yen, Howard and Chen, Danqi},
  journal={arXiv preprint arXiv:2410.02660},
  year={2024}
}