Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions notebooks/searches/mcmc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,10 @@
"hand-tune the leapfrog step count. Because it uses gradients, the run is typically much more\n",
"sample-efficient than the ensemble samplers above on smooth, unimodal posteriors.\n",
"\n",
"Two requirements distinguish it from `Emcee` / `Zeus`:\n",
"\n",
" 1) The analysis must be built with `use_jax=True` so the log-likelihood is JAX-traceable end to\n",
" end (`jax.grad` of it has to be takeable). Below we construct a separate `analysis_jax` to\n",
" keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path.\n",
" 2) The user's model must be registered as a JAX pytree so `model.instance_from_vector` flows\n",
" through `jax.jit`. `enable_pytrees()` is a one-shot process-level call; `register_model(model)`\n",
" walks the user's model and registers each concrete class it finds (here, `af.ex.Gaussian`).\n",
" This is the same mechanism the `Nautilus_jax` example uses.\n",
"Unlike `Emcee` / `Zeus`, the analysis must be built with `use_jax=True` so the log-likelihood is\n",
"JAX-traceable end to end (`jax.grad` of it has to be takeable). Below we construct a separate\n",
"`analysis_jax` to keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path. Nothing\n",
"else is needed: the model is registered as a JAX pytree automatically when the fit starts.\n",
"\n",
"The fit itself runs in two phases:\n",
"\n",
Expand Down Expand Up @@ -416,11 +411,6 @@
" )\n",
" sys.exit(0)\n",
"\n",
"from autofit.jax.pytrees import enable_pytrees, register_model\n",
"\n",
"enable_pytrees()\n",
"register_model(model)\n",
"\n",
"analysis_jax = af.ex.Analysis(data=data, noise_map=noise_map, use_jax=True)\n",
"\n",
"search = af.BlackJAXNUTS(\n",
Expand Down
18 changes: 4 additions & 14 deletions scripts/searches/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,10 @@
hand-tune the leapfrog step count. Because it uses gradients, the run is typically much more
sample-efficient than the ensemble samplers above on smooth, unimodal posteriors.

Two requirements distinguish it from `Emcee` / `Zeus`:

1) The analysis must be built with `use_jax=True` so the log-likelihood is JAX-traceable end to
end (`jax.grad` of it has to be takeable). Below we construct a separate `analysis_jax` to
keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path.
2) The user's model must be registered as a JAX pytree so `model.instance_from_vector` flows
through `jax.jit`. `enable_pytrees()` is a one-shot process-level call; `register_model(model)`
walks the user's model and registers each concrete class it finds (here, `af.ex.Gaussian`).
This is the same mechanism the `Nautilus_jax` example uses.
Unlike `Emcee` / `Zeus`, the analysis must be built with `use_jax=True` so the log-likelihood is
JAX-traceable end to end (`jax.grad` of it has to be takeable). Below we construct a separate
`analysis_jax` to keep the existing `analysis` (used by Emcee / Zeus) on its NumPy path. Nothing
else is needed: the model is registered as a JAX pytree automatically when the fit starts.

The fit itself runs in two phases:

Expand Down Expand Up @@ -280,11 +275,6 @@
)
sys.exit(0)

from autofit.jax.pytrees import enable_pytrees, register_model

enable_pytrees()
register_model(model)

analysis_jax = af.ex.Analysis(data=data, noise_map=noise_map, use_jax=True)

search = af.BlackJAXNUTS(
Expand Down
Loading