Faster Deep Ensembles#929
Open
avullo wants to merge 29 commits into
Open
Conversation
…er layer Replace E separate Dense branch paths in KerasEnsemble with a single model that stacks all E inputs into [E, batch, D], runs one VectorizedEnsembleDenseLayer (batched matmul [E, batch, D] @ [E, D, H]) per hidden layer, then splits [E, batch, 2] params into E separate DistributionLambda outputs. External interface unchanged: same input/output names, loss=[nll]*E, metrics, callbacks, compile/fit, verbose=1 all preserved. Co-authored-by: Cursor <cursoragent@cursor.com>
…eparate calls Generate all E bootstrap index sets at once with tf.random.uniform([E, N]), then gather both query_points and observations in a single batched tf.gather per tensor, yielding [E, N, D] and [E, N, 1]. This replaces E×2 individual gather calls with 2 calls, and separates the bootstrap and no-bootstrap paths for clarity. Co-authored-by: Cursor <cursoragent@cursor.com>
…r step When N % batch_size == 0, reshape each input/output tensor from [N, ...] to [n_batches, batch_size, ...] before from_tensor_slices. Each Dataset element is then a pre-formed [batch_size, ...] slice rather than requiring B individual sample copies to be stacked per step. Co-authored-by: Cursor <cursoragent@cursor.com>
…] input and one [batch,E,1] output _build_vectorized_ensemble now accepts a single 'ensemble_input' of shape [E*D], reshapes to [E, batch, D] internally, transposes the [E, batch, 2] params to [batch, E, 2], and wraps in one DistributionLambda giving Normal([batch,E,1]). prepare_dataset and prepare_query_points branch on len(input_names)==1 to pack/ unpack the stacked representation. ensemble_distributions splits the single batched Distribution into E Normal distributions for the predict API. The compile() call is adapted to use one loss/metric for single-output models. _warmup_jit gains a forward-pass fallback to infer output shape when DistributionLambda does not propagate it statically. Reduces per-step Dataset tensor count from 2E=20 to 2, and Keras metric scalars from 2E to 2. Co-authored-by: Cursor <cursoragent@cursor.com>
…,1] output reduces per-step tensor overhead 20→2
…h a scaled gradient. Fix set state.
added 10 commits
May 23, 2026 17:39
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.
Related issue(s)/PRs:
Summary
...
Fully backwards compatible: yes / no
PR checklist