Instructions to use kerasformers/gemma-4-31b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use kerasformers/gemma-4-31b with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use kerasformers/gemma-4-31b with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://kerasformers/gemma-4-31b") - Notebooks
- Google Colab
- Kaggle
Add Gemma4TextGenerate text-only usage example
Browse files
README.md
CHANGED
|
@@ -47,6 +47,24 @@ For model details, license, and usage terms, see Google's
|
|
| 47 |
|
| 48 |
## ✨ Quick start
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
```python
|
| 51 |
import os
|
| 52 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
|
|
|
| 47 |
|
| 48 |
## ✨ Quick start
|
| 49 |
|
| 50 |
+
### Text-only
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
import os
|
| 54 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 55 |
+
|
| 56 |
+
from kerasformers.models.gemma4 import Gemma4TextGenerate, Gemma4Tokenizer
|
| 57 |
+
|
| 58 |
+
model = Gemma4TextGenerate.from_weights("kerasformers/gemma-4-31b")
|
| 59 |
+
tokenizer = Gemma4Tokenizer.from_weights("kerasformers/gemma-4-31b")
|
| 60 |
+
|
| 61 |
+
inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
|
| 62 |
+
outputs = model.generate(**inputs, max_new_tokens=64)
|
| 63 |
+
print(tokenizer.decode(outputs[0]))
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### Image + text
|
| 67 |
+
|
| 68 |
```python
|
| 69 |
import os
|
| 70 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|