Registry / ai-ml / keras-tuner

keras-tuner

JSON →
library1.4.8pypypiunverified

KerasTuner is a hyperparameter optimization library for Keras, making it easy to find the best hyperparameters for your machine learning models. It supports various tuning algorithms like RandomSearch, Hyperband, and BayesianOptimization. The library is actively maintained and frequently updated, with recent versions adding support for Keras 3 (multi-backend) and improving distributed execution.

pip install keras-tuner
INSTALL
IMPORT
SIG · KERAS-TUNER
K
keras-tuner
ai-mlpythonv1.4.8
Install
20.0s avg
Import
19234ms
Disk
2150MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
4/8 runs
✓ 21s
py 3.11
4/8 runs
✓ 19.13s
py 3.12
4/8 runs
✓ 17.84s
py 3.13
4/8 runs
✓ 17.61s
py 3.9
4/8 runs
✓ 24.46s
2150MB installed
● package 2150MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HyperModel
from keras_tuner import HyperModel
from keras_tuner import HyperModel

This quickstart demonstrates how to use KerasTuner with a `HyperModel` to search for optimal hyperparameters for a simple Keras model on the Fashion MNIST dataset. It defines a model with tunable dense layer units and learning rate, then uses `RandomSearch` to find the best configuration.

import keras import keras_tuner as kt import numpy as np # Define a HyperModel class MyHyperModel(kt.HyperModel): def build(self, hp): model = keras.Sequential() model.add(keras.layers.Flatten(input_shape=(28, 28))) model.add(keras.layers.Dense(units=hp.Int('units', min_value=32, max_value=512, step=32), activation='relu')) model.add(keras.layers.Dense(10, activation='softmax')) model.compile(optimizer=keras.optimizers.Adam(hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])), loss='sparse_categorical_crossentropy', metrics=['accuracy']) return model # Load dummy data (Fashion MNIST) (x_train, y_train), (x_test, y_test) = keras.datasets.fashion_mnist.load_data() x_train = x_train[:10000].astype('float32') / 255.0 y_train = y_train[:10000] x_val = x_test[:2000].astype('float32') / 255.0 y_val = y_test[:2000] # Instantiate a tuner tuner = kt.RandomSearch( MyHyperModel(), objective='val_accuracy', max_trials=3, executions_per_trial=2, directory='my_dir', project_name='my_intro_to_kt' ) # Search for the best hyperparameters tuner.search(x_train, y_train, epochs=2, validation_data=(x_val, y_val)) # Get the best hyperparameters best_hps = tuner.get_best_hyperparameters(num_trials=1)[0] print(f"Best units: {best_hps.get('units')}, best learning rate: {best_hps.get('learning_rate')}") # Get the best model best_model = tuner.get_best_models(num_models=1)[0] best_model.evaluate(x_val, y_val)
Debug
Known issues
breakingPrivate APIs (e.g., internal utility functions) were moved under `keras_tuner.src.*`. Direct imports from old private paths will fail.
fix
Update any imports of internal components from `keras_tuner.some_private_api` to `keras_tuner.src.some_private_api`. Public APIs remain at the top level (e.g., `keras_tuner.tuners.RandomSearch`).
affects: >=1.4.0
gotchaKerasTuner v1.4.6+ introduced official support for Keras 3 (multi-backend), while still supporting Keras 2. Ensure your Keras environment is correctly configured if you use a specific backend (e.g., TensorFlow, PyTorch, JAX).
fix
If using Keras 3, ensure you have `keras` installed and potentially set `KERAS_BACKEND` environment variable. If using Keras 2, ensure you have `tensorflow<2.16` and `keras<3.0`.
affects: >=1.4.6
gotchaDistributed tuning (especially when `project_name` is shared across multiple processes) can be sensitive to race conditions or premature chief shutdown, which have been incrementally fixed across versions. Issues like client waiting indefinitely or chief exiting early are possible.
fix
Upgrade to KerasTuner v1.4.7 or newer to benefit from fixes to distributed execution stability. Carefully manage the lifecycle of parallel tuning processes.
affects: <1.4.7
gotchaKerasTuner v1.4.8 added `grpcio` and `protobuf` as direct dependencies. If you have older or incompatible versions of these libraries installed, it might lead to conflicts or runtime errors.
fix
Ensure you have compatible versions of `grpcio` and `protobuf` installed. A clean `pip install keras-tuner` will pull the correct versions. If conflicts arise, consider using a virtual environment.
affects: >=1.4.8
Upgrade
Version history
1.4.8latest on PyPI · released Nov 11, 2025
Audit
Dependencies
kerasrequiredRequired for model definition and training. KerasTuner 1.4.6+ supports Keras 3+ and maintains backward compatibility with Keras 2.
tensorflowoptionalA common backend for Keras models. Explicitly installing `keras-tuner[tensorflow]` ensures compatibility.
grpciorequiredAdded in v1.4.8; essential for distributed tuning communication.
protobufrequiredAdded in v1.4.8; essential for distributed tuning communication.
Agent activity
12 hits · last 30 days
node
10
Resources
keras-tuner — pip install keras-tuner · libregistry