Skip to content

Commit 93ac2bd

Browse files
State the memory behavior precisely
1 parent 4026146 commit 93ac2bd

2 files changed

Lines changed: 63 additions & 63 deletions

File tree

examples/variational_inference/streaming_dataset.ipynb

Lines changed: 59 additions & 59 deletions
Large diffs are not rendered by default.

examples/variational_inference/streaming_dataset.myst.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ print(len(glob.glob(f"{shard_dir}/*.parquet")), "shards written")
9898
It reads one shard at a time and gets `n_rows` from the Parquet metadata without
9999
scanning the data, so `total_size="auto"` resolves `N` for free. The `DataLoader`
100100
batches and shuffles it into fixed-size minibatches. The model reads a
101-
`pm.Data("batch", ...)` placeholder, the only data resident at any point, and the
102-
`Trainer` writes each minibatch into it with `set_data`. There are no callbacks:
101+
`pm.Data("batch", ...)` placeholder holding a single batch, and the `Trainer`
102+
writes each minibatch into it with `set_data`. There are no callbacks:
103103
`total_size=len(loader)` triggers the `N / batch_size` rescaling and `Trainer.fit`
104104
runs the loop.
105105

@@ -117,7 +117,7 @@ loader = DataLoader(
117117
118118
with pm.Model() as model:
119119
b = pm.Normal("b", 0.0, 3.0, shape=4)
120-
batch = pm.Data("batch", np.zeros((batch_size, 4))) # placeholder, the only data in RAM
120+
batch = pm.Data("batch", np.zeros((batch_size, 4))) # placeholder for one minibatch
121121
logit = b[0] + b[1] * batch[:, 0] + b[2] * batch[:, 1] + b[3] * batch[:, 2]
122122
pm.Bernoulli("y", logit_p=logit, observed=batch[:, 3], total_size=len(loader))
123123
@@ -179,7 +179,7 @@ fig.tight_layout();
179179

180180
Both paths feed the same `batch_size` to ADVI, but `pm.Minibatch` keeps all `N`
181181
rows resident, so its array grows linearly in `N`, while the streaming `DataLoader`
182-
only holds one `batch_size` buffer. The dense `float64` design matrix dominates the
182+
holds one batch plus its bounded shuffle buffer. The dense `float64` design matrix dominates the
183183
cost. The line below is its lower bound (`N * ncols * 8` bytes), not a measurement:
184184

185185
```{code-cell} ipython3

0 commit comments

Comments
 (0)