Practical overview
When it fits
Use Kfac Jax when building or researching JAX-based neural-network training and you want the documented K-FAC optimizer and curvature-estimation approach.
Who it is for
- Researchers exploring curvature-aware optimization in machine learning.
- Developers training neural networks with JAX who want to integrate K-FAC.
Documented uses
- Add K-FAC second-order optimization to JAX training code.
- Compute approximate curvature information for neural-network optimization.
- Use K-FAC within a Haiku model training loop.
Requirements & limits
The project is open source under the Apache-2.0 license. The repository documents pip installation from PyPI or GitHub.
- JAX must be installed first, including relevant accelerator support where needed.
- The optimizer requires loss registration for curvature estimation and assumes the loss is averaged across minibatch examples.
- The optimizer handles staging internally; direct jit or pmap wrapping of its step and value-and-gradient function is discouraged or incorrect according to the quickstart.
- The quickstart uses Haiku, while its dataset iterator is only a placeholder for a real data pipeline.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install KFAC-JAX for a JAX environment
Prepare the library and its documented examples dependencies for use in JAX-based development.
Before you start
- Python environment with JAX installed and relevant accelerator support configured.
- pip.
Steps
Install JAX by following the JAX installation instructions for the relevant accelerator support.
Install KFAC-JAX with the command below or from the repository with the command below.
pip install -U kfac-jaxpip install git+https://github.com/google-deepmind/kfac-jaxIf using the project examples, install their additional dependencies with the command below.
pip install kfac-jax[examples]
Expected outcome
KFAC-JAX and, if selected, its example dependencies are installed in the Python environment.
Guide limitations
- This covers installation only; it does not verify the environment or run a model.
- The repository states that JAX brings a C++ dependency.
Add the K-FAC optimizer to a Haiku training loop
Follow the repository quickstart pattern for initializing and stepping a K-FAC optimizer on a JAX model.
Before you start
- JAX and KFAC-JAX installed.
- A Haiku model, a loss function, and a minibatch data pipeline.
Steps
Register the model’s supported loss with the corresponding KFAC-JAX loss-registration function; the quickstart uses softmax cross-entropy.
Provide the loss and its gradients to
kfac_jax.Optimizer, setting its auxiliary-output, state and RNG options to match the loss function.Initialize the optimizer with model parameters, a JAX random key and a batch.
In the training loop, call
optimizer.stepwith the parameters, optimizer state, key and batch.
Expected outcome
The documented integration pattern supplies K-FAC optimizer steps and statistics within a JAX training loop.
Guide limitations
- The optimizer requires a recognized registered loss to estimate curvature and expects the loss to be averaged over minibatch examples.
- Do not apply
jax.jitorjax.pmapdirectly toOptimizer.stepor the supplied value-and-gradient function; the optimizer stages its step internally. - The example demonstrates Haiku; it uses a dummy dataset iterator that must be replaced with the user's data pipeline.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 20 November 2026
- Original website title
- google-deepmind/kfac-jax · Official homepage title · retained in its source language

