Skip to content

Fix MGUCell hidden state update#5467

Open
lanarkite99 wants to merge 1 commit into
google:mainfrom
lanarkite99:resume/flax-mgu-cell-fix
Open

Fix MGUCell hidden state update#5467
lanarkite99 wants to merge 1 commit into
google:mainfrom
lanarkite99:resume/flax-mgu-cell-fix

Conversation

@lanarkite99
Copy link
Copy Markdown

What does this PR do?

Fixes #4608.

This fixes the nn.MGUCell hidden-state update equation to match the Minimal Gated Unit recurrence.

The current implementation computes:

h' = (1 - f) * n + f * h

but according to the MGU formulation, the gate should mix the previous hidden state and candidate activation as:

h' = (1 - f) * h + f * n

This PR updates the implementation and the displayed equation in the MGUCell docstring.

It also expands the existing MGU regression test so the cell output is checked against a manually computed recurrence for both:

reset_gate=True
reset_gate=False

Tested with:

python -m pytest tests/linen/linen_test.py -k mgu -q

Result:2 passed, 99 deselected

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 21, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in MinimalGatedUnit

1 participant