Repository navigation
Unifying the nation under one backend - #1
Merged
Merged
Conversation
Merge the main (TensorFlow), torch, and jax branches into a single
multi-backend package with a common sample/sample_batch API per backend
(affine.backends.{tensorflow,torch,jax}), imported lazily so only the
framework in use needs to be installed. The historical entry points of
all three branches are preserved at the top level.
Bug fixes relative to the old branches:
- torch: NaN log-probs were mapped to +inf in sample(), so proposals in
invalid regions were accepted with probability 1; now -inf (rejected).
- torch: sample_batch() left the final chain row uninitialized (all
zeros) with the default n_burnin/thin; the chain now stores the
initial state and every step with no uninitialized entries.
- torch: sample() crashed on GPU walkers (random draws were CPU-only).
- All backends: acceptance is computed in log space, avoiding float32
overflow-to-NaN (silent rejection) for ~130+ parameters.
- All backends: dtype-agnostic (float64 works), no in-place mutation of
user tensors, single RNG source, optional seeding for reproducibility.
- Gibbs example notebook: latent chains were split with n_hyper_walkers
instead of n_latent_walkers; tf.concat of scalars fails on modern TF.
Packaging: pyproject.toml with per-backend extras, pytest suite covering
all backends (moments recovery, NaN rejection regression, trailing-zeros
regression, reproducibility, legacy APIs), GitHub Actions CI, examples/
directory, CHANGELOG, expanded README.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
|
Sorry for taking a while to get to this. I think it would be good if the basic example included all backends. Will try to make some modifications to that as I test it. Also, would be good if the tf backend used the same naming convention (i.e. |
All six samplers now share one signature, with the PyTorch module as the
reference:
sample([rng,] log_prob, n_steps, current_state, n_burnin=0, thin=1,
args=(), progress=True, save_lp=False, [device=None,] *,
save_extras=False, progressbar=None)
- tensorflow: affine_sample/affine_sample_batch renamed sample/sample_batch;
the old names are kept as module-level aliases and the top-level wrappers
still work.
- torch: sample takes (log_prob, n_steps, current_state, ...) like
sample_batch, infers n_walkers and n_params from the walker shape, and
accepts device=. The old positional style is no longer accepted.
- jax, tensorflow: keyword order follows torch; progress is the primary
spelling of the progress-bar flag, progressbar remains an alias.
Tests, example notebooks, README and CHANGELOG updated to match; the stray
copy of the README torch snippet in the sampling example is removed.
Co-Authored-By: Claude Fable 5.1 <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.
Merges the
jax,tensorflowandpytorchbackends into one codebase. Each of them can now be called withaffine.jax,affine.tensorfloworaffine.torch. Simple unit tests are integrated for the affine sampler in thetestsdirectory.CHANGELOG.mddetails the exact changes implemented in this branch.setup.pyis now replaced withpyproject.toml.