Highlights
Keras has a new model distillation API!
You now have access to an easy-to-use API for distilling large models into small models while minimizing performance drop on a reference dataset -- compatible with all existing Keras models. You can specify a range of different distillation losses, or create your own losses. The API supports multiple concurrent distillation losses at the same time.
Example:
# Load a model to distill
teacher = ...
# This is the model we want to distill it into
student = ...
# Configure the process
distiller = Distiller(
teacher=teacher,
student=student,
distillation_losses=LogitsDistillation(temperature=3.0),
)
distiller.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
# Train the distilled model
distiller.fit(x_train, y_train, epochs=10)Keras supports GPTQ quantization!
GPTQ is now built into the Keras API. GPTQ is a post-training, weights-only quantization method that compresses a model to int4 layer by layer. For each layer, it uses a second-order method to update weights while minimizing the error on a calibration dataset.
Learn how to use it in this guide.
Example:
model = keras_hub.models.Gemma3CausalLM.from_preset("gemma3_1b")
gptq_config = keras.quantizers.GPTQConfig(
dataset=calibration_dataset,
tokenizer=model.preprocessor.tokenizer,
weight_bits=4,
group_size=128,
num_samples=256,
sequence_length=256,
hessian_damping=0.01,
symmetric=False,
activation_order=False,
)
model.quantize("gptq", config=gptq_config)
outputs = model.generate(prompt, max_length=30)Better support for Grain datasets!
- Add Grain support to
keras.utils.image_dataset_from_directoryandkeras.utils.text_dataset_from_directory. Specifyformat="grain"to return a Grain dataset instead of a TF dataset. - Make almost all Keras preprocessing layers compatible with Grain datasets.
New features
- Add
keras.layers.ReversibleEmbeddinglayer: an embedding layer that can also also project backwards to the input space. Use it with thereverseargument incall(). - Add argument
opset_versioninmodel.export(). Argument specific toformat="onnx"; specifies the ONNX opset version. - Add
keras.ops.isinop. - Add
keras.ops.isneginf,keras.ops.isposinfops. - Add
keras.ops.isrealop. - Add
keras.ops.cholesky_inverseop and addupperargument inkeras.ops.cholesky. - Add
keras.ops.image.scale_and_translateop. - Add
keras.ops.hypotop. - Add
keras.ops.gcdop. - Add
keras.ops.kronop. - Add
keras.ops.logaddexp2op. - Add
keras.ops.viewop. - Add
keras.ops.unfoldop. - Add
keras.ops.jvpop. - Add
keras.ops.trapezoidop. - Add support for over 20 news ops with the OpenVINO backend.
Breaking changes
- Layers
StringLookup&IntegerLookupnow save vocabulary loaded from file. Previously, when instantiating these layers from a vocabulary filepath, only the filepath would be saved when saving the layer. Now, the entire vocabulary is materialized and saved as part of the.kerasarchive.
Security fixes
- Fix two vulnerabilities related to adversarial saved files loaded with
safe_mode: CVE-2025-12058 and CVE-2025-12060.
New Contributors
- @WIgor made their first contribution in #21432
- @ILCSFNO made their first contribution in #21563
- @samthakur587 made their first contribution in #21524
- @buildwithsuhana made their first contribution in #21554
- @MCCbena made their first contribution in #21569
- @amitsrivastava78 made their first contribution in #21551
- @Ma-gi-cian made their first contribution in #21614
- @arunthakur009 made their first contribution in #21600
- @vpratz made their first contribution in #21615
- @miguelteixeiragomes made their first contribution in #21650
- @Flakes342 made their first contribution in #21646
- @TRNWWZ made their first contribution in #21671
- @danielenricocahall made their first contribution in #21738
- @utsab345 made their first contribution in #21721
- @wenyi-guo made their first contribution in #21763
- @SamKnightGit made their first contribution in #21782
Full Changelog: v3.11.0...v3.12.0