Instructions to use kerasformers/qwen2-7b-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use kerasformers/qwen2-7b-instruct 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/qwen2-7b-instruct 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/qwen2-7b-instruct") - Notebooks
- Google Colab
- Kaggle
See our collection for all Qwen2 versions.
Run Qwen2 with Keras 3: JAX, PyTorch, or TensorFlow
kerasformers/qwen2-7b-instruct
Qwen2 is Alibaba's decoder-only transformer family: grouped-query attention with q/k/v bias, SwiGLU MLPs, RMSNorm, and rotary positions, in dense 0.5B-72B sizes (plus the Qwen2-57B-A14B mixture-of-experts), as base and instruct variants.
For more details on the model, please see the upstream model card.
Pure-Keras 3 conversion of Qwen/Qwen2-7B-Instruct for kerasformers. One implementation runs unmodified on TensorFlow / Torch / JAX.
This is an instruct (chat-tuned) checkpoint; load Qwen2Tokenizer so the chat template is applied.
Quick start
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from kerasformers.models.qwen2 import Qwen2Generate, Qwen2Tokenizer
model = Qwen2Generate.from_weights("kerasformers/qwen2-7b-instruct")
tokenizer = Qwen2Tokenizer.from_weights("kerasformers/qwen2-7b-instruct")
inputs = tokenizer([
{"role": "user", "content": "Explain rotary embeddings in one sentence."}
])
outputs = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.decode(outputs[0]))
Load any Qwen2 variant the same way with from_weights("kerasformers/<variant>"):
| Variant | Hub | Type |
|---|---|---|
qwen2-0.5b |
kerasformers/qwen2-0.5b |
base |
qwen2-0.5b-instruct |
kerasformers/qwen2-0.5b-instruct |
instruct |
qwen2-1.5b |
kerasformers/qwen2-1.5b |
base |
qwen2-1.5b-instruct |
kerasformers/qwen2-1.5b-instruct |
instruct |
qwen2-7b |
kerasformers/qwen2-7b |
base |
qwen2-7b-instruct |
kerasformers/qwen2-7b-instruct |
instruct |
qwen2-72b |
kerasformers/qwen2-72b |
base |
qwen2-72b-instruct |
kerasformers/qwen2-72b-instruct |
instruct |
qwen2-57b-a14b |
kerasformers/qwen2-57b-a14b |
MoE base |
qwen2-57b-a14b-instruct |
kerasformers/qwen2-57b-a14b-instruct |
MoE instruct |
qwen1.5-moe-a2.7b |
kerasformers/qwen1.5-moe-a2.7b |
MoE base |
qwen1.5-moe-a2.7b-chat |
kerasformers/qwen1.5-moe-a2.7b-chat |
MoE chat |
Tips
- Set
KERAS_BACKENDbefore importing Keras / kerasformers. - Prefer
Qwen2Tokenizer.from_weights(...)so the chat template matches. - Larger checkpoints: try
load_dtype="bfloat16"orquantization="int8". - See Loading Weights and the Qwen2 docs.
- Community / upstream safetensors still work via the
hf:prefix, e.g.Qwen2Generate.from_weights("hf:Qwen/Qwen2-7B-Instruct").
Special Thanks
A huge thank you to the Qwen team at Alibaba for creating and releasing these models.
License: Apache 2.0.
- Downloads last month
- 16