Planned implementation: reconstruction-loss token aggregation mode
Planned implementation: reconstruction-loss token aggregation mode
Methodology note: Token-sum versus token-mean NLL aggregation
This note records the planned focused ablation for reconstruction_loss_token_aggregation_mode, which will support mean and sum. The current implementation corresponds to mean.
Approved scope
- The mode applies only to reconstruction-family terms.
- KL, posterior entropy, posterior variance, router support, router marginal KL, inter-latent divergence, and other auxiliary losses are unchanged.
meanremains the default.sumis allowed as an optimization setting, including for the raw reconstruction term.- The z-free reference scale must be recomputed from validation records using the same aggregation mode as the training objective.
- The mode must be explicit in run config, slurm params, run naming, and aggregate tables.
This is an ablation, not a replacement of the default objective.
Aggregation contract
For example , let be the supervised y-region, , z-conditioned token NLL , and frozen z-free token NLL .
The uniform per-example aggregation is:
Batch reduction remains an example mean:
So sum means "per-example supervised-token sum, then batch mean." It does not mean global token mean over the whole batch.
Token-weighted aggregation contract
Token-weighting code currently normalizes token weights per example, so over active supervised tokens. To make token-weighted losses match the selected uniform aggregation mode, define:
The factor is required for consistency. Without it, raw reconstruction would move to sequence-sum scale while token-weighted reconstruction would remain on token-mean scale. With it, recovers the corresponding uniform aggregation mode exactly.
Loss-term adaptation
Raw reconstruction
The raw reconstruction component becomes:
This is the component logged as reconstruction_loss.
Distribution-normalized reconstruction
The distribution-normalized component becomes:
The reference scale must be mode-matched. A mean-scale validation loss cannot be reused as the denominator for a sum-scale reconstruction objective.
Example-level inverse-surprisal reconstruction
The example-level inverse-surprisal component becomes:
The epsilon is in the same units as , so the implementation should treat it as mode-sensitive. The existing default is effectively a mean-scale epsilon; for sum, the safest first implementation is to reuse the configured value but document that it is in selected-mode units and log base-loss minima so pathological tiny denominators are visible.
This method still makes sense under sum, but if is negligible, the per-example ratio mostly cancels the length factor. So it is probably less informative as the first aggregation-mode ablation than distribution-normalized or token-weighted terms.
Raw token-weighted reconstruction
The high-surprisal token-weighted reconstruction component becomes:
where is the detached high-surprisal token-weight vector derived from the frozen z-free token NLL.
For sum, this means multiplying the current weighted mean by .
Normalized concentration-corrected token-weighted reconstruction
The concentration factor should be computed with the selected aggregation mode:
Because both numerator and denominator are multiplied by under sum, when the same normalized token weights are used. The normalized concentration-corrected component is:
This method still makes sense under sum. At , it reduces to distribution-normalized uniform reconstruction in the selected aggregation mode.
Normalized inverse-surprisal token-weighted reconstruction
The low-surprisal inverse-token ablation follows the same matched-scale pattern:
As with , the scale factor is unchanged between mean and sum if both numerator and denominator use the same aggregation mode. This ablation still makes sense under sum, but the strongest comparison remains against the high-surprisal token-weighted term with matched mode, alpha, and z-free reference scale.
Implementation requirements
- Add
reconstruction_loss_token_aggregation_modewith allowed valuesmeanandsum. - Add the corresponding CLI flag, likely
--reconstruction-loss-token-aggregation-mode {mean,sum}. - Thread the mode through:
path:core/disentanglement/config.pypath:core/disentanglement/losses.pypath:core/disentanglement/token_weighting.pypath:core/disentanglement/shared_discrete_cvae.pypath:core/disentanglement/continuous_cvae.pypath:experiments/synthetic_sequences/disentangled/config.pypath:experiments/synthetic_sequences/disentangled/train_disentangled.pypath:experiments/synthetic_sequences/disentangled/train_step.py
- Recompute
zfree_reference_scalefrom validation records with the selected aggregation mode. Forentangled_runsources, do not silently load an old saved mean-scale validation loss when mode issum. - Record the mode in the saved run config and any run metadata artifacts.
- Include the mode in slurm family params and template recovery tests.
- Include the mode in run naming so
meanandsumruns cannot collide. - Include the mode in aggregate parsing and aggregate tables.
- Log supervised token-count diagnostics, at least mean/min/max over training and validation batches, so length effects can be interpreted.
Pilot collection
The first pilot should be narrow. The cleanest comparisons are mode-matched normalized variants:
distwithmeanversusdistwithsum;tokccwithmeanversustokccwithsum;- optionally the current best hybrid with
meanversus the same hybrid withsum; - raw
sumis allowed, but should be interpreted as both a length-weighting intervention and a larger reconstruction-to-KL scale unless paired with explicit beta or normalizer controls.
The main outcome to watch is whether sum changes latent usage and strategy separation beyond what can be explained by a larger reconstruction scale or by upweighting longer examples.
Expected confounds
- Sequence length may correlate with task, strategy, parse success, or answer correctness.
- Raw
sumchanges the reconstruction-to-KL balance by approximately the active supervised token count. - Distribution normalization removes the global average scale change but does not remove within-distribution length weighting.
- Example-level inverse-surprisal ratios may cancel much of the mean-vs-sum difference, making them less diagnostic for the first pilot.
- Token-weighted
sumpreserves within-example token emphasis but gives longer examples more total reconstruction weight.
Current status
This note records the planned ablation contract. The code has not yet been updated.