From daead65a19c7ae60a8ccd592afeb2458ee079044 Mon Sep 17 00:00:00 2001 From: slopisgood Date: Fri, 1 Aug 2025 11:51:51 -0700 Subject: [PATCH 1/2] Add public register_call_context_args method to Layer Add a public wrapper for _register_call_context_args on keras.layers.Layer that forwards call-context argument names. This makes the documented example using seq.register_call_context_args(...) functional and resolves issue #21530. --- keras/src/layers/layer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/keras/src/layers/layer.py b/keras/src/layers/layer.py index 6dd945557603..3a21b724056c 100644 --- a/keras/src/layers/layer.py +++ b/keras/src/layers/layer.py @@ -1797,6 +1797,22 @@ def call(self, x): ) + def register_call_context_args(self, *names): + """Public wrapper for `_register_call_context_args`. + + This method registers call-context arguments for this layer. It simply + forwards the provided argument names to the private method + `_register_call_context_args`. See `_register_call_context_args` for + details. + + Args: + *names: Names of call-context arguments to register. + + Returns: + None + """ + return self._register_call_context_args(*names) + def is_backend_tensor_or_symbolic(x, allow_none=False): if allow_none and x is None: return True From 05f66995c6fa0d0954f9e8c89c8a0e9fc946cbc4 Mon Sep 17 00:00:00 2001 From: slopisgood Date: Fri, 1 Aug 2025 14:49:55 -0700 Subject: [PATCH 2/2] Fix indentation of register_call_context_args method Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- keras/src/layers/layer.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/keras/src/layers/layer.py b/keras/src/layers/layer.py index 3a21b724056c..f405173aee5b 100644 --- a/keras/src/layers/layer.py +++ b/keras/src/layers/layer.py @@ -1797,21 +1797,21 @@ def call(self, x): ) - def register_call_context_args(self, *names): - """Public wrapper for `_register_call_context_args`. - - This method registers call-context arguments for this layer. It simply - forwards the provided argument names to the private method - `_register_call_context_args`. See `_register_call_context_args` for - details. - - Args: - *names: Names of call-context arguments to register. - - Returns: - None - """ - return self._register_call_context_args(*names) + def register_call_context_args(self, *names): + """Public wrapper for `_register_call_context_args`. + + This method registers call-context arguments for this layer. It simply + forwards the provided argument names to the private method + `_register_call_context_args`. See `_register_call_context_args` for + details. + + Args: + *names: Names of call-context arguments to register. + + Returns: + None + """ + return self._register_call_context_args(*names) def is_backend_tensor_or_symbolic(x, allow_none=False): if allow_none and x is None: