Skip to content

Fix GlobalAveragePooling1D with an empty batch and a mask#906

Open
theomeb wants to merge 1 commit into
keras-team:masterfrom
theomeb:fix-67023-global-average-pooling-1d-empty-input
Open

Fix GlobalAveragePooling1D with an empty batch and a mask#906
theomeb wants to merge 1 commit into
keras-team:masterfrom
theomeb:fix-67023-global-average-pooling-1d-empty-input

Conversation

@theomeb

@theomeb theomeb commented Jun 2, 2026

Copy link
Copy Markdown

Fixes the crash when GlobalAveragePooling1D is called on an empty batch with a mask (StridedSlice index 0 of dimension 0 out of bounds), e.g. under MirroredStrategy when a replica gets an empty shard.

The cast tf.cast(mask, inputs[0].dtype) indexes the batch dim; changing it to inputs.dtype avoids touching the data. Includes a regression test in global_average_pooling_test.py (passes in graph and eager modes).

Upstream issue: tensorflow/tensorflow#67023

Casting the mask with tf.cast(mask, inputs[0].dtype) indexes the batch
dimension of inputs, triggering a StridedSlice that fails when the batch is
empty (e.g. when MirroredStrategy hands an empty shard to a replica). Cast
against inputs.dtype instead, which reads the dtype without indexing the data.

Adds a regression test for an empty batch passed together with a mask.

See tensorflow/tensorflow#67023
@github-actions github-actions Bot added the size:S label Jun 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue in GlobalAveragePooling1D where casting the mask using inputs[0].dtype would fail on empty batches. The code is updated to use inputs.dtype directly instead. Additionally, a unit test has been added to verify that the layer correctly handles empty batches with a mask. There are no review comments, so no further feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant