Skip to content

Conversation

@jameslovespancakes
Copy link
Contributor

Fixes #102598

When using GRU (or other RNN layers) with return_state=True in a Functional API model, various KeyError exceptions were thrown during model compilation when only one output was used.

The issue occurred when a model had a single output from a multi-output layer (e.g., only sequences from GRU with return_state=True), but the loss/metrics were provided as a nested structure (list or tuple).

This fix adds handling in map_to_output_names() to unwrap single-element nested structures when the model has a single output, matching the expected structure for loss and metric routing.

Fixes tensorflow#102598

When using GRU (or other RNN layers) with return_state=True in a Functional
API model, various KeyError exceptions were thrown during model compilation
when only one output was used.

The issue occurred when a model had a single output from a multi-output layer
(e.g., only sequences from GRU with return_state=True), but the loss/metrics
were provided as a nested structure (list or tuple).

This fix adds handling in map_to_output_names() to unwrap single-element
nested structures when the model has a single output, matching the expected
structure for loss and metric routing.
Copy link
Collaborator

@mihaimaruseac mihaimaruseac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done in the keras repo. The legacy files in TF should only be updated for typos or security fixes.

@github-project-automation github-project-automation bot moved this from Assigned Reviewer to Reviewer Requested Changes in PR Queue Oct 24, 2025
@github-project-automation github-project-automation bot moved this from Reviewer Requested Changes to Closed/Rejected in PR Queue Oct 24, 2025
@google-ml-butler google-ml-butler bot removed the awaiting review Pull request awaiting review label Oct 24, 2025
@jameslovespancakes jameslovespancakes deleted the fix-issue-102598-gru-functional-api branch October 27, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prtype:bugfix PR to fix a bug size:S CL Change Size: Small

Projects

Status: Closed/Rejected

Development

Successfully merging this pull request may close these issues.

GRU character generation functional API model throws various exceptions.

4 participants