Zarvan: A Hybrid MoE Architecture for Advanced Sequence Modeling.
Project description
Zarvan: A Hybrid MoE Architecture for Advanced Sequence Modeling
Zarvan is an advanced neural network architecture designed to overcome the fundamental limitations of Transformers and RNNs. By unifying the strengths of parallel processing and stateful reasoning, Zarvan provides a powerful, scalable solution for the next generation of sequence modeling challenges.
This library is built on pure PyTorch, offering a lightweight, independent, and high-performance implementation of the Zarvan architecture.
🚀 Key Features
- Hybrid Mixture-of-Experts (MoE) Architecture: Employs an intelligent MoE system that dynamically chooses between three "experts" to process a sequence: two for global pattern recognition and a dedicated state machine for step-by-step reasoning.
- Linear Time Complexity ($O(S)$): By replacing the quadratic ($O(S^2)$) self-attention mechanism, Zarvan is significantly more efficient and ideal for processing ultra-long sequences.
- 🧠 Stateful Sequential Reasoning: Features the Sequential Extractor, a deterministic state machine that maintains a perfect, non-decaying memory of the sequence history, enabling it to solve complex, path-dependent tasks where Transformers fail.
- ⚡ Lightweight & Independent: Built on pure PyTorch with zero external dependencies beyond
torch, ensuring easy integration, maximum flexibility, and no version conflicts.
🏛️ Architecture Overview
The core of Zarvan is a stack of identical blocks. Each block is a Mixture-of-Experts model that dynamically combines the outputs of three specialist modules via a learned gating network.
- Holistic Extractor: Captures the "gist" or overall summary of the sequence.
- Associative Extractor: Acts as a "focused memory" retriever for salient, sparse information.
- Sequential Extractor (The State Machine): Functions as a parallelized state machine that tracks the sequence history losslessly using gated accumulation and phase representation.
An Expert Gate then learns to weigh the outputs of these three modules for each token, allowing the model to adapt its strategy based on the input.
🚀 Installation
Install the package directly from PyPI:
pip install zarvan
Or after cloning the repository locally:
git clone [https://github.com/systbs/zarvan-torch.git](https://github.com/systbs/zarvan-torch.git)
cd zarvan-torch
pip install .
✨ Quick Start
Using the independent zarvan library is clean and simple.
import torch
from zarvan import Zarvan, ZarvanConfig
# 1. Define the model configuration
# The ZarvanConfig object holds all architectural hyperparameters.
config = ZarvanConfig(
vocab_size=10000,
embed_dim=256,
hidden_dim=1024,
num_heads=4,
num_layers=6,
num_classes=2, # For a binary classification task
max_len=128
)
# 2. Instantiate the model from the configuration
model = Zarvan(config)
model.eval() # Set to evaluation mode
num_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f"Model created successfully with {num_params / 1e6:.2f}M parameters.")
# 3. Create dummy input data
input_ids = torch.randint(0, config.vocab_size, (2, 50)) # (Batch, Sequence Length)
# 4. Perform a forward pass
# The output is a simple torch.Tensor containing the logits.
with torch.no_grad():
logits = model(input_ids)
print("\n--- I/O Shapes ---")
print("Input IDs shape:", input_ids.shape)
print("Logits shape:", logits.shape)
# Expected Logits shape: torch.Size([2, 50, 2])
# 5. Save and load the model using the built-in methods
save_directory = "./saved_zarvan_model"
model.save_pretrained(save_directory)
loaded_model = Zarvan.from_pretrained(save_directory)
# Verify that the loaded model works and produces the same output
with torch.no_grad():
loaded_logits = loaded_model(input_ids)
assert torch.allclose(logits, loaded_logits, atol=1e-5)
print("\nSaved and loaded model outputs match. ✅")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zarvan-0.1.4.tar.gz.
File metadata
- Download URL: zarvan-0.1.4.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e47cda7ed71360ba5ed43cbe1b070f5f95250789b851e83b417121059e0aba9
|
|
| MD5 |
8daeea7822dbb2c23f5520e6d685868f
|
|
| BLAKE2b-256 |
c5e4d094d91deb742d6163edb3664e7fb1ab8fc98c477b377b74b04c9f22ed90
|
File details
Details for the file zarvan-0.1.4-py3-none-any.whl.
File metadata
- Download URL: zarvan-0.1.4-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d22e5847d50ae490ae9c28c59a65ca6ed557cf9fa89d25bf57e3323b42b07316
|
|
| MD5 |
b3c482631b2257bd0c507e34404427c4
|
|
| BLAKE2b-256 |
6cefbdfc41858fc86df4e6d7451a2c1176d4a559a84687180becfed2f5fec278
|