Padding and a new stream are different boundaries
numeric▲▲△Use , initially zero. An example has one real input followed by one zero padding input. Compare the final state with and without a state mask. A new independent example then begins with input . Compare resetting its initial state with wrongly carrying the previous valid state. Does detaching the carried value fix the latter?
Hint
A zero input still applies the recurrent matrix.
Solution
After the real input, . An ordinary zero-input update yields . Freezing the state at the padding position keeps it at two. Masking only the padded loss does not change that unmasked update.
For the new independent example, resetting gives . Wrongly carrying the valid state two gives . The result depends on an unrelated example.
Detaching retains the number two. It stops a derivative, not a contaminating forward value, so the new example still produces two. Reset at independent-sequence boundaries. Carry and detach only when the next chunk continues the same stream and truncated training is intended.