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.2.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.2.0
File Size Uploaded
anyinit-0.2.0.tar.gz 132.6 kB Details

Built distribution (wheel)

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

Total release size: 224.6 kB

Release files / anyinit-0.2.0.tar.gz

Download URL anyinit-0.2.0.tar.gz
Size 132.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d3bb80c36ff22b962c8bbd28aeda296c2b6ccd69ac7c38c330d43dfc2095e299
BLAKE2b-256 checksum
How to use checksums
6934c8cff8a337d26ffb562a1a4f76d395a4e8d8085e9eebfc15f03d628fedef
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 7, 2026.

Transparency log

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

Download URL anyinit-0.2.0-py3-none-any.whl
Size 92.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04c0d9b2ac414599abfceb14636b41a85efaa01d3a09b763355ba9a7a523fdf1
BLAKE2b-256 checksum
How to use checksums
5c88ca9bcee56c3c49275fdf763c1752973e51edc485a0feff2df626058d9e85
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 7, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.0 This release

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