Skip to content

[Bug] hp.Int with large max_value causes cryptic JAX shape error instead of helpful message #1054

Description

@amadhan882

Description

When hp.Int samples a very large value (e.g. close to max_value=10**9), the resulting model architecture becomes degenerate and fails with a cryptic JAX broadcasting error rather than a clear, actionable message. All trials fail and the tuner halts with a RuntimeError, giving the user no indication of which hyperparameter caused the problem.

To Reproduce

import keras_tuner as kt
import numpy as np
import tensorflow as tf

def build_model(hp):
    units = hp.Int("units", min_value=1, max_value=10**9)
    model = tf.keras.Sequential([tf.keras.layers.Dense(units, input_shape=(1,))])
    model.compile(loss="mse")
    return model

tuner = kt.RandomSearch(build_model, objective="val_loss", max_trials=3,
                        directory="my_dir", project_name="repro")
tuner.search(x=np.array([1,2,3]), y=np.array([1,2,3]), epochs=1)

Actual behavior

ValueError: Incompatible shapes for broadcasting: shapes=[(3,), (3, 54517531)]
...followed by...
RuntimeError: Number of consecutive failures exceeded the limit of 3.

The error message points deep into JAX internals with no reference to the
hyperparameter that caused it, making it very hard to debug.

Expected behavior

A clear warning or validation error such as:
"Sampled value for 'units' (54517531) may produce an invalid architecture.
Consider narrowing your search range."

Or at minimum, the RuntimeError should mention which hp parameter and sampled
value led to repeated failures.

Environment

  • Running on: Google Colab
  • keras-tuner: 1.4.8
  • keras: 3.13.2
  • tensorflow: 2.19.0
  • jax: 0.7.2
  • numpy: 2.0.2
  • python: 3.12.13 (main, Mar 4 2026, 09:23:07) [GCC 11.4.0]
  • platform: Linux-6.6.113+-x86_64-with-glibc2.35
  • GPU: /physical_device:GPU:0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions