Skip to main content

Installation

To begin using the GLiClass model, you can install the GLiClass Python library through pip, conda, or directly from the source.

Install via Pip

pip install gliclass

Install from Source

To install the GLiClass library from source, follow these steps:

  1. Clone the Repository:

    First, clone the GLiClass repository from GitHub:

    git clone https://github.com/Knowledgator/GLiClass
  2. Navigate to the Project Directory:

    Change to the directory containing the cloned repository:

    cd GLiClass
  3. Install Dependencies:

    tip

    It's a good practice to create and activate a virtual environment before installing dependencies:

    python -m venv venv
    source venv/bin/activate # On Windows use: venv\Scripts\activate
  4. Install the GLiNER Package:

    Finally, install the GLiClass package using:

    pip install -U .
    tip

    Use pip install -U -e . to install in editable mode

  5. Verify Installation:

    You can verify the installation by importing the library in a Python script:

    import gliclass
    print(gliclass.__version__)

Optional Accelerators

GLiClass supports optional flash attention backends for enhanced performance with specific model types.

FlashDeBERTa (for DeBERTa v2 models)

For accelerated inference with DeBERTa v2 models, install FlashDeBERTa:

pip install flashdeberta

When available, DeBERTa v2 models automatically use FlashDebertaV2Model instead of the standard implementation.

To explicitly enable FlashDeBERTa:

export USE_FLASHDEBERTA=1

TurboT5 (for T5/mT5 models)

For accelerated inference with T5 and mT5 models, install TurboT5:

pip install turbot5

When available, T5 and mT5 models automatically use FlashT5EncoderModel.

To activate TurboT5:

export TURBOT5_ATTN_TYPE=triton-basic
note

Both accelerators are optional and activate automatically when installed. No code modifications are required to benefit from the performance improvements.