DeBERTa Documentation

repository·master·Indexed 24 days ago

https://github.com/microsoft/deberta

An advanced transformer model improving upon BERT and RoBERTa using disentangled attention and an enhanced mask decoder. This repository provides tools for pre-training with Masked Language Modeling (MLM) and Replaced Token Detection (RTD), fine-tuning on GLUE, RACE, and AlphaNLI datasets, and implementing Scale Invariant Fine-Tuning (SiFT). It includes support for ONNX export, quantization, distributed training across multiple nodes, and integration with PyTorch via the deberta.DeBERTa class.

Tokens
9.1K
Snippets
9
Records
68
Agent score
78%

What's inside DeBERTa

  1. Export model to ONNX format and quantization

    master

    During evaluation, you can export the model to ONNX format using the --export_ort_model flag. You can also generate quantized models by controlling the --fp16 flag.

    Export Options

    • Standard ONNX export: Use --export_ort_model True.
    • Quantized model export: Use --fp16 False --export_ort_model True.

    Output File Naming

    Exported models are saved in the output folder with the following naming convention based on the <prefix>:

    • If fp16 is True: <prefix>__onnx_fp16.bin
    • If fp16 is False: <prefix>__onnx_fp32.bin and <prefix>__onnx_qt.bin
  2. Pre-train with Replaced Token Detection (RTD)

    master

    To train an ELECTRA-like model using the Replaced Token Detection task, use the rtd.sh script. Available DeBERTaV3 configurations include:

    • deberta-v3-xsmall: 9M backbone parameters (12 layers, 256 hidden size) + 32M embedding parameters (128k vocabulary).
    • deberta-v3-base: 81M backbone parameters (12 layers, 768 hidden size) + 96M embedding parameters (128k vocabulary).
    • deberta-v3-large: 288M backbone parameters (24 layers, 1024 hidden size) + 128M embedding parameters (128k vocabulary).
  3. Continuously train with Replaced Token Detection

    master

    You can perform continuous training on DeBERTaV3-X models by using the -continue suffix. You must check the rtd.sh script to specify the initialization models for both the generator and the discriminator.

    Common checkpoint sources for continuous training include Hugging Face repositories for deberta-v3-xsmall, deberta-v3-small, and deberta-v3-large.

  4. Install DeBERTa dependencies from source

    master

    If you have pulled the repository source code, you can install the required dependencies using pip:

    1. Run pip3 install -r requirements.txt from the root directory.
    2. Navigate to experiments/glue/ to run GLUE experiments.
    pip3 install -r requirements.txt
  5. Run fine-tuning experiments for GLUE tasks

    master

    You can run fine-tuning experiments for various GLUE benchmark tasks using the provided shell scripts in the experiments/glue/ directory. The scripts take the model size/variant as an argument.

    Example commands for the Large model:

    • MNLI xxlarge v2: experiments/glue/mnli.sh xxlarge-v2
    • QQP large: experiments/glue/qqp.sh large
    • CoLA large: experiments/glue/cola.sh

    Note: Results may vary based on GPU models, drivers, CUDA versions, precision (FP16 vs FP32), and random seeds.

  6. Run SiFT experiments via shell scripts

    master

    You can run pre-configured SiFT experiments for DeBERTa by executing the provided shell scripts in the experiments/glue/ directory.

    Examples:

    • For a base model: experiments/glue/mnli.sh base-sift
    • For an xxlarge-v2 model: experiments/glue/mnli.sh xxlarge-v2-sift
  7. Run DeBERTa using Docker

    master

    Docker is the recommended way to run DeBERTa as all dependencies are pre-built in the bagai/deberta image.

    To run GLUE experiments with Docker:

    1. Pull the code.
    2. Run ./run_docker.sh.
    3. Execute bash commands located under /DeBERTa/experiments/glue/ within the container.
    ./run_docker.sh
  8. Pre-train DeBERTa with MLM and RTD objectives

    master
    To perform pre-training using Masked Language Modeling (MLM) or Replaced Token Detection (RTD) objectives, refer to the instructions and implementation located in the experiments/language_models directory.