Rollout alternative implementation. - #2748
Draft
grassesi wants to merge 14 commits into
Draft
Conversation
Storing the steps and converting them via chunk_idx/batch_idx lets a partial rollout be indexed without callers tracking offsets. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The predictors now take the global forecast step and let ModelOutput resolve it, so they stay correct when the output covers only part of the rollout. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The context manager had been absorbed into the comment above it, so intermediate rollout steps still built a graph. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sizing the zero arrays from the batch and stream config instead of indexing preds[0] lets a step that holds no predictions for a stream still be written. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The caller knows which steps its data covers, so the writer no longer has to reconstruct them from the target count and the offset. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Taking the steps from ModelOutput lets a partial rollout be written, at the cost of the first chunk emitting empty entries for its leading offset steps. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collecting the model call and the write in _process_validation_chunks gives the rollout a single place to be split into chunks. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Each chunk continues from the previous one and is written as it completes; the predictions themselves are still retained for the loss computation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chunked rollout reimplementation
This PR contains a reimplementation of chunked rollout inspired from #2076 . Below are the differences listed.
Conceptual changes
A chunk is described by the global forecast steps it covers
A chunk is a list of global forecast step ids. It is passed to
Model.forwardand stored inModelOutput. This wayModelOutputbecomes self describing, eliminating downstream indexcomputations. It simplifies the interface of
validation_io.write_outputandModel.predict_decoders/Model.predict_latent.The first chunk includes leading empty forecast_offset steps
With
forecast_offset > 0the first chunk'sModelOutputis sized to start at step 0. The leadingn
forecast_offsetsteps are left empty. This way the concatenation of the data fields in each chunk'sModelOutputis identical to the fields in aModelOutputcovering a global, unchunked rollout.Use polymorphism to get latent tokens for rollout.
For the first chunk in a rollout, the latent tokens are constructed from the sources (
BatchSamples) byrunning the encoder. All following chunks require the tokens and the initial sources, so they retrieved from
the previous chunks output (
ModelOutput).Model.forwardtakes either aBatchSamplesinstance (firstchunk) or
ModelOutput(all other). The interface between both classes is unified using the.latentand.batch_samplesattributes. In case ofModelOutputthey just fetch the required data.BatchSamplesitselfif queried for
.batch_samples.BatchSamples.latentis a empty, signaling to the model to use the encoder.Behavioral changes
latent_pre_normis applied only at the true first forecast stepPrevious code repopulates
LatentState.class_tokenandpatch_tokensat the head ofevery chunk, so latent heads and SSL losses see post-norm fields at steps where an unchunked run
would see
None.posteriorsis only written once, on the first chunkPrevious code writes
posteriorsat index 0 of every chunk, storing the previous chunk'sLatentStatethere from the second chunk onwards
Pushforward marks only the final step of the whole rollout
Previous code skips decoding for every step except
rollout_steps - 1, which is the last step of eachchunk. It therefore decodes and backpropagates at every chunk boundary rather than
once at the end of the rollout.
num_steps: 0still produces outputevenmn's_get_forecast_chunksreturns[]fornum_steps == 0, so no forward pass runs at all.milti_stream_data_sampler._get_output_lengthclamps to at least one output step, so an MTM configuration(
forecast_offset:0,num_steps: 0) has one valid step. In this case, previous code skipps the forward passand any output writing.
Spoofed targets no longer depend on non-empty predictions
Previous code reads
preds[0].shapeto size its zero arrays, which raisesIndexErrorwhen the chunk holds no predictions for that stream.
Questions:
How does it interact with changes like latent output (#1860) or infernce mode optimizations (#2272) ...?
Issue Number
Is this PR a draft? Mark it as draft.
Checklist before asking for review
./scripts/actions.sh lint./scripts/actions.sh unit-test./scripts/actions.sh integration-testlaunch-slurm.py --time 60