Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gpt-neo

> 数据库
Open source

An implementation of model parallel GPT-2 and GPT-3-style models using the mesh-tensorflow library.

8.3K stars0 likes1 views
WebsiteGitHub

About

An implementation of model parallel GPT-2 and GPT-3-style models using the mesh-tensorflow library.

GPT Neo

*As of August, 2021 code is no longer maintained. It is preserved here in archival form for people who wish to continue to use it.

1T or bust my dudes

An implementation of model & data parallel GPT3-like models using the mesh-tensorflow library.

If you're just here to play with our pre-trained models, we strongly recommend you try out the HuggingFace Transformer integration.

Training and inference is officially supported on TPU and should work on GPU as well. This repository will be (mostly) archived as we move focus to our GPU-specific repo, GPT-NeoX.

In addition to the functionality offered by GPT-3, we also offer the following:

  • Local attention
  • Linear attention
  • Mixture of Experts
  • Axial Positional embedding

NB, while neo can technically run a training step at 200B+ parameters, it is very inefficient at those scales. This, as well as the fact that many GPUs became available to us, among other things, prompted us to move development over to GPT-NeoX.

Pretrained Models

Update 21/03/2021:

We're proud to release two pretrained GPT-Neo models trained on The Pile, the weights and configs can be freely downloaded from the-eye.eu.

1.3B: https://mystic.the-eye.eu/public/AI/gptneo-release/GPT3_XL/

2.7B: https://mystic.the-eye.eu/public/AI/gptneo-release/GPT3_2-7B/

For more information on how to get these set up, see the colab notebook, or read through the rest of the readme.

Model Evaluations

Linguistic Reasoning

Model and Size Pile BPB Pile PPL Wikitext PPL Lambada PPL Lambada Acc Winogrande Hellaswag
GPT-Neo 125M ----- ----- 32.285 30.266 37.36% 50.43% 28.67%
GPT-3 125M ----- ----- ----- 18.6 42.7% 52.0% 33.7%
GPT-Neo 350M ----- ----- 22.5657 13.876 47.27% 51.14% 32.16%
GPT-3 350M ----- ----- ----- 9.09 54.3% 52.1% 43.6%
GPT-3 Ada 0.9631 ----- ----- 9.954 51.60% 52.90% 35.93%
GPT-Neo 1.3B 0.7527 6.159 13.10 7.498 57.23% 55.01% 38.66%
GPT-3 1.3B ----- ----- ----- 5.44 63.6% 58.7% 54.7%
GPT-2 1.5B 1.0468 ----- 17.48 10.634 51.21% 59.40% 40.03%
GPT-Neo 2.7B 0.7165 5.646 11.39 5.626 62.22% 56.50% 42.73%
GPT-3 2.7B ----- ----- ----- 4.60 67.1% 62.3% 62.8%

Physical and Scientific Reasoning

Model and Size MathQA PubMedQA Piqa
GPT-Neo 125M 22.78% 55.10% 63.06%
GPT-3 125M ----- ----- 64.6%
GPT-Neo 350M 23.45% 53.80% 65.07%
GPT-3 350M ----- ----- 70.2%
GPT-3 Ada 24.29% 52.80% 68.88%
GPT-Neo 1.3B 24.05% 54.40% 71.11%
GPT-3 1.3B ----- ----- 75.1%
GPT-2 1.5B 23.64% 58.33% 70.78%
GPT-Neo 2.7B 24.72% 57.54% 72.14%
GPT-3 2.7B ----- ----- 75.6%

Note: All evaluations were done using our evaluation harness. Some results for GPT-2 and GPT-3 are inconsistent with the values reported in the respective papers. We are currently looking into why, and would greatly appreciate feedback and further testing of our eval harness.

Setup

bash
git clone https://github.com/EleutherAI/GPTNeo
cd GPTNeo
pip3 install -r requirements.txt

Training Setup

TPUs:

Sign up for Google Cloud Platform, and create a storage bucket.

Create your VM through a google shell (https://ssh.cloud.google.com/) with ctpu up --vm-only so that it can connect to your Google bucket and TPUs and install the requirements with pip (see above).

Google colab provides tpu-v8s for free, which should be enough to finetune our models up to GPT3XL (1.5B parameter) sizes. Click to run through our example colab notebook.

For more detailed instructions, run through our Training Guide below.

GPUs:

You can also choose to train GPTNeo locally on your GPUs. To do so, you can omit the Google cloud setup steps above, and git clone the repo locally. Run through the Training Guide below, then when running main.py, you simply have to omit the tpu flag, and pass in GPU ids instead.

Note: Some users have reported having difficulty getting MTF to recognize their GPUs. See here for details and instructions on how to fix it.

Generating Text

Once you have a trained model, or you've downloaded one of our pre-trained models, generating text is as simple as running the main.py script with the --predict flag on. You can pass a path to your prompt txt file with the --prompt flag, like so:

bash
python3 main.py --predict --prompt <example_prompt.txt> --tpu <tpu_name> --model <config_name>

or, if using GPUs:

bash
python3 main.py --predict --prompt <example_prompt.txt> --gpu_ids <device:GPU:0 device:GPU:1> --model <config_name>

Training Guide

1. Create your Tokenizer (OPTIONAL)

We recommend you use Huggingface's pretrained GPT2 tokenizer with our repo (instructions provided below), but if you want to train a model with a different vocabulary size, we provide facilities to train your own tokenizer like so:

bash
python data/train_tokenizer.py \
    --base_dir ./path/to/your/txt/files \
    --output_dir ./output/path \
    --file_type txt \
    --vocab_size 50257

# if it succeeded, you should see the message
# 'tokenizer saved at ./output/path/byte-level-bpe.tokenizer.json'

2. Tokenizing your Dataset

If you just want to test training, you can skip this step and download some dummy data like so:

bash
wget https://storage.googleapis.com/connors-datasets/bundestag/bundestag_0.tfrecords

Then copy the data to your bucket, or if using GPUs, a local directory:

gsutil cp bundestag_0.tfrecords gs://<your bucket>/

If using your own data to train, you can use the data/create_tfrecords.py script to encode your text data into tfrecords.

Your data must either be in the form of lots of normal .txt files (one document per file), or in any format supported by lm_dataformat.

You can run the script without parameters to see help for all options.

In document mode Each example in the tfrecords is one (variably sized) document. This is to be used with the documents_fixed and documents_random sampling modes (For more details see the parameters reference section). Document mode is the default mode.

The below command will tokenize all files in acceptable formats in base_dir using gpt2 tokenizer and save them to output_dir

python3 create_tfrecords.py --mode documents --input_dir <base> --name <name> --output_dir <output> --use_gpt2_tokenizer --minimum_size <min> 
  • input_dir: Defines the folder where your data is located. The script will encode all files present in this folder.
  • name: Name of output files will be name_i.tfrecords where i is the number of the file.
  • output_dir: Where to save the tfrecords to
  • use_gpt2_tokenizer: Whether to use the pretrained HuggingFace GPT2 tokenizer, in which case the separator will be set to [50256].
  • encoder_path: if not using the pretrained gpt2 tokenizer, use this flag to provide a path to your generated tokenizer json.
  • separator: Written in list format, the separator token(s) to insert between documents (e.g. "[0]"). Will depend on your encoder.
  • minimum_size: The minimum size (in tokens) a document must have, otherwise it is discarded. This is what will later determine your stitch parameter: stitch * minimum_size must always be greater or equal n_ctx (For more details see the parameters reference section).

4. Using a Dataset in a Model

To use a dataset in a model, you must first register that dataset under ./configs/dataset_configs folder. First choose a filename with a .json extension. That filename will serve as the dataset identification. The config should be filled out the following manner.

If you have a dataset encoded using the pretrained gpt2 tokenizer, you can specify that like so:

json
{
    "n_vocab": 50257,
    "path": "gs://neo-datasets/openwebtext-documents/openwebtext_*.tfrecords",
    "eval_path": "gs://neo-datasets/openwebtext-documents/openwebtext_*.tfrecords",
    "tokenizer_is_pretrained": true,
    "tokenizer_path": "gpt2"
}

or if you've trained a custom tokenizer, like so:

json
{
    "n_vocab": 32768,
    "path": "./path/to/your/*.tfrecords",
    "eval_path": "./path/to/your/eval/*.tfrecords",
    "tokenizer_path": "./path/to/your/byte-level-bpe.tokenizer.json"
}

Finally, in your model config, add the filename that you created above to the datasets array.

The <dataset id> will be the filename, excluding the .json, that you created above

"datasets": [[<dataset id>, <stitch>, <datatype>, <weight>]] # datasets key defines at run time how each dataset is processed for training

5. Choose a model configuration

Once you have your datasets set up, find a suitable config in /configs.

Here we use a GPT3-XL sized model as an example, but there are many more in ./configs, all of which have short summaries in the Available Configs section.

All you need to do is edit the dataset id as described above, and edit model_path (where logs and checkpoints will be saved) to point to a cloud bucket you have write access to (or local path, if using GPUs).

…

6. Run Training

python3 main.py --model <your_config_name> --steps_per_checkpoint <n> --tpu <tpu-name>
  • tpu: Name of the TPU to use.
  • steps_per_checkpoint: The frequency in steps at which to save checkpoints.
  • --auto_layout and --auto_layout_and_mesh_shape (Optional): Disable training and instead auto generate a memory efficient layout (and mesh_shape)
  • gpu_ids: if training using GPUs, omit the tpu flag and pass in the ids of your gpus. In the example below, we train on 3 GPUs, specifying their device ids delimited by spaces:
python3 main.py --model <your_config_name> --steps_per_checkpoint <n> --gpu_ids <device:GPU:0 device:GPU:1>

Available Configs

We have several model sizes available, but some of our configs require large TPUs and will need tweaking to run on smaller machines, or GPUs. Below is a short guide to each model in the configs directory:

TODO

Extra Features:

Training (with Sacred)

Sacred helps track experiments and is much ni

Issues· 15 open

View all issuesOpen on GitHub
  • #323

    Cannot Connect To Local TPU-VM

    bugUpdated Feb 25, 2022
  • #270

    The temperature at 0.0001 (or other arbitrarily small float) is still too high

    bugUpdated Feb 23, 2022
  • #273

    IndexError: index out of range in self

    bugUpdated Feb 9, 2022
  • #272

    TPU device does not support heartbeats.

    bugUpdated Feb 1, 2022
  • #271

    The model should return just the generated text, not the prompt text + generated text.

    feature requestUpdated Jan 24, 2022
  • #269

    Not able to generate predicted text after `Done with copy master to slices.` with 1.3B pre-trained model

    Updated Jan 21, 2022
  • #266

    Argument not a list with same length as devices

    bugUpdated Jan 14, 2022
  • #265

    Links in the readme to the-eye.eu don't work

    bugUpdated Jan 14, 2022
  • #183

    GPT-3 configuration for a v3-32 TPU

    documentationUpdated Mar 31, 2021
  • #156

    Fine-tuning stuck in endless no-op loop at the end

    bugUpdated Mar 30, 2021

> Tags

Pythongptgpt-2gpt-3language-model

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库