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.1.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.1.0
File Size Uploaded
anyinit-0.1.0.tar.gz 127.3 kB Details

Built distribution (wheel)

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

Total release size: 216.7 kB

Release files / anyinit-0.1.0.tar.gz

Download URL anyinit-0.1.0.tar.gz
Size 127.3 kB
Tags Source
SHA-256 checksum
How to use checksums
97a7461a152c959b233c53bf88c54333c95b640dfe56e422b51a7062765d5d6e
BLAKE2b-256 checksum
How to use checksums
feb6dcadd0d5f705bb0ece43c2da09b3c7917930415689f6bf4fe740ca544656
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.1.0-py3-none-any.whl

Download URL anyinit-0.1.0-py3-none-any.whl
Size 89.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cd82a516f17dedc445d058e42634055e4e2d5d535ce9dbc4da3bbd3a8666ffe
BLAKE2b-256 checksum
How to use checksums
1c604e44548af57238a5b68753ce74cec9b088a0324b657bf396d08d05ce95da
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

0.2.0

2 release files

This release

0.1.0 This release

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