Skip to main content

A novel neural architecture merging SSM, RNN, and Hierarchical processing.

Project description

LaminarNet: Structured Orthogonal State Space Sequence Model

LaminarNet Logo

A Next-Generation Neural Architecture for Long-Context Sequence Modeling

PyPI version License: MIT


🌊 Overview

LaminarNet is a novel deep learning architecture designed to overcome the limitations of traditional Transformers in handling long sequences. By fusing principles from State Space Models (SSMs), Recurrent Neural Networks (RNNs), and Hierarchical Processing, LaminarNet achieves $O(N)$ inference complexity while maintaining the parallel training benefits of Transformers.

At its core, LaminarNet introduces three groundbreaking mechanisms:

  1. Geometric Drift Fields (GDF): Parallelizable rotation-based state evolution that replaces standard RNN loops with prefix sums.
  2. Cross-Stratum Routing (CSR): A bidirectional, multi-resolution information exchange system that allows different layers of abstraction to communicate effectively.
  3. Phase Mesh Encoding (PME): A stabilized coupled oscillator system for position encoding, offering superior extrapolation capabilities compared to Rotary Embeddings (RoPE).

🚀 Key Features

  • Linear Complexity: Scales linearly with sequence length during inference, making it ideal for long-context applications.
  • Hierarchical Structure: Processes information at multiple resolutions (strata) simultaneously, capturing both local details and global context.
  • Parallel Training: Utilizes prefix scan algorithms to enable efficient parallel training on GPUs.
  • Stabilized Dynamics: Incorporates gated retention and phase clipping to ensure stable training dynamics even at depth.

📦 Installation

Install LaminarNet directly from PyPI:

pip install laminarnet

🛠️ Usage

Basic Example

import torch
from laminarnet import LaminarNet, LaminarNetConfig

# Initialize configuration
config = LaminarNetConfig(
    vocab_size=32000,
    d_model=256,
    n_layers=6,
    seq_len=2048,
    n_strata=2
)

# Create model
model = LaminarNet(config)

# Forward pass
inputs = torch.randint(0, 32000, (1, 128))  # (Batch, SeqLen)
logits = model(inputs)

print(f"Output shape: {logits.shape}")
# Output: torch.Size([1, 128, 32000])

Advanced Configuration

You can customize the depth, width, and hierarchical structure of the network:

config = LaminarNetConfig(
    d_model=512,
    n_heads=8,
    n_layers=12,
    d_ff=2048,
    n_strata=3,            # 3 levels of hierarchy
    strata_ratios=(1, 4, 16), # Compression ratios for each stratum
    n_oscillators=32,      # Number of phase oscillators
    dropout=0.1
)

🔬 Architecture Deep Dive

1. Geometric Drift Fields (GDF)

Unlike traditional RNNs that rely on matrix multiplications for state updates, GDF employs a rotation-based mechanism in a high-dimensional vector space. By using parallel prefix sums (cumulative rotations), GDF achieves the sequential modeling power of an RNN with the parallel efficiency of a Transformer.

# Conceptual GDF Update
theta = tanh(Project(x))
state = state * rotation(theta) + input

2. Cross-Stratum Routing (CSR)

CSR enables information to flow between "fast" strata (processing high-frequency details) and "slow" strata (processing global context). This mimics the biological plausibility of neural oscillation coupling in the brain.

3. Phase Mesh Encoding (PME)

Replacing static positional embeddings, PME uses a system of coupled oscillators to encode position as a dynamic state. This allows the model to generalize to sequence lengths far beyond those seen during training.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

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


Developed with ❤️ by Unan

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

laminarnet-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

laminarnet-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file laminarnet-0.1.0.tar.gz.

File metadata

  • Download URL: laminarnet-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for laminarnet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9b1a5ef4747b96950f46da2c15566e9877e692c43e41e16b9f610139d38f136c
MD5 c73fa33e987ffaac7b44c67d7cbb8e39
BLAKE2b-256 be79357abbce528db3cc6ce2c8e719512e84ccb1859d7fa4612cb3c07bb0eb20

See more details on using hashes here.

File details

Details for the file laminarnet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: laminarnet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for laminarnet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b48c6ec726d50ab181883358edb504060da28bffe02ddcb443ae712ff719e099
MD5 98c968c286222af04e7ad684c1b445b0
BLAKE2b-256 48094d414ed72b5d230ada2938bad52c163aee77eb2f89786b40b7b042bc2255

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