Skip to main content

Adaptive Input/Output Normalization for deep neural networks. Enables stable training of extremely deep networks through adaptive residual scaling (Alpha) by Babayev's Theory

Project description

AION-Torch: Adaptive Input/Output Normalization

PyPI version PyPI downloads License: MIT Python 3.10+

AION-Torch is a PyTorch library that implements Adaptive Input/Output Normalization (AION), a method for stabilizing deep neural networks. AION automatically adjusts residual connections to prevent vanishing and exploding gradients, enabling stable training of very deep networks with minimal configuration.


🚀 Features

  • Adaptive Residual Scaling: Automatically adjusts residual connection strength based on signal statistics
  • Stable Deep Training: Prevents vanishing/exploding gradients even in networks with 1000+ layers
  • Drop-in Replacement: Works with any architecture using residual connections (Transformers, ResNets, etc.)
  • Distributed Ready: Fully supports DDP with synchronized statistics across all GPUs
  • Zero Config: Sensible defaults work out-of-the-box, no hyperparameter tuning needed

📦 Installation

From PyPI

pip install aion-torch

⚡ Quick Start

1. The AionBlock (Recommended)

The easiest way to use AION is to replace your standard residual blocks with AionBlock. It implements the Pre-LayerNorm pattern augmented with AION scaling.

import torch
import torch.nn as nn
from aion_torch import AionBlock

# Define your transformation layer (e.g., Attention or MLP)
mlp_layer = nn.Sequential(
    nn.Linear(512, 2048),
    nn.GELU(),
    nn.Linear(2048, 512)
)

# Wrap it in an AionBlock
# Structure: x + alpha * layer(norm(x))
block = AionBlock(layer=mlp_layer, dim=512)

# Forward pass
x = torch.randn(8, 128, 512)
output = block(x)

2. Low-Level AionResidual

For custom architectures, you can use the AionResidual adapter directly.

from aion_torch import AionResidual

class MyLayer(nn.Module):
    def __init__(self, dim):
        super().__init__()
        self.norm = nn.LayerNorm(dim)
        self.ffn = nn.Linear(dim, dim)
        # Initialize AION adapter
        self.aion = AionResidual(alpha0=0.1, beta=0.05)

    def forward(self, x):
        residual = x
        x_norm = self.norm(x)
        y = self.ffn(x_norm)

        # Apply adaptive residual connection
        # Formula: x + alpha * y
        return self.aion(residual, y)

🧠 How It Works

AION adaptively scales residual connections using a simple but effective formula:

$$ \alpha = \frac{\alpha_0}{1 + \beta \cdot \text{ratio}} $$

where ratio measures the relative magnitude of the transformation output compared to the input. When the network becomes unstable (high ratio), AION automatically reduces the scaling factor. When stable (low ratio), it uses a stronger connection.

Key insight: By maintaining balanced signal propagation, AION ensures gradients flow stably through arbitrarily deep networks without exponential growth or decay.

For the theoretical foundation and mathematical proofs, DM me.

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide (coming soon) and check out the issues.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ x Abbasagha Babayev

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aion_torch-0.3.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aion_torch-0.3.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file aion_torch-0.3.0.tar.gz.

File metadata

  • Download URL: aion_torch-0.3.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for aion_torch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d030210a5df2b32d0be12fe1aa0d8cd29e24c2f4a90690fbc99ecae01a2ab867
MD5 3895308ee859f7f26d5b06159d30cca3
BLAKE2b-256 6fd445570e4016a2f6156965c4d31a7d6d19d6737571924a398b130ec2193a3e

See more details on using hashes here.

File details

Details for the file aion_torch-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: aion_torch-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for aion_torch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be3ae93dc45b016cd3c348e688116d3295eed96ac2cf9c2c923bf1890db12a4a
MD5 e253c54f1573d288913fda96e356a091
BLAKE2b-256 79f1d6a7370965ed86e3f4ace4b89e2b0edeea19f6f7db064f511fc79a87b8bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page