Streaming variational inference: Trainer for minibatch ADVI#710
Draft
YichengYang-Ethan wants to merge 3 commits into
Draft
Streaming variational inference: Trainer for minibatch ADVI#710YichengYang-Ethan wants to merge 3 commits into
YichengYang-Ethan wants to merge 3 commits into
Conversation
Ports the streaming data layer (IterableDataset, parquet_source, DataLoader, shuffle_buffer) from pymc-devs/pymc#8325. Self-contained numpy/pyarrow data layer with no pymc-internal coupling; public names mirror torch.utils.data. Tests moved alongside.
Port the Trainer from pymc-devs/pymc#8333 onto the DataLoader in pymc-devs#698. The Trainer owns the fitting loop and streams each minibatch into the model's pm.Data placeholder with set_data, so the user writes no callbacks: Trainer(method="advi", dataloader=loader, data_name="batch").fit(n) fit(n) feeds exactly n minibatches (the first seeds the placeholder before step 0; the advance after the final step is skipped). User callbacks compose with the internal advance, and an Inference instance is forwarded to pm.fit unchanged. The N / batch_size rescaling stays in the model via total_size=len(loader), reusing create_minibatch_rv, so it runs on today's pm.fit. Folding that scaling into the inference step, so the Trainer derives it from len(dataloader) and it drops out of the model body, follows the VI rework; the Trainer Notes document this. Adds tests/variational/test_streaming_trainer.py.
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.
Streaming variational inference: Trainer for minibatch ADVI
Stacks on #698 (the streaming
DataLoader). This adds theTrainerthatdrives variational inference over a
DataLoaderwith no user-facingcallbacks — the second half of the streaming-VI work, ported here from
pymc-devs/pymc#8333 now that the data layer lives in extras.
What it does
Trainer(method="advi", dataloader=loader, data_name="batch").fit(n)owns thefitting loop and streams each minibatch into the model's
pm.Dataplaceholderwith
set_data, so the user writes no callbacks. TheDataLoaderownsbatching (
len(dataloader)is the dataset sizeN), the model owns the math.fit(n)feeds exactlynminibatches: the first seeds the placeholder beforestep 0, and the advance after the final step is skipped. User callbacks (e.g. a
convergence tracker) compose with the internal advance instead of colliding on
the keyword. An
Inferenceinstance is forwarded topm.fitunchanged.Where the scaling lives (interim)
The
N / batch_sizerescaling stays in the model, viatotal_size=len(loader),reusing the existing
create_minibatch_rvmachinery. This runs on today'spm.fitunchanged. Folding the scaling into the inference step — so theTrainerderives it fromlen(dataloader)and it drops out of the model body —is the cleaner end state and fits naturally with the VI rework
(
fit_advi/Inference.step(batch)); it will follow once that inference-stepAPI lands. The
Notessection ofTrainerdocuments this.Tests
tests/variational/test_streaming_trainer.py: end-to-end equivalence to in-RAMpm.MinibatchADVI, exact batch accounting (fit(n)consumesnbatches),placeholder seeding/streaming,
refineresuming the stream, the pass-boundarytotal_sizecheck, user-callback composition, and the input guards.Refs
Ports pymc-devs/pymc#8333 · stacks on #698 · original data layer
pymc-devs/pymc#8325.