Update handling of pytrees to work with empty sequences and optax MaskedNode and MaskedState.
Update handling of pytrees to work with empty sequences and optax MaskedNode and MaskedState.

PiperOrigin-RevId: 458138427

google/paxml,google/paxml