Add variational and spatial token autoencoders - #156
Merged
sergioald merged 9 commits intoJul 31, 2026
Merged
Conversation
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.
Summary
This PR extends the BlueMath_tk autoencoder framework with two advanced model
families:
VariationalAutoencoderSpatialTokenConvLSTMTransformerAutoencoderIt also strengthens the shared autoencoder infrastructure with stricter input
validation, transactional checkpoint loading, numerically stable scientific
reconstruction metrics, consistent latent-shape handling, and expanded
regression coverage.
This branch is based on the full-sequence reconstruction behaviour introduced
in PR #154.
New models
VariationalAutoencoder
The new variational autoencoder provides:
fit,predict,encode,decode,evaluate, and checkpoint support.The implemented objective is:
Validation uses the same stochastic beta-VAE objective used during training.
Posterior-mean reconstruction is reported separately through
val_deterministic_reconstruction_loss.SpatialTokenConvLSTMTransformerAutoencoder
The new spatial-token model operates on full spatiotemporal sequences:
Its architecture combines:
k;The decoder receives only the latent vector and learned model parameters. There
are no skip connections, cached inputs, or encoder feature maps that bypass the
latent bottleneck.
Shared autoencoder hardening
The PR improves validation and failure handling across the existing and new
autoencoder families.
Input and target validation
(k,); or(B, k).rejected.
build-state mutation.
Non-finite execution protection
Training, validation, inference, and checkpoint operations check for non-finite:
A failed fit cannot leave a model marked as successfully fitted with invalid
state.
Transactional checkpoint loading
Checkpoint loading is staged before modifying a live model.
A failed checkpoint load preserves:
Checkpoints containing values that are finite in their stored dtype but overflow
when converted to the destination dtype are rejected before the live model is
modified.
Scientific reconstruction metrics
The reconstruction metric API now provides robust NumPy and PyTorch
implementations of:
Supported reductions are:
none;sample;mean;sum.The implementation includes:
eps;Very small non-zero residuals remain distinguishable from exact reconstruction,
while very large but representable residuals do not fail merely because their
direct squares or intermediate sums overflow.
Test-state isolation
The advanced autoencoder tests now restore:
Restoration is checked after both successful and deliberately failing inner test
runs.
Public API
The intended public autoencoder exports are explicitly declared:
StandardAutoencoderOrthogonalAutoencoderLSTMAutoencoderCNNAutoencoderVisionTransformerAutoencoderConvLSTMAutoencoderHybridConvLSTMTransformerAutoencoderVariationalAutoencoderSpatialTokenConvLSTMTransformerAutoencoderThe common workflow is:
For the full-sequence spatiotemporal models:
Scope and limitations
The latent vector provides dimensional compression, but this PR does not
implement entropy coding, bitrate control, latent quantisation, or a deployable
storage codec.
Other current limitations include:
device;
beta=0does not produce a prior-matched generative model;environment did not include a CUDA-capable device.
Chronological experiment splitting, common benchmarking, latent quantisation,
storage accounting, and downstream scientific evaluation are intended for
separate follow-up work.
Tests
The added and expanded tests cover:
Local validation
Post-rebase validation against the current
developbranch: