online-data-mixing
An implementation of online data mixing for the Pile dataset, based on the GPT-NeoX library.
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.2%) to scientific vocabulary
Repository
An implementation of online data mixing for the Pile dataset, based on the GPT-NeoX library.
Basic Info
Statistics
- Stars: 7
- Watchers: 0
- Forks: 2
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
ODM - Online Data Mixing (Under development)
This is the official repository for the methods provided in Efficient Online Data Mixing For Language Model Pre-Training.
Abstract
The data used to pretrain large language models has a decisive impact on a model's downstream performance, which has led to a large body of work on data selection methods that aim to automatically determine the most suitable data to use for pretraining. Existing data selection methods suffer from slow and computationally expensive processes, a problem amplified by the increasing size of models and of pretraining datasets. Data mixing, on the other hand, reduces the complexity of data selection by grouping data points together and determining sampling probabilities across entire groups. However, data mixing proportions are typically fixed before training and therefore cannot adapt to changing training dynamics. To address these limitations, we develop an efficient algorithm for Online Data Mixing (ODM) that combines elements from both data selection and data mixing. Based on multi-armed bandit algorithms, our online approach optimizes the data mixing proportions during training. Remarkably, our method trains a model that reaches the final perplexity of the next best method with 19\% fewer training iterations, and improves performance on the 5-shot MMLU benchmark by 1.9% relative accuracy, while adding negligible wall-clock time during pretraining.
Overview
This repository contains code for developing efficient online data mixing methods.
The majority of the functionality is found in the datasamplingutils.py file. Specifically, the SmoothedMeanWeightUpdater class is the data mixing implementation described in the paper, used to store and update mixture weights.
Note: This repository is under active development as is subject to change.
Setup
This repository is not setup to be directly run as-is. This is in part because it was developed for the now defunct Pile dataset. However, the core functions can be replicated with minimal effort.
If you already have access to the Pile dataset, you can use the code from this repo directly. To setup the environment, use:
bash
bash alon_setup.sh
For more details on setup and usage, you can follow the original gpt-neox README in the section below titled "Original GPT-NeoX README".
To Do:
- [ ] Isolate the functions specific to ODM so that it can be packaged with pip
Acknowledgements
This work is built on the GPT-NeoX framework developed by EleutherAI and the original repository can be found at https://github.com/EleutherAI/gpt-neox
Original GPT-NeoX README
# GPT-NeoX This repository records [EleutherAI](https://www.eleuther.ai)'s library for training large-scale language models on GPUs. Our current framework is based on NVIDIA's [Megatron Language Model](https://github.com/NVIDIA/Megatron-LM) and has been augmented with techniques from [DeepSpeed](https://www.deepspeed.ai) as well as some novel optimizations. We aim to make this repo a centralized and accessible place to gather techniques for training large-scale autoregressive language models, and accelerate research into large-scale training. For those looking for a TPU-centric codebase, we recommend [Mesh Transformer JAX](https://github.com/kingoflolz/mesh-transformer-jax). **If you are not looking to train models with billions of parameters from scratch, this is likely the wrong library to use. For generic inference needs, we recommend you use the Hugging Face `transformers` library instead which supports GPT-NeoX models.** # Contents * [Quick Start](#quick-start) * [Environment and Dependencies](#environment-and-dependencies) * [Usage](#usage) * [Configuration](#configuration) * [Datasets](#datasets) * [Preconfigured Datasets](#preconfigured-datasets) * [Using Custom Data](#using-custom-data) * [Training and Finetuning](#training-and-finetuning) * [Select Pretrained Models](#pretrained-models) * [GPT-NeoX-20B](#gpt-neox-20b) * [Pythia](#pythia) * [Polyglot](#polyglot) * [Fill-in-the-Middle](#fill-in-the-middle) * [Inference](#inference) * [Evaluation](#evaluation) * [Exporting to Hugging Face](#exporting-to-hugging-face) * [Monitoring](#monitoring) * [Weights & Biases](#wandb) * [TensorBoard](#tensorboard) * [Administrative Notes](#administrative-notes) * [Citing GPT-NeoX](#citing-gpt-neox) * [Licensing](#licensing) * [Publications](#publications) * [Acknowledgements](#acknowledgements) # Quick Start ## Environment and Dependencies ### Host Setup First make sure you are in an environment with Python 3.8 with an appropriate version of PyTorch 1.8 or later installed. **Note:** Some of the libraries that GPT-NeoX depends on have not been updated to be compatible with Python 3.10+. Python 3.9 appears to work, but this codebase has been developed and tested for Python 3.8. To install the remaining basic dependencies, run: ```bash pip install -r requirements/requirements.txt python ./megatron/fused_kernels/setup.py install # optional if not using fused kernels ``` from the repository root. ### Flash Attention To use [Flash-Attention](https://github.com/HazyResearch/flash-attention), install the additional dependencies in `./requirements/requirements-flashattention.txt` and set the attention type in your configuration accordingly (see [configs](./configs/)). This can provide significant speed-ups over regular attention on certain GPU architectures, including Ampere GPUs (such as A100s); see the repository for more details. ### Containerized Setup We also provide a Dockerfile if you prefer to run NeoX in a container. To use this option, first build an image named `gpt-neox` from the repository root directory with `docker build -t gpt-neox -f Dockerfile .`. We also host pre-built images on [Docker Hub at `leogao2/gpt-neox`](https://hub.docker.com/r/leogao2/gpt-neox/tags). You can then run a container based on this image. For instance, the below snippet mounts the cloned repository (`gpt-neox`) directory to `/gpt-neox` in the container and uses [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) to make four GPUs (numbers 0-3) accessible to the container. [As noted by the NCCL documentation](https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/troubleshooting.html#sharing-data), both `--shm-size=1g` and `--ulimit memlock=-1` are important to prevent Docker from allocating too little shared memory. ``` nvidia-docker run --rm -it -e NVIDIA_VISIBLE_DEVICES=0,1,2,3 --shm-size=1g --ulimit memlock=-1 --mount type=bind,src=$PWD,dst=/gpt-neox gpt-neox ``` ## Usage All functionality (inference included), should be launched using `deepy.py`, a wrapper around the `deepspeed` launcher. We currently offer three main functions: 1. `train.py` is used for training and finetuning models. 2. `evaluate.py` is used to evaluate a trained model using the [language model evaluation harness](https://github.com/EleutherAI/lm-evaluation-harness). 3. `generate.py` is used to sample text from a trained model. which can be launched with: ```bash ./deepy.py [script.py] [./path/to/config_1.yml] [./path/to/config_2.yml] ... [./path/to/config_n.yml] ``` E.G To generate text unconditionally with the GPT-NeoX-20B model, you can use the following: ```bash ./deepy.py generate.py ./configs/20B.yml ``` Or optionally pass in a text file (e.g `prompt.txt`) to use as the prompt, which should be a plain `.txt` file with each prompt separated by newline characters, also passing in the path to an output file. ```bash ./deepy.py generate.py ./configs/20B.yml -i prompt.txt -o sample_outputs.txt ``` To reproduce our evaluation numbers on, for example, TriviaQA and PIQA use: ```bash ./deepy.py evaluate.py ./configs/20B.yml --eval_tasks triviaqa piqa ``` You can add an arbitrary list of evaluation tasks here, for details of all tasks available, see [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness). For more details on each entry point, see the [Training and Finetuning](#training-and-finetuning), [Inference](#inference) and [Evaluation](#evaluation) # Configuration GPT-NeoX parameters are defined in a YAML configuration file which is passed to the deepy.py launcher. We have provided some example .yaml files in [configs](./configs/), including one for GPT-NeoX-20B, and example configuration files for other model sizes. These files are generally complete, but non-optimal. For example, depending on your specific GPU configuration, you may need to change some settings such as `pipe-parallel-size`, `model-parallel-size` to increase or decrease the degree of parallelisation, `train_micro_batch_size_per_gpu` or `gradient-accumulation-steps` to modify batch size related settings, or the `zero_optimization` dict to modify how optimizer states are parallelised across workers. For a more detailed guide to all the features available and how to configure them, see [the configuration README](configs/README.md), and for documentation of every possible argument, see [configs/neox_arguments.md](configs/neox_arguments.md). # Datasets ## Preconfigured Datasets Several preconfigured datasets are available, including most components from [the Pile](https://arxiv.org/abs/2101.00027), as well as the Pile train set itself, for straightforward tokenization using the `prepare_data.py` entry point. E.G, to download and tokenize the Enron emails corpus with the GPT2 Tokenizer, saving them to `./data` you can run: ``` python prepare_data.py -d ./data ``` or with the GPT-NeoX-20B tokenizer (assuming you have it saved at `./20B_checkpoints/20B_tokenizer.json`): ``` python prepare_data.py -d ./data -t HFTokenizer --vocab-file ./20B_checkpoints/20B_tokenizer.json ``` The tokenized data will be saved out to two files: `[data-dir]/[dataset-name]/[dataset-name]_text_document.bin`and `[data-dir]/[dataset-name]/[dataset-name]_text_document.idx`. You will need to add the prefix that both these files share to your training configuration file under the `data-path` field. E.G: ```yaml "data-path": "./data/enron/enron_text_document", ``` ## Using Custom Data To prepare your own dataset for training with custom data, format it as one large [jsonl](https://jsonlines.org/)-formatted file with each item in the list of dictionaries being a separate document. The document text should be grouped under one JSON key, i.e `"text"`. Any auxiliary data stored in other fields will not be used. Next make sure to download the GPT2 tokenizer vocab, and merge files from the following links: - Vocab: https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json - Merge: https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt Or use the 20B tokenizer (for which only a single Vocab file is needed): - Vocab: https://the-eye.eu/public/AI/models/GPT-NeoX-20B/slim_weights/20B_tokenizer.json (alternatively, you can provide any tokenizer file that can be loaded by Hugging Face's tokenizers library with the `Tokenizer.from_pretrained()` command) You can now pretokenize your data using `tools/preprocess_data.py`, the arguments for which are detailed below: ``` usage: preprocess_data.py [-h] --input INPUT [--jsonl-keys JSONL_KEYS [JSONL_KEYS ...]] [--num-docs NUM_DOCS] --tokenizer-type {HFGPT2Tokenizer,HFTokenizer,GPT2BPETokenizer,CharLevelTokenizer} [--vocab-file VOCAB_FILE] [--merge-file MERGE_FILE] [--append-eod] [--ftfy] --output-prefix OUTPUT_PREFIX [--dataset-impl {lazy,cached,mmap}] [--workers WORKERS] [--log-interval LOG_INTERVAL] optional arguments: -h, --help show this help message and exit input data: --input INPUT Path to input jsonl files or lmd archive(s) - if using multiple archives, put them in a comma separated list --jsonl-keys JSONL_KEYS [JSONL_KEYS ...] space separate listed of keys to extract from jsonl. Defa --num-docs NUM_DOCS Optional: Number of documents in the input data (if known) for an accurate progress bar. tokenizer: --tokenizer-type {HFGPT2Tokenizer,HFTokenizer,GPT2BPETokenizer,CharLevelTokenizer} What type of tokenizer to use. --vocab-file VOCAB_FILE Path to the vocab file --merge-file MERGE_FILE Path to the BPE merge file (if necessary). --append-eod Append anWeights & Biases
EleutherAI is currently using [Weights & Biases to record our experiments](https://wandb.ai/eleutherai/neox). If you are logged into Weights & Biases on your machine—you can do this by executing `wandb login`—your runs will automatically be recorded. There are two optional fields associated with Weights & Biases:wandb_group allows you to name the run group and wandb_team allows you to assign your runs to an organization or team account.
## TensorBoard
We also support using TensorBoard via the tensorboard-dir field. Dependencies required for TensorBoard monitoring can be found in and installed from `./requirements/requirements-tensorboard.txt`.
# Running on multi-node
If you need to supply a hostfile for use with the MPI-based DeepSpeed launcher, you can set the environment variable `DLTS_HOSTFILE` to point to the hostfile.
# Administrative Notes
## Citing GPT-NeoX
If you have found the GPT-NeoX library helpful in your work, you can cite this repository as
```bibtex
@software{gpt-neox-library,
title = {{GPT-NeoX: Large Scale Autoregressive Language Modeling in PyTorch}},
author = {Andonian, Alex and Anthony, Quentin and Biderman, Stella and Black, Sid and Gali, Preetham and Gao, Leo and Hallahan, Eric and Levy-Kramer, Josh and Leahy, Connor and Nestler, Lucas and Parker, Kip and Pieler, Michael and Purohit, Shivanshu and Songz, Tri and Phil, Wang and Weinbach, Samuel},
url = {https://www.github.com/eleutherai/gpt-neox},
doi = {10.5281/zenodo.5879544},
month = {8},
year = {2021},
version = {0.0.1},
}
```
To cite our 20 billion parameter model, please use
```bibtex
@inproceedings{gpt-neox-20b,
title={{GPT-NeoX-20B}: An Open-Source Autoregressive Language Model},
author={Black, Sid and Biderman, Stella and Hallahan, Eric and Anthony, Quentin and Gao, Leo and Golding, Laurence and He, Horace and Leahy, Connor and McDonell, Kyle and Phang, Jason and Pieler, Michael and Prashanth, USVSN Sai and Purohit, Shivanshu and Reynolds, Laria and Tow, Jonathan and Wang, Ben and Weinbach, Samuel},
booktitle={Proceedings of the ACL Workshop on Challenges \& Perspectives in Creating Large Language Models},
url={https://arxiv.org/abs/2204.06745},
year={2022}
}
```
Citation instructions for other pretrained models can be found [in the appropriate repository](#pretrained-models).
## Licensing
This repository hosts code that is part of EleutherAI's GPT-NeoX project. Copyright (c) 2021, EleutherAI. Licensed under the Apache License:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This repository is based off code written by NVIDIA that is licensed under the Apache License, Version 2.0. In accordance with the Apache License, all files that are modifications of code originally written by NVIDIA maintain a NVIDIA copyright header. All files that do not contain such a header are the exclusive copyright of EleutherAI. When the NVIDIA code has been modified from its original version, that fact is noted in the copyright header. All derivative works of this repository must preserve these headers under the terms of the Apache License.
This repository also contains code written by a number of other authors. Such contributions are marked and the relevant licensing is included where appropriate.
For full terms, see the `LICENSE` file. If you have any questions, comments, or concerns about licensing please email us at contact@eleuther.ai.
## Publications
The following publications have come out of this project:
- Black, Biderman, Hallahan, Anthony, Gao, Golding, He, Leahy, McDonell, Phang, Pieler, Prashanth, Purohit, Reynolds, Tow, Wang, and Weinbach. "[GPT-NeoX-20B: An Open-Source Autoregressive Language Model](https://arxiv.org/abs/2204.06745)." In *Proceedings of the ACL Workshop on Challenges \& Perspectives in Creating Large Language Models*. 2022.
The following publications by other research groups use this library:
- Chi, Fan, Ramadge, and Rudnicky. "[KERPLE: Kernelized Relative Positional Embedding for Length Extrapolation](https://arxiv.org/abs/2205.09921)". _arXiv preprint arXiv:2205.09921_. 2022.
- Horawalavithana, Ayton, Sharma, Howland, Subramanian, Vasquez, Cosbey, Glenski, and Volkova. "[Foundation Models of Scientific Knowledge for Chemistry: Opportunities, Challenges and Lessons Learned](https://openreview.net/pdf?id=SLX-I2MHUZ9)." In *Proceedings of the ACL Workshop on Challenges \& Perspectives in Creating Large Language Models*. 2022.
- Kolak, Martins, Le Goues, and Hellendoorn. "[Patch Generation with Language Models: Feasibility and Scaling Behavior](https://openreview.net/forum?id=rHlzJh_b1-5)"." In *Proceedings of the Deep Learning for Code Workshop at ICLR*. 2022.
- Muennighoff, Niklas. "[SGPT: GPT Sentence Embeddings for Semantic Search](https://arxiv.org/abs/2202.08904)." *arXiv preprint arXiv:2202.08904*. 2022.
- Xu, Alon, Neubig, and Hellendoorn. "[A Systematic Evaluation of Large Language Models of Code](https://arxiv.org/abs/2202.13169)." In *Proceedings of the ICLR Workshop on Deep Learning For Code*. 2022.
## Acknowledgements
We run our experiments on a Kubernetes cluster generously provided by [CoreWeave](https://coreweave.com/) and a SLURM cluster provided by [Stability AI](https://stability.ai).
How to Cite
If you extend or use this work, please cite the paper where it was first introduced:
@misc{albalak2023efficient,
title={Efficient Online Data Mixing For Language Model Pre-Training},
author={Alon Albalak and Liangming Pan and Colin Raffel and William Yang Wang},
year={2023},
eprint={2312.02406},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Owner
- Name: Alon Albalak
- Login: alon-albalak
- Kind: user
- Location: Santa Barbara, CA
- Website: https://alon-albalak.github.io/
- Twitter: AlbalakAlon
- Repositories: 5
- Profile: https://github.com/alon-albalak
PhD student, Natural Language Processing and Deep Learning
Citation (CITATION.cff)
# YAML 1.2
---
authors:
- affiliation: EleutherAI
family-names: Andonian
given-names: Alex
- affiliation: EleutherAI
family-names: Biderman
given-names: Stella
- affiliation: EleutherAI
family-names: Black
given-names: Sid
- affiliation: EleutherAI
family-names: Gali
given-names: Preetham
- affiliation: EleutherAI
family-names: Gao
given-names: Leo
- affiliation: EleutherAI
family-names: Hallahan
given-names: Eric
- affiliation: EleutherAI
family-names: Levy-Kramer
given-names: Josh
- affiliation: EleutherAI
family-names: Leahy
given-names: Connor
- affiliation: EleutherAI
family-names: Nestler
given-names: Lucas
- affiliation: EleutherAI
family-names: Parker
given-names: Kip
- affiliation: EleutherAI
family-names: Pieler
given-names: Michael
- affiliation: EleutherAI
family-names: Purohit
given-names: Shivanshu
- affiliation: EleutherAI
family-names: Songz
given-names: Tri
- affiliation: EleutherAI
family-names: Phil
given-names: Wang
- affiliation: EleutherAI
family-names: Weinbach
given-names: Samuel
cff-version: "1.1.0"
keywords:
- "Transformers"
- "Massive language model"
- "Autoregressive language model"
license: "Apache-2.0"
message: "If you use this software, please cite it using these metadata."
repository-code: "https://www.github.com/eleutherai/gpt-neox"
title: "GPT-NeoX: Large Scale Autoregressive Language Modeling in PyTorch"
version: "0.0.1"
doi: "10.5281/zenodo.5879544"
date-released: 2021-08-23
...
GitHub Events
Total
- Watch event: 2
Last Year
- Watch event: 2
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/checkout v2 composite
- crazy-max/ghaction-docker-meta v1 composite
- docker/build-push-action v2 composite
- docker/login-action v1 composite
- docker/setup-buildx-action v1 composite
- docker/setup-qemu-action v1 composite
- actions/checkout v2 composite
- actions/checkout v3 composite
- actions/setup-python v2 composite
- pre-commit/action v2.0.3 composite
- nvidia/cuda 11.1.1-devel-ubuntu20.04 build
- autopep8 ==1.5.6 development
- clang-format ==13.0.1 development
- pre-commit * development
- pytest ==6.2.3 development
- pytest-cov ==2.11.1 development
- pytest-forked ==1.3.0 development
- pytest-xdist * development
- transformers * development
- flash-attn ==0.2.2
- cupy-cuda111 ==8.6.0
- triton ==0.4.2
- tensorboard ==2.5.0
- best-download *
- deepspeed eb7f5cff36678625d23db8a8fe78b4a93e5d2c75
- einops ==0.3.0
- ftfy ==6.0.1
- huggingface_hub ==0.11.0
- lm_eval ==0.3.0
- numpy ==1.22.0
- protobuf ==3.20.
- pybind11 ==2.6.2
- regex *
- sentencepiece *
- six *
- tiktoken ==0.1.2
- tokenizers ==0.12.1
- transformers *
- urllib3 *
- wandb ==0.10.28