gemma-2-2b-it / README.md
IMvision12's picture
Super-squash branch 'main' using huggingface_hub
7ff0f34
|
Raw
History Blame Contribute Delete
3.16 kB
metadata
pipeline_tag: text-generation
license: gemma
base_model: google/gemma-2-2b-it
library_name: kerasformers
extra_gated_heading: Access Gemma on Hugging Face
language:
  - en
tags:
  - keras
  - kerasformers
  - gemma2
  - gemma
  - gemma-2-2b
  - text-generation
  - arxiv:2408.00118
  - pytorch
  - jax
  - tf

See our collection for all Gemma 2 sizes and variants.

Run Gemma 2 with Keras 3: JAX, PyTorch, or TensorFlow

GitHub Docs HuggingFace

kerasformers/gemma-2-2b-it

Pure-Keras 3 conversion of google/gemma-2-2b-it for kerasformers. One implementation runs unmodified on TensorFlow / Torch / JAX. This is the instruction-tuned checkpoint, served here as text -> text via Gemma2TextGenerate; weights are stored in bfloat16.

For model details, license, and usage terms, see Google's model card.

✨ Quick start

import os
os.environ["KERAS_BACKEND"] = "torch"  # or "jax" / "tensorflow"

from kerasformers.models.gemma2 import Gemma2TextGenerate, Gemma2Tokenizer

model = Gemma2TextGenerate.from_weights("kerasformers/gemma-2-2b-it")
tokenizer = Gemma2Tokenizer.from_weights("kerasformers/gemma-2-2b-it")

inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
outputs = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.decode(outputs[0]))

Load any Gemma 2 variant the same way with from_weights("kerasformers/<variant>"):

Tips

  • Set KERAS_BACKEND before importing Keras / kerasformers.
  • Loads in bfloat16 by default. Pass load_dtype="float32" for full precision, or quantization="int8" to shrink further.
  • See the Gemma 2 docs.
  • Community / upstream weights still work via the hf: prefix: Gemma2TextGenerate.from_weights("hf:google/gemma-2-2b-it").

Special Thanks

A huge thank you to the Google Gemma authors for creating and releasing these models.

License: Gemma (gated). Accept the license on the upstream Hub card before downloading.