Current reconstruction loss stack
Current reconstruction loss stack
This note documents the current reconstruction-related loss composition in the disentangled trainers.
Current shape
Both the discrete and continuous implementations now treat reconstruction as a linear combination of six explicit scalar terms:
These six reconstruction terms are:
reconstruction_lossdistribution_normalized_reconstruction_lossexample_inverse_surprisal_weighted_reconstruction_losstoken_weighted_reconstruction_lossnormalized_concentration_corrected_token_weighted_reconstruction_lossnormalized_inverse_surprisal_token_weighted_reconstruction_loss
The full training objective then adds KL and the other configured auxiliaries:
Current design choices
- All six reconstruction terms are always computed and logged in both latent types.
- The trainer does not choose one reconstruction family implicitly.
- The objective uses a plain weighted sum of the six explicit reconstruction scalars.
- Token-level and example-level weighting both depend on one frozen z-free reference-model pass.
zfree_reference_scaleis a shared scalar used by:distribution_normalized_reconstruction_lossnormalized_concentration_corrected_token_weighted_reconstruction_lossnormalized_inverse_surprisal_token_weighted_reconstruction_loss
Shared implementation structure
The current implementation factors reconstruction into two stages:
- compute token-level masked NLL once
- aggregate that same token-level tensor in different ways
The common low-level helper lives in:
path:core/disentanglement/losses.py
The important current pattern is:
masked_token_nll_per_position(...)computes masked token NLL with shape[B, T-1]masked_token_nll_per_example(...)aggregates that tensor uniformly over active positionstoken_weighted_masked_nll_per_example(...)aggregates that same tensor with token weightstoken_weighted_masked_nll_per_example(...)is also reused with inverse-surprisal token weights
So the current reconstruction variants differ primarily in aggregation, not in how token NLL is scored.
For the formal and implementation-level implications of this denominator choice, see Token-sum versus token-mean NLL aggregation.
Planned ablation note: reconstruction-loss token aggregation mode.
Current configuration surface
The core loss config now nests reconstruction-specific settings under:
ReconstructionLossConfiginpath:core/disentanglement/config.py
The current reconstruction config fields are:
raw_weightdistribution_normalized_weightexample_inverse_surprisal_weighttoken_weighted_weightnormalized_concentration_corrected_token_weighted_weightnormalized_inverse_surprisal_token_weighted_weighttoken_weight_alphaexample_inverse_surprisal_epsiloninverse_surprisal_token_weight_epsilonzfree_reference_scale
The trainer-side config wiring lives in:
path:experiments/synthetic_sequences/disentangled/config.pypath:experiments/synthetic_sequences/disentangled/train_step.pypath:experiments/synthetic_sequences/disentangled/train_disentangled.py
Diagnostics
The current implementation always tracks token-weighting summary diagnostics:
token_weighted_base_losstoken_concentration_factorinverse_token_weighted_base_lossinverse_token_base_scale_factortoken_weighting/weight_maxtoken_weighting/weight_ratio_max_mintoken_weighting/effective_token_count_meaninverse_token_weighting/weight_maxinverse_token_weighting/weight_ratio_max_mininverse_token_weighting/effective_token_count_mean
These come from aligned z-free reference statistics computed in:
path:core/disentanglement/token_weighting.py
Related notes
- Current implementation: empirical z-free-relative reconstruction rescaling
- Current implementation: example-level inverse-surprisal weighting
- Current implementation: token-level surprisal-share weighting
- Current implementation: normalized concentration-corrected token-weighted reconstruction
- Current implementation: normalized inverse-surprisal token-weighted reconstruction ablation