The same weights, two GRUs
counterexample▲▲△Exact values where possible; six decimal places for non-exact numerical results.
STATEMENT
Show that applying the reset gate before or after the recurrent matrix gives different GRUs, and find exactly when the two agree.
GIVEN
A two-unit GRU step with zero input contribution and zero candidate biases. The recurrent candidate matrix swaps coordinates, . The preceding state is . The reset pre-activations are and the update pre-activations are zero. Use PyTorch’s update, , for both.
FIND
The gates, both candidates and both new states; then a condition on and under which the two placements agree for every state.
STRATEGY
Compute and separately. For the general condition, write both as products with and compare entries.
SOLUTION
The gates are and . The update gate is the same in both models, so any difference comes from the candidate.
Reset before the matrix, as in Cho and colleagues: , and the swap gives . Hence
Reset after the matrix, as in PyTorch: , then , and
With , the new states are the averages of candidate and old state: before and after. Same weights, same state, same gates, and every coordinate differs by more than .
When they agree. The candidates’ recurrent parts are and . They agree for every exactly when the matrices are equal. Their entries are and , so the condition is
A weight joining two coordinates may be nonzero only if their reset values are equal. A uniform reset, , satisfies it for every ; a diagonal satisfies it for every . The swap matrix with unequal resets satisfies neither, which is why this example separates them.
Biases add a second difference. In the after form the recurrent bias is inside the reset, , so the reset scales it. In the before form a bias added outside is not scaled. Even scalar models differ when that bias is nonzero.
Answer
, . Before: candidate , state . After: candidate , state . They agree for all states exactly when for all .
Check — sanity
The swap matrix moves each coordinate’s reset to the other side. Reset before: coordinate one’s value, scaled by , lands in coordinate two. Reset after: coordinate two’s value lands in coordinate one and is scaled there by . The mirror-image answers are what that bookkeeping predicts.
Where this breaks
The commutation test is for one step with fixed gates. Over a sequence the two models also produce different gates, because the gates read states that have already diverged. Load a checkpoint into the placement it was trained with. The update-gate convention can be converted by negating weights; this example gives no such conversion for the reset placement.
Variation
Make the reset uniform at and keep the swap matrix. Both forms now give the candidate .