pypi Keras 3.16.0
Keras 3.16.0

one hour ago

Keras 3.16.0 Release Notes

PyPI Downloads Python Diff

638

PULL REQUESTS

108

CONTRIBUTORS

81

FIRST-TIME CONTRIBUTORS

9

NEW OPS

40+

BACKEND-AGNOSTIC OPS

2

NEW LAYERS
🔌
Pluggable Backends
backends as separate packages
🔢
x64 Mode
opt-in 64-bit dtypes
🚀
XLA SavedModel Export
JAX to XLA Serving Engine
⚡
Faster Training Loops
steps_per_execution on JAX & PyTorch
🪶
Quantization
ternary · 2-bit packing · GPTQ / AWQ
🧮
New Ops
grad · cov · matrix_power · lgamma
🧵
PyTorch Distribution
data parallel · model parallel
🔥
torch.compile Friendly
fewer graph breaks
🧪
TensorFlow-free Groundwork
JAX CI without TensorFlow
🖼️
New Layers & Losses
TernaryDense · Mosaic · sparse focal
☁️
Remote Paths
gs:// without TensorFlow
🛡️
Security Hardening
safer loading and deserialization

Highlights

🔌 Pluggable Backends

Keras backends no longer have to live inside the keras package. A backend can now ship as its own keras_<name> package and is loaded when KERAS_BACKEND names it, while jax, numpy, tensorflow and torch stay built in. (#23795, #23770, #23642, #24447)

  • OpenVINO is now a pluggable backend. It has moved out of this repository into keras-team/keras-openvino. (#23858)
  • MLX is a recognized pluggable backend through the keras-mlx package. (#23795, #24444)
  • Install extras: pip install "keras[openvino]" and pip install "keras[mlx]" pull in the matching 3.16.* backend package. (#24444)
  • Bring your own backend: set KERAS_ALLOW_UNOFFICIAL_BACKEND=1 to load any keras_<name> package as a backend, for developing and testing new ones against a standard Keras install. (#24232)
# pip install "keras[openvino]"
import os

os.environ["KERAS_BACKEND"] = "openvino"

import keras

🔢 64-bit dtype control with x64_mode

A new setting decides whether 64-bit inputs keep 64-bit results. Set it with keras.config.set_x64_mode(), the KERAS_X64_MODE environment variable, or the "x64_mode" field of keras.json. (#24047, #24265, #24270, #24302, #24307, #24308, #24147)

  • "off" is the default on JAX, NumPy and PyTorch: results are capped to 32-bit.
  • "explicit_x64" is the default and only mode on TensorFlow: a 64-bit input gives a 64-bit output, while 32-bit inputs, Python scalars and default dtypes stay 32-bit. On JAX it requires JAX 0.8.0 or newer.
  • "enable_x64" is reserved and not supported yet.
keras.config.set_x64_mode("explicit_x64")
x = keras.ops.ones((2,), "int64")
keras.ops.add(x, x).dtype  # int64

🚀 XLA SavedModel export

model.export(path, format="xla_saved_model") exports a model on the JAX backend to the XLA Serving Engine format. It requires the xla-saved-model package. (#24143, #24097)

⚡ Faster multi-step training loops

  • On JAX, steps_per_execution > 1 with jit_compile=True now runs the steps on-device with jax.lax.scan, with one host dispatch per group of steps. (#23527)
  • The PyTorch backend now supports steps_per_execution > 1. (#23234)
  • steps_per_execution handling was optimized across backends. (#23305)

🪶 Quantization

  • keras.layers.TernaryDense: a dense layer trained with weights constrained to {-1, 0, +1}, which can be frozen to packed ternary weights with layer.quantize("ternary"). (#22960, #23758, #23906, #23909)
  • New public helpers: keras.quantizers.TernaryQuantizationConfig, QuantizationReport, and the pack_int2 / unpack_int2 / pack_ternary / unpack_ternary codecs. (#22960, #23345, #23470)
  • model.quantize() is observable and fail-safe. (#23345)
  • GPTQ and AWQ reworked: batched calibration with a Cholesky inverse-Hessian, AWQ aligned with the reference implementation, one-step quantization without a pending state, and calibration of third-party layers that declare support. (#23481, #23478, #24174, #24221, #24237, #24015, #24057)
  • One quantization protocol across layers: Dense, EinsumDense, Embedding, ReversibleEmbedding and TernaryDense now share a geometry protocol and a strategy registry. (#23521, #23591, #23606, #23630, #23758)

New Features

Ops

  • keras.ops.grad (experimental): returns a function computing the gradient of f, on backends with automatic differentiation. (#23670)
  • keras.ops.cov, keras.ops.matrix_power, keras.ops.column_stack, keras.ops.copysign, keras.ops.float_power, keras.ops.lgamma and keras.ops.gammainc. (#23494, #23227, #23153, #23498, #23500, #23541, #23549, #23365)
  • keras.ops.image.reconstruct_patches: the inverse of extract_patches, with channels_first support, inferred output_size for padding="valid", and overlapping patches. (#22984, #23267, #23319, #23930)
  • keras.ops.top_k accepts is_stable. (#23367)
  • keras.ops.linalg.norm accepts a list for axis. (#23721)
  • keras.ops.in_top_k supports multi-dimensional inputs. (#23232)
  • keras.ops.cross supports 2-D vectors on PyTorch and JAX. (#23801, #23769)
  • keras.ops.image.resize supports Lanczos interpolation on PyTorch. (#23792)
  • TensorFlow convolutions support strides > 1 together with dilation_rate > 1. (#23181)

Layers and losses

  • keras.layers.Mosaic: a mosaic image augmentation layer. (#23963)
  • keras.losses.SparseCategoricalFocalCrossentropy and keras.losses.sparse_categorical_focal_crossentropy. (#23482)
  • label_smoothing in SparseCategoricalCrossentropy. (#23488)
  • Layer.add_weight accepts a layout argument. (#24058)
  • adapt() shows a progress bar, and in Discretization, IndexLookup and TextVectorization it now takes the inputs from (x, y) batches, such as those yielded by a PyDataset. (#22971, #23362, #23440)
  • keras.layers.GroupedQueryAttention is now the canonical name, with GroupQueryAttention kept as an alias. (#23905)

Saving and data

  • keras.saving.load_model accepts file objects (io.IOBase). (#23873)
  • ModelCheckpoint supports remote paths. (#24092)
  • Remote paths such as gs:// work without TensorFlow through the new gcs extra: pip install "keras[gcs]". (#24020, #24098, #24081)
  • audio_dataset_from_directory supports Grain. (#23224)

Distribution on PyTorch

  • Data parallel and model parallel training on the PyTorch backend, with DTensor support for Keras variables and distribution utilities. (#23316, #23402, #23404, #23366, #23052, #23403)
  • Multi-process sharding for Torch DataLoader, PyDataset and NumPy adapters. (#23045, #23044, #23046)
  • jit_compile=True works under torch DataParallel. (#23948)

Backend-agnostic Ops and TensorFlow-free Groundwork

  • More than 40 ops gained a backend-agnostic implementation, including the nan* reductions, the split and stack family, window functions, correlate, corrcoef, histogram and argpartition. The TensorFlow backend now uses several of them directly. (#23643, #23854, #23925, #24041, #24131, #24344, #24367, #24443)
  • A CI job runs the JAX tests with TensorFlow uninstalled, to catch new TensorFlow dependencies outside the TensorFlow backend. (#24145)
  • The TensorBoard callback works without TensorFlow: when TensorFlow is not installed, it writes scalars, the model summary, histograms and images with tensorboardX. (#24198, #24238)
  • A new OpTest harness checks each op across input dtypes, 64-bit dtypes, floatx settings, the backend JIT, functional models and gradients. (#23970, #24187, #24212, #24230, #24240, #24266, #24277)

Performance

  • PyTorch: removed torch.compile graph breaks in model compilation, dot_product_attention, BatchNormalization, UnitNormalization, SGD and Adadelta; channels_last pooling; a direct path for pointwise convolutions; vectorized scatter for a much faster MeanIoU; a GPU memory leak fixed in tree utilities. (#23744, #23327, #24083, #24159, #23949, #23645, #23178, #23196, #23111)
  • Layer call overhead: faster input compatibility checks, a single name scope per call, cheaper dtype standardization, and traceback argument info built only on error. (#23184, #23301, #23200, #23183, #23182)
  • Data: no tensor copies when using a tf.data.Dataset with JAX or NumPy. (#24291)
  • Normalization: backends can provide fused RMS and layer normalization. (#23510)

Security

  • Restricted unpickling when loading the IMDB, Reuters and CIFAR datasets, and pinned SHA-256 hashes for Fashion-MNIST. (#23047, #23252, #24036)
  • Rejected decompression bombs in .keras asset extraction, the remaining zip readers and KerasFileEditor. (#23101, #23212, #23303)
  • Verified all intermediary H5 groups when navigating H5 files, and validated the file name derived from origin in get_file. (#23168, #23330)
  • Rejected classes when deserializing a function config, and excluded visualization utilities from modeling API deserialization. (#24369, #24023)
  • Removed unsupported NPZ weight storage and consolidated ZIP validation. (#23655)

Breaking and Behavior Changes

  • OpenVINO is no longer bundled. Install it with pip install "keras[openvino]". (#23858, #24444)
  • Minimum PyTorch version is now 2.6.0. (#24048)
  • 64-bit inputs are now treated as 32-bit by default on JAX, NumPy and PyTorch (x64_mode="off"), for example an int64 tensor passed to an op gives int32. Set x64_mode="explicit_x64" to keep them. If you set JAX's own 64-bit flags yourself and they do not match x64_mode, Keras warns. (#24308, #24047)
  • .keras archives with NPZ weights no longer load. The unsupported model.weights.npz storage was removed. (#23655)
  • keras.ops.size returns a Python int on every backend. (#23496)
  • keras.ops.layer_normalization no longer accepts arbitrary keyword arguments. (#24278)
  • Integer inputs are promoted to float in activations and math ops such as leaky_relu, hard_sigmoid, hard_silu, selu, softsign, sigmoid, softmax, erf, erfinv and rsqrt. (#23608, #23545, #23639, #23853, #24163, #24321, #24322)
  • RNN layers no longer propagate masks automatically, which fixes a CTC loss dimension mismatch. (#23235)
  • TensorFlow: jit_compile=True under a multi-replica tf.distribute strategy now warns and falls back to jit_compile=False, and keras.ops.mean no longer upcasts float16 and bfloat16 to float32. (#24301, #23802)
  • Stricter argument validation now raises on invalid values for RMSprop and Adadelta rho, Adagrad initial_accumulator_value, BatchNormalization momentum, GroupNormalization epsilon, Huber delta, loss label_smoothing and EarlyStopping patience. (#23676, #23677, #23624, #23623, #23675, #23573, #23504, #23559)

Bug Fixes and Improvements

  • Losses and metrics: fixed the alpha and beta swap in Tversky loss, R2Score on zero-variance data and its sample count, IoU.result with a non-last axis, FBetaScore sample weights, and losses dropping delta or axis on serialization. (#23333, #23420, #23334, #23668, #23335, #23286)
  • Layers: fixed RandomCrop bounding box offsets, Bidirectional output shape with an asymmetric backward layer, attention weights for fully masked rows, beta in layer and group normalization for large inputs, and Functional models accepting inputs with a mismatched last axis or dict inputs with extra keys. (#23519, #23687, #23902, #23782, #23924, #23920, #23261)
  • Saving: fixed Sequential.from_config variable paths so Orbax checkpoints restore weights, function serialization on Windows, Layer path reconstruction on reload, and compile config mutation during HDF5 save. (#24055, #23631, #24087, #23475, #23870)
  • PyTorch: fixed lstsq on GPU, linspace and logspace end points and num=1, symmetric padding, cross default axis, stateful GRU and LSTM cuDNN backward, float64 on MPS, and ONNX export with dynamic shapes. (#24146, #24305, #24236, #23230, #23219, #23464, #23701, #23058)
  • TensorFlow: fixed rot90 for non-square arrays, unravel_index order, searchsorted for multi-dimensional values, tril and triu with out-of-range k, map_coordinates mirror and reflect modes, and exact floor_divide for floats. (#23435, #23434, #23436, #24070, #24014, #23938, #24056)
  • JAX: fixed window ops under jax.jit, StopIteration during validation on empty datasets, and 64-bit NumPy data in fit, evaluate and predict. (#24337, #23690, #24147)
  • NumPy 2.x and Python 3.14 compatibility fixes. (#24242, #24275, #23408, #23259)

CI & Infrastructure

  • Releases publish to PyPI through OIDC trusted publishing. (#23557)
  • GPU and TPU tests are split into four shards and triggered by a one-shot run-gpu-tpu-tests label. (#24144, #23857)
  • master now carries a .dev0 version between releases. (#24347)
  • The import test flow runs against the installed wheel. (#24458)
  • CPU tests moved to a reusable workflow on linux-x86-n4-16 runners, and auto-assignment, stale and Zizmor checks moved to shared workflows. (#23572, #24062, #23471, #24178, #24179)

Contributors

We would like to thank all contributors for this release: @2sumtech, @AbdulAliMamnun, @ahlag, @andersendsa, @andife, @Andreas-Hum, @anishmehta24, @aswanth-07, @Ayoubhm07, @Bratet, @brianmanderson, @buildwithsuhana, @bzantium, @calad0i, @ChiragSW, @CodingSelim, @DavidAriOstenfeldt, @davidtungy, @Deeven-Seru, @devs6186, @DisturbedCrow, @divyashreepathihalli, @FactualExplorer, @fchollet, @fhchl, @gaga1313, @GargiGupta-io, @gaurav-gandhi-2411, @GodlyDonuts, @goyaladitya05, @hertschuh, @iezepov, @ILCSFNO, @indrajeetapache, @IshaanPotle, @ishitta-iyer, @james77777778, @jayzuccarelli, @jdymitarai, @jeffcarp, @jerryxyj, @jjdev11, @JyotinderSingh, @Kaif10, @KaiOnCode, @kaivalya-cyber, @karpovantonme, @laxmareddyp, @lequangdung2005, @LinZiyuu, @MaddipatlaChetan24, @madhanalagarsamy, @maitry63, @marco-trotta1, @MarcosAsh, @mayankdas2005, @mncrftfrcnm, @mohammadmseet-hue, @mr-field, @mrinalghoshh, @MrNagabhushana-0-dev, @Nanduu24, @Neilblaze, @Nicholas022400701, @Noxtimo, @nurulgofran, @Osamaali313, @pandeylakshya207-max, @patminn107, @pctablet505, @peinguim, @Phoebus-Liu, @princemittalr, @priyankn, @Priyanshu-byte-coder, @pwuertz, @rootkiller6788, @rstar327, @SABITHSAHEB, @SamanehSaadat, @samudraneel05, @sandeepvijayarao09, @SEPURI-SAI-KRISHNA, @SharadhNaidu, @shashaka, @Shi-pra-19, @Sid-5137, @SID-6921, @simeon-kepp, @Snakinya, @sohumt123, @sugata100, @tandede, @TheManishCode, @UgaTheDev, @ujwalreddybattu04, @usmanmateen, @utsab345, @Vansh-Sharmaa, @vera-rubin, @VimalN2005, @Viranshul-P, @vishwakt, @vnayakde, @vruotolo, @winklemad, @yeti107, @zuccamia.

New Contributors

81 people made their first contribution in this release

Full Changelog: v3.15.0...v3.16.0

Don't miss a new Keras release

NewReleases is sending notifications on new releases.