From 07dc0a4fd317bcda0f8d4a12dbdecef093dcde17 Mon Sep 17 00:00:00 2001 From: Emmanuel Ferdman Date: Fri, 2 May 2025 04:00:24 -0700 Subject: [PATCH 1/2] Fix message formatting Signed-off-by: Emmanuel Ferdman --- keras/src/backend/tensorflow/nn.py | 2 +- keras/src/backend/tensorflow/numpy.py | 2 +- keras/src/layers/attention/grouped_query_attention.py | 2 +- keras/src/layers/core/lambda_layer.py | 2 +- keras/src/layers/preprocessing/category_encoding.py | 2 +- keras/src/ops/linalg.py | 4 ++-- keras/src/ops/numpy.py | 2 +- keras/src/utils/dataset_utils.py | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/keras/src/backend/tensorflow/nn.py b/keras/src/backend/tensorflow/nn.py index bea8c1855326..5457ce1bb514 100644 --- a/keras/src/backend/tensorflow/nn.py +++ b/keras/src/backend/tensorflow/nn.py @@ -353,7 +353,7 @@ def depthwise_conv( if num_spatial_dims > 2: raise ValueError( "`inputs` rank must be 3 (1D conv) or 4 (2D conv). Received: " - "{inputs.ndim}." + f"{inputs.ndim}." ) # Because we use `tf.nn.depthwise_conv2d` for both 1D and 2D convs, we set # `tf_data_format` using 2D conv format. diff --git a/keras/src/backend/tensorflow/numpy.py b/keras/src/backend/tensorflow/numpy.py index a50f6dff4db4..8acf87bff166 100644 --- a/keras/src/backend/tensorflow/numpy.py +++ b/keras/src/backend/tensorflow/numpy.py @@ -1999,7 +1999,7 @@ def unravel_index(x, shape): if None in shape: raise ValueError( - "`shape` argument cannot contain `None`. Received: shape={shape}" + f"`shape` argument cannot contain `None`. Received: shape={shape}" ) if x.ndim == 1: diff --git a/keras/src/layers/attention/grouped_query_attention.py b/keras/src/layers/attention/grouped_query_attention.py index bb60655fe2ba..aec0c546b337 100644 --- a/keras/src/layers/attention/grouped_query_attention.py +++ b/keras/src/layers/attention/grouped_query_attention.py @@ -464,7 +464,7 @@ def compute_output_shape( raise ValueError( "The last dimension of `query_shape` and `value_shape` " f"must be equal, but are {query_shape[-1]}, {value_shape[-1]}. " - "Received: query_shape={query_shape}, value_shape={value_shape}" + f"Received: query_shape={query_shape}, value_shape={value_shape}" ) if value_shape[1:-1] != key_shape[1:-1]: diff --git a/keras/src/layers/core/lambda_layer.py b/keras/src/layers/core/lambda_layer.py index 11d5f15f0f9e..d6a12f70b9f9 100644 --- a/keras/src/layers/core/lambda_layer.py +++ b/keras/src/layers/core/lambda_layer.py @@ -170,7 +170,7 @@ def _serialize_function_to_config(self, fn): def _raise_for_lambda_deserialization(arg_name, safe_mode): if safe_mode: raise ValueError( - "The `{arg_name}` of this `Lambda` layer is a Python lambda. " + f"The `{arg_name}` of this `Lambda` layer is a Python lambda. " "Deserializing it is unsafe. If you trust the source of the " "config artifact, you can override this error " "by passing `safe_mode=False` " diff --git a/keras/src/layers/preprocessing/category_encoding.py b/keras/src/layers/preprocessing/category_encoding.py index 183debf49908..07fb9794475a 100644 --- a/keras/src/layers/preprocessing/category_encoding.py +++ b/keras/src/layers/preprocessing/category_encoding.py @@ -157,7 +157,7 @@ def call(self, inputs, count_weights=None): if self.output_mode != "count": raise ValueError( "`count_weights` is not used when `output_mode` is not " - "`'count'`. Received `count_weights={count_weights}`." + f"`'count'`. Received `count_weights={count_weights}`." ) count_weights = self.backend.convert_to_tensor( count_weights, dtype=self.compute_dtype diff --git a/keras/src/ops/linalg.py b/keras/src/ops/linalg.py index 8263c1ffb7d4..03ea09ca3b2c 100644 --- a/keras/src/ops/linalg.py +++ b/keras/src/ops/linalg.py @@ -665,7 +665,7 @@ def _assert_1d(*arrays): for a in arrays: if a.ndim < 1: raise ValueError( - "Expected input to have rank >= 1. Received scalar input {a}." + f"Expected input to have rank >= 1. Received scalar input {a}." ) @@ -674,7 +674,7 @@ def _assert_2d(*arrays): if a.ndim < 2: raise ValueError( "Expected input to have rank >= 2. " - "Received input with shape {a.shape}." + f"Received input with shape {a.shape}." ) diff --git a/keras/src/ops/numpy.py b/keras/src/ops/numpy.py index 3e46225369c8..8775cd7e6c5a 100644 --- a/keras/src/ops/numpy.py +++ b/keras/src/ops/numpy.py @@ -2283,7 +2283,7 @@ def compute_output_spec(self, x): if len(x_shape) < 2: raise ValueError( "`diagonal` requires an array of at least two dimensions, but " - "`x` is of shape {x.shape}." + f"`x` is of shape {x.shape}." ) shape_2d = [x_shape[self.axis1], x_shape[self.axis2]] diff --git a/keras/src/utils/dataset_utils.py b/keras/src/utils/dataset_utils.py index f1b6b7e02f10..b8d2a534b1a2 100644 --- a/keras/src/utils/dataset_utils.py +++ b/keras/src/utils/dataset_utils.py @@ -406,7 +406,7 @@ def _rescale_dataset_split_sizes(left_size, right_size, total_length): if left_size + right_size > total_length: raise ValueError( "The sum of `left_size` and `right_size` should " - "be smaller than the {total_length}. " + f"be smaller than the {total_length}. " f"Received: left_size + right_size = {left_size + right_size}" f"and total_length = {total_length}" ) From 621ba7c794c06272e2bb766fd5b034ffeb93f1a1 Mon Sep 17 00:00:00 2001 From: Emmanuel Ferdman Date: Fri, 2 May 2025 04:24:01 -0700 Subject: [PATCH 2/2] Fix message formatting Signed-off-by: Emmanuel Ferdman --- keras/src/layers/attention/grouped_query_attention.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/keras/src/layers/attention/grouped_query_attention.py b/keras/src/layers/attention/grouped_query_attention.py index aec0c546b337..b57028446f0d 100644 --- a/keras/src/layers/attention/grouped_query_attention.py +++ b/keras/src/layers/attention/grouped_query_attention.py @@ -464,7 +464,8 @@ def compute_output_shape( raise ValueError( "The last dimension of `query_shape` and `value_shape` " f"must be equal, but are {query_shape[-1]}, {value_shape[-1]}. " - f"Received: query_shape={query_shape}, value_shape={value_shape}" + f"Received: query_shape={query_shape}, " + f"value_shape={value_shape}" ) if value_shape[1:-1] != key_shape[1:-1]: