Large-scale pretraining for dialogue
This repository contains the source code and trained model for a large-scale pretrained dialogue response generation model. The human evaluation results indicate that the response generated from DialoGPT is comparable to human response quality under a single-turn conversation Turing test.
The repository is based on huggingface pytorch-transformer and OpenAI GPT-2, containing data extraction script, model training code and pretrained small (117M) medium (345M) and large (762M) model checkpoint.
The model is trained on 147M multi-turn dialogue from Reddit discussion thread. The largest model can be trained in several hours on a 8 V100 machines (however this is not required), with distributed training and FP16 option.
The include script can be used to reproduce the results of DSTC-7 grounded dialogue generation challenge and a 6k multi-reference dataset created from Reddit data.
Project webpage: https://www.microsoft.com/en-us/research/project/large-scale-pretraining-for-response-generation/
ArXiv paper: https://arxiv.org/abs/1911.00536
(Update 07/09/2022) Changes on the files.pushshift.io/reddit server caused our data generation pipeline to break. These problems have now been fixed, and the steps explained in the Data Preparation subsection below should work again. Data is generated in about 10 hours with 8 processes (-j 8), and 800GB of temporary disk space is needed.
(Update 06/23/2021) We have released a retrieval-augmented/grounded version of DialoGPT (RetGen), please check out the RetGen repo and RetGen paper
(Update 05/20/2021) An awesome video walkthrough on YouTube for DialoGPT by Prakhar Mishra
(Update 03/31/2021) A 3rd party demo by AK391 using Gradio web demo try it out
(Update 09/15/2020) A set of large-scale dialog ranking models has been released!
DialoGPT generation is improved by integrating with our latest dialog ranking models, DialogRPT
(Update 07/08/2020) The 6K multi-ref test set has been released!
To generate the data, pleaser run demo.py and set the data option to 'full', the generated 6k multi-ref test set will be located at
./data/test.refs.txt
(Update 03/10/2020) Model cards available in Huggingface Transformers!
Please check out our model cards in huggingface Transformers repository. With several lines of code it should be pretty straighforward to play with the DialoGPT interactively.
small model: https://huggingface.co/microsoft/DialoGPT-small
medium model: https://huggingface.co/microsoft/DialoGPT-medium
large model: https://huggingface.co/microsoft/DialoGPT-large
(New) Ranking model: https://huggingface.co/microsoft/DialogRPT-updown
(Update 01/06/2020) Some third-party decoding script implementations:
DialoGPT was developed entirely on Ubuntu 16.04, and -- depending on our availability -- we try to provide support if you experience difficulties running the code on the same configuration. However, we are unable to provide support for other distributions or operating systems. Portions of the code may run on other UNIX flavors (macOS, Windows subsystem for Linux, Cygwin, etc.), but it is recommended to use Ubuntu for the main training code.
The training code can be run on CPU, but it can be slow. We would recommend to use GPU to train and finetune all models. There is no minimal limit of the number of GPUs. However, if using distributed train for multiple GPUs configuration, the speed-up vs the number of GPUs is roughly sub-linear. To simulate the same batchsize when using less GPUs, please use a larger gradient_accumulation_steps in model training.
The 117M and 345M model can be loaded in a single GPU with 12G memory. The 762M model would require a single GPU that has greater than 16G memory for efficient training. The training speed on a benchmark data with 50M training instances and V100 GPUs:
| n_gpu | epoch time (h) | token/sec |
|---|---|---|
| 1 | 118 | 10847 |
| 2 | 62 | 20645 |
| 4 | 34 | 37647 |
| 8 | 18 | 71356 |
Fine-tuning from our pretrained model on a new dataset typically requires 1-2 epochs.
We created a demo script demo.py to ease the difficulty of the deployment of this system. The demo.py contains a pipeline of model downloading, data extraction, data preprocessing and model training over a dummy dataset within one commandline.
Please use the below commandlines to clone, install the requirements and load the Conda environment (Note that the Nvidia CUDA 10.0 developer toolkit is required):
sudo apt-get install -y make wget gzip bzip2 xz-utils zstd sedgit clone https://github.com/microsoft/DialoGPT.git
cd DialoGPT
conda env create -f LSP-linux.yml -n LSP
conda activate LSPIf you run this on an architecture other than Linux, please use LSP-generic.yml instead of LSP-linux.yml but please note that the generic one is not tested in all platform, so the stablity can not be gauranteed.
To use fp16 training, please install apex by using commands below
conda activate LSP
git clone https://github.com/NVIDIA/apex
cd apex
git reset --hard 3d01e4a0a188cc8df54bc6e44cf5eb40ff6b4cc5
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" .
python3.6 demo.pyTo start, first install the docker and Nvidia-docker from their official repos. The image environment for running the code can be loaded as below:
Nvidia-docker v2.*
$ docker run --gpus all --ipc=host --rm -it -v $PWD:/workspace --network=host icaruszyz/large-scale-training:dialogpt bashNvidia-docker v1.*
$ nvidia-docker --rm -it -v $PWD:/workspace --network=host icaruszyz/large-scale-training:dialogpt bashInside the docker container, run
python demo.pyThis section explains all components in the demo.py.
Before running demo.py, you can set DATA_FOLDER (default value ./models) in demo.py as the place you want to download all the data and pretrained/fine-tuned models. Then simply run
python demo.pyto
Note that by default the demo.py will use a dummy data, please specify the Reddit training data by using option --data. Three options are available:dummy,small and full.
python demo.py --data small
python demo.py --data fullThe small Reddit data is around 140MB and the full Reddit data is more than 27GB. You can prepare a cup of coffee when processing with the full Reddit data because it takes a long time!
To generate the 6k multi-ref test set data, pleaser run demo.py and set the data option to 'full', the generation will be located at
./data/test.refs.txt
The pretrained and fine-tuned models are available on azure blobstorage.
Please run/see demo.py for more details about how to download/use those models. Or you could download directly by using the links in demo_utils.py.
First, use the prepare4db.sh to convert a tsv data file into the correct format that the following script can recognize.
The trainig data need to be then processed into a database file with below commandline:
python prepro.py --corpus $DATA_PATHThe training script can be used in single GPU or multiple GPU settings (distributed training across multiple GPUs within a single node):
python ./LSP_train.py # Single GPU training
python -m torch.distributed.launch --nproc_per_node=8 ./LSP_train.py # Training on 8 GPUsThe training script accept several arguments to tweak the training:
| Argument | Type | Default value | Description |
|---|---|---|---|
| max_seq_length | int |
128 |
Maximum number of tokens for each training instance. |
| train_input_file | str |
"" |
Path of the training dataset in a .db format |
| eval_input_file | str |
"" |
Path of the validation set in a tsv format |
| continue_from | int |
0 |
Resuming the training after a specified number of steps |
| fp16 | boolean |
True |
Whether to use 16-bits floating point for model training. |
| train_batch_size | int |
4 |
Batch size for training |
| valid_batch_size | int |
4 |
Batch size for validation |
| gradient_accumulation_steps | int |
2 |
Accumulate gradients on several steps |
| learning_rate | float |
1e-5 |
Learning rate |
| lr_schedule | str |
`n |
No open issues yet, or sync has not completed.