SuperAPIAI Directory

recurrentgemma

github.com · AI developer platforms

RecurrentGemma is a series of open-weight language models released by Google DeepMind, based on the novel Griffin architecture. This architecture replaces global attention with a hybrid mechanism of local attention and linear recurrence, thereby achieving fast inference when generating long sequences. This repository contains the model implementation as well as example code for sampling and fine-tuning. The official recommendation is for most users to use the highly optimized Flax implementation, while an unoptimized PyTorch reference implementation is also provided. Model checkpoints can be downloaded via Kaggle and include weights and tokenizer. The code supports running on CPU, GPU, or TPU; the Flax implementation is optimized for TPU and includes low-level Pallas kernels for linear scans of recurrent layers. The project uses Poetry to manage dependencies and provides Colab tutorials covering sampling and fine-tuning.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

Purpose

RecurrentGemma is a series of open-weight language models introduced by Google DeepMind, based on the novel Griffin architecture. By replacing global attention with a hybrid of local attention and linear recurrence, this architecture achieves fast inference when generating long sequences. It is suitable for scenarios that require long-sequence generation and emphasize inference efficiency, such as text generation, translation, and other tasks.

Main Capabilities

  • Provides open-weight language models based on the Griffin architecture.
  • Includes the model implementation as well as example code for sampling and fine-tuning.
  • The official recommendation is to use the highly optimized Flax implementation, while an unoptimized PyTorch reference implementation is also provided.
  • Supports running on CPU, GPU, or TPU; the Flax implementation is optimized for TPU and includes low-level Pallas kernels for linear scans of recurrent layers.

Usage

Install Dependencies

The project uses Poetry to manage dependencies. Full installation steps:

  1. Check out the code.
  2. Run poetry install -E full to create a virtual environment containing all dependencies.
  3. Run poetry shell to activate the virtual environment.

If only some dependencies are needed, the following alternative commands can be used:

  • If using pip instead of Poetry, first create a virtual environment (python -m venv recurrentgemma-demo and source recurrentgemma-demo/bin/activate), then run pip install .[full].
  • Install only the JAX path dependencies:poetry install -E jax or pip install .[jax].
  • Install only the PyTorch path dependencies:poetry install -E torch or pip install .[torch].
  • Install the dependencies required to run unit tests:poetry install -E test or pip install .[test].

Download the Model

Model checkpoints can be obtained via Kaggle:http://kaggle.com/models/google/recurrentgemma。选择 For the Flax or PyTorch model variant, click the download button to download the model archive, then extract it to a local directory. The archive contains the model weights and tokenizer.

Run Unit Tests

At the root of the source tree, install the [test] optional dependencies (such as pip install .[test]), then run the tests.

Run the Sampling Script

Pass the paths to the weights directory and tokenizer to run the example sampling script.

Colab Tutorials

  • colabs/sampling_tutorial_jax.ipynb: Sampling example using JAX.
  • colabs/sampling_tutorial_pytorch.ipynb: Sampling example using PyTorch.
  • colabs/fine_tuning_tutorial_jax.ipynb: A basic tutorial on fine-tuning RecurrentGemma using JAX, for example an English-French translation task.

Running these notebooks requires a Kaggle account, and you must first read and accept the Gemma license terms on the RecurrentGemma page. After that, the weights and tokenizer will be automatically downloaded when running the notebook. Currently, detailed information on the hardware supported by the different notebooks is not provided.

Use cases

  • Language model applications that require efficient generation of long sequences.
  • Academic research or experiments exploring the novel Griffin architecture.
  • Fine-tuning based on an open-weights model to adapt to a specific task.

Limitations

  • The PyTorch implementation in the repository has not been optimized and is for reference only.
  • Use of the model is subject to the Gemma license terms.
  • Currently, detailed information on the hardware supported by the different Colab notebooks is not provided.
  • This project is not an official Google product.

License

The code is licensed under the Apache License 2.0. Copyright 2024 DeepMind Technologies Limited.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools