Skip to main content

AnyInit

CI codecov PyPI Python Docs License: MIT

Initialize any model, in any framework, correctly — with one call.

import anyinit

report = anyinit.initialize(model)
print(report)

model can be a PyTorch module, a Keras model or a Flax module. AnyInit traces it, finds which activation follows each layer, and scales every weight so the signal neither dies nor explodes on its way through. Nothing to configure, nothing to look up.

Install

pip install anyinit

AnyInit depends on NumPy alone and uses whichever framework your model comes from.

What "any" means

Any framework. PyTorch, Keras 3 (on TensorFlow, JAX or PyTorch) and Flax, detected from the model. The same seed gives the same weights in all three.

Any activation. AnyInit measures the function itself instead of looking it up in a table, so a new activation is one decorator away:

@anyinit.register_activation
class ReLUCubed(torch.nn.Module):
    def forward(self, x):
        return torch.relu(x) ** 3

Any architecture. Branches, residual additions, concatenations, normalization, pooling, dropout, attention and embeddings.

Theory or measurement. Scale from theory, with no data, or from real batches:

anyinit.initialize(model, "analytic", (32, 3, 224, 224))   # shapes only, milliseconds
anyinit.initialize(model, "empirical", batch)              # measures, assumes nothing

It tells you when it cannot help

Some activations cannot be kept stable across depth by any initialization. AnyInit says so in the report instead of handing back a network that will not train:

Stability
  relu3   chi= 3.000  sigma*=  0.7148  unstable degree=3
      ! relu3 is homogeneous of degree 3 (chi=3.000), so a relative error grows by
        3.00x per layer and reaches 3.49e+09x over 20 layers. No scalar initialization
        is depth-stable here: reduce depth, insert normalization, or use a degree-one
        activation

Call report.assert_healthy() to turn that into an exception, for example in CI.

Learn more

The documentation covers:

Contributions are welcome; see Contributing.

References

Variance scaling comes from Glorot and Bengio (2010) and He et al. (2015), whose rectifier gain falls out of the moment map as the degree-one case. Treating signal propagation as a dynamical system, and the order parameter behind the χ diagnostic, come from Poole et al. (2016) and Schoenholz et al. (2017). The empirical mode generalizes LSUV (Mishkin & Matas, 2016) from a sequence of layers to a graph. Fixed points of the variance map, and the SELU constants the reference table reproduces, are from Klambauer et al. (2017). The sinusoidal distribution is from Fernández-Hernández et al. (2025).

What is new is evaluating the moment map numerically, by Gaussian quadrature, instead of deriving it per activation, which is why AnyInit accepts an activation it has never seen.

Fernández-Hernández, A., Mestre, J. I., Dolz, M. F., Duato, J., & Quintana-Ortí, E. S. (2025). Sinusoidal initialization, time for a new start. In Advances in Neural Information Processing Systems (Vol. 38). https://doi.org/10.48550/arXiv.2505.12909

Glorot, X., & Bengio, Y. (2010). Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the Thirteenth International Conference on Artificial Intelligence and Statistics (pp. 249–256). PMLR. https://proceedings.mlr.press/v9/glorot10a.html

He, K., Zhang, X., Ren, S., & Sun, J. (2015). Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification. In Proceedings of the IEEE International Conference on Computer Vision (pp. 1026–1034). IEEE. https://doi.org/10.1109/ICCV.2015.123

Klambauer, G., Unterthiner, T., Mayr, A., & Hochreiter, S. (2017). Self-normalizing neural networks. In Advances in Neural Information Processing Systems (Vol. 30, pp. 971–980). https://arxiv.org/abs/1706.02515

Mishkin, D., & Matas, J. (2016). All you need is a good init. In International Conference on Learning Representations. https://arxiv.org/abs/1511.06422

Poole, B., Lahiri, S., Raghu, M., Sohl-Dickstein, J., & Ganguli, S. (2016). Exponential expressivity in deep neural networks through transient chaos. In Advances in Neural Information Processing Systems (Vol. 29, pp. 3360–3368). https://arxiv.org/abs/1606.05340

Schoenholz, S. S., Gilmer, J., Ganguli, S., & Sohl-Dickstein, J. (2017). Deep information propagation. In International Conference on Learning Representations. https://arxiv.org/abs/1611.01232

Metadata

Release files for anyinit 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anyinit 0.3.0
File Size Uploaded
anyinit-0.3.0.tar.gz 149.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anyinit 0.3.0
File Interpreter ABI Platform
anyinit-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 248.4 kB

Release files / anyinit-0.3.0.tar.gz

Download URL anyinit-0.3.0.tar.gz
Size 149.5 kB
Tags Source
SHA-256 checksum
How to use checksums
051ce9849cdf47bef84281b66d6659c21d3b15b4aba6e70f72ffeef48ff546f9
BLAKE2b-256 checksum
How to use checksums
4c9a4b3d57711548d6994d9deab796aeca8f303add0daa278e1461fd4f93c356
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / anyinit-0.3.0-py3-none-any.whl

Download URL anyinit-0.3.0-py3-none-any.whl
Size 99.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3ac6abe0c3d6f30fa9375660ce6d60e0f79cc60932fb5fd6fc7516721140424
BLAKE2b-256 checksum
How to use checksums
22da44d724ca44874ddee9f737bd8a73cbfe8ca1a05ce053bf0fe3af2f1d142b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page