Skip to content

Fix KeyError for input-only hidden states and dropped pure-copy edges (#184) - #190

Merged
chaoming0625 merged 1 commit into
mainfrom
fix/184-input-only-hidden
Oct 24, 2026
Merged

chaoming0625 merged 1 commit into
mainfrom
fix/184-input-only-hidden

Conversation

@chaoming0625

Copy link
Copy Markdown
Collaborator

Fixes #184.

Summary

Input-only hidden state (the issue).

  • Cause: write_jaxpr_of_hidden_group_transition builds the group jaxpr only from equations reachable from the group invars. A latch latch^t = x @ w that joined the group through V's transition was therefore never produced and never bound, and eval_jaxpr raised KeyError.
  • Fix: such an outvar is now bound from the forward pass as a constvar, which gives a zero Jacobian row. This is the mechanism the zero-recurrence fallback already uses.

Pure copies (found while fixing; same family).

  • Cause: h2^t = h1^{t-1} (a delay line / shift register) has no equation, so the edge was dropped. h2 fell back to a zero-recurrence group, and the weight feeding h1 got a silently zero online gradient. Downstream's new + 0*old workaround hides this case too.
  • Fix: _post_check now merges the copy into the source's group, which gives an identity row.
  • A same-step read of the copy is indistinguishable in the jaxpr from a read of h1^{t-1} (they are one variable), so it cannot be fixed there. It now emits a WARNING DiagnosticKind.HIDDEN_COPY_SAME_STEP_READ that names both states. A read on the next step is exact.

Spec: docs/specs/2026-10-24-issue-184-input-only-hidden.md.

Before / after

model (D-RTRL etrace_grad, |grad w|) main this branch BPTT
issue repro (latch) KeyError 37.508961 (= --workaround result) —
delay line, copy read next step KeyError 0.584477 0.584477

Tests

  • _compiler/hidden_group_test.py::TestInputOnlyHiddenInMergedGroup:
    • transition + diagonal Jacobian [[0,0],[1,0.9]] for latch <- x@w and latch <- x;
    • two latches;
    • deterministic constvars;
    • shift-register identity row.
  • _compiler/hidden_group_test.py::TestHiddenCopySameStepRead: warns for a same-step read, silent for a next-step read.
  • _algorithm/d_rtrl_test.py::TestEquationFreeHiddenEdges:
    • D-RTRL equals BPTT through the finite-window oracle (chunked_online_param_gradients, chunk 1 and 3) for the latch and delay-line models;
    • d_rtrl and eprop match the new + 0*old workaround.
  • 14 of the 15 new tests fail without the fix.
  • Full suite (CPU, remote): 2921 passed, 1 skipped, no failures. The only error is a hypothesis import missing in the remote env, which also occurs on main.

…#184)

A hidden state whose new value depends only on inputs (an input latch)
joins a group through another member's transition, so no collected
equation produces it and HiddenGroup.transition raised KeyError. Bind
such outvars as constvars (zero Jacobian row).

A pure copy h2^t = h1^{t-1} (delay line) has no equation, so its edge
was dropped and the weight feeding h1 got a zero online gradient. Merge
the copy into the source's group (identity row). A same-step read of the
copy cannot be attributed to h2^t and now emits a WARNING
(HIDDEN_COPY_SAME_STEP_READ).
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
braintrace/_compiler/hidden_group.py 94.73% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@chaoming0625
chaoming0625 merged commit f83c7ac into main Oct 24, 2026
6 of 7 checks passed
@chaoming0625
chaoming0625 deleted the fix/184-input-only-hidden branch October 24, 2026 10:02
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.

KeyError in HiddenGroup.transition when a HiddenState depends only on inputs (no hidden-to-hidden path)

1 participant