Loomy
Loomy (luminamoon) provides low-precision numerical optimization, rational neural network layers, and dataset text preprocessing utilities developed by Silver Moon (@cloverxion) and Lumina Moon (@cloverx-id) contributors.
Written in Rust and Python, it includes:
Projects & Components
| Project / Component | Path | Status | Description | Documentation |
|---|---|---|---|---|
| LuminaV Optimizer | optimizer/ |
Active (v2.0.0rc1) |
LuminaV v2.0.0 optimizer with CPU SIMD (AVX-512/AVX2/NEON), optional CubeCL GPU backend, Triton AOT (182 ELF64 GPU binaries) / JIT kernels, Triangle Family (buffer="T1", "T2"), CWD, RTV, opt-in RPM (momentum_type="rpm", pairwise Cayley rotation), configurable bound_floor, FSDP2/DTensor/HSDP sync, and MurmurHash3 + 3D Weyl-Kronecker stochastic rounding. |
Optimizer Guide |
| LuminaMoon Data Engine | data/ |
Active (v2.0.0rc1) |
Data pipeline and text preprocessing library: DataPipeline, TokenBatch, SequencePacker, AVX-512/AVX2/NEON SIMD normalization, StringTensor (Arrow PyCapsule + GPU buffers), Shannon entropy filtering, XXH3-128 WAL & MinHash LSH deduplication, PII masking, TokenRingBuffer, and 256B LMDL v2 Ping-Pong checkpoint recovery. |
Data Engine Guide |
| LSO-Eval | eval/ |
Active |
Optimizer evaluation and Z3/parity checks: Z3 SMT solver checks, 2D trajectory benchmarks, numerical parity tests, and Two-Class 4B LLM & Vision evaluation. | LSO-Eval Guide |
| Changelogs | changelogs/ |
Active |
Version histories separating Software Package releases (v1.0.0–v2.0.0rc1) and LuminaV Algorithm Math versions (v1.0.0–v2.0.0). |
Changelogs |
| Documentation | docs/ |
Active |
Documentation index, developer guides (docs/optimize/, docs/dataloader/), and dependency compatibility notes (docs/dependencies/). |
Docs Index |
| Ra-Family Architecture | python/luminamoon/nn/ |
Active (v2.0.0rc1) |
Rational, tanh-free & square-root-free neural layers (RaNorm, RaSwiGLU, RaAttention, LinearCrossEntropy, RaMoE, and functional counterparts), plus PyTorch position, latent/slot attention, reversible blocks, and memory modules (QRoPE, LatentKVAttention, ReversibleDKDBlock, ReversibleDKDStack, OrthogonalHub, TwoTierMemory). |
Ra-Family Guide |
| Python Package & CLI | python/luminamoon/ |
Active (v2.0.0rc1) |
Lazy-loaded free-threaded (abi3t) Python namespace exposing optimizer, nn, data, and interactive CLI (luminamoon --help / lm.help()). |
API Reference |
| Theoretical References | references/ |
Active |
Comparison with prior work, mathematical formulas, component mapping, literature notes, and BibTeX citations for LuminaV, Ra-Family, and Data Engine. | References Guide |
Quickstart
Installation
Install the current v2.0.0rc1 pre-release from PyPI (once 2.0.0 GA ships, pip install luminamoon installs 2.0.0+ directly). Because the core package declares dependencies = [], include the optional extras matching your workflow:
pip install --pre luminamoon # Core Rust/Python package (no mandatory deps)
pip install --pre "luminamoon[torch]" # PyTorch optimizer & Ra-Family layers
pip install --pre "luminamoon[numpy]" # Standalone NumPy & DataPipeline packing
pip install --pre "luminamoon[all]" # Complete stack (NumPy, PyTorch, Triton GPU, Arrow, Polars)
Or build from source using Maturin and the Rust 2024 toolchain:
git clone https://github.com/cloverx-id/luminamoon.git
cd luminamoon
pip install maturin
maturin develop --release
Basic Usage (LuminaV Optimizer)
import numpy as np
from luminamoon import LuminaV
# Initialize parameters
weights = np.random.randn(64, 10).astype(np.float32)
biases = np.zeros(10, dtype=np.float32)
# Instantiate LuminaV optimizer (uses default hyperparameters)
optimizer = LuminaV([weights, biases], lr=3e-4, weight_decay=0.08, buffer=2)
# Execute optimization step with explicit gradients
grad_w = np.random.randn(64, 10).astype(np.float32)
grad_b = np.random.randn(10, dtype=np.float32)
optimizer.step(grads=[grad_w, grad_b])
For PyTorch deep learning workflows, see the PyTorch Integration Guide.
LuminaV Hyperparameter Quick Reference
All default values below are defined in luminamoon.optimizer.constants and printed by lm.help("optimizer"):
| Parameter | Type | Default | Description |
|---|---|---|---|
lr |
float |
3e-4 (0.0003) |
Learning rate (η). |
betas |
Tuple[float, float] |
(0.9, 0.999) |
Exponential moving average factors (β₁, β₂) for first-moment momentum and second-moment variance. |
eps |
float |
1e-8 |
Numerical stability constant (ε) in the adaptive denominator. |
weight_decay |
float |
0.08 (8e-2) |
Decoupled weight decay coefficient. |
cautious_weight_decay |
bool |
False |
Applies decoupled weight decay only where step_val * param >= 0.0 (CWD). |
variance_type |
str |
"standard" |
2-buffer variance update: "standard" (L2) or "rtv" (Rational-Tempered Variance). |
variance_temper |
float |
3.0 |
Outlier-tempering ratio for "rtv" relative to max(sigma_prev, abs(m_prev)). |
momentum_type |
str |
"standard" |
Momentum update mode: "standard" (EMA) or "rpm" (opt-in pairwise Cayley rotation on adjacent coordinates with no extra state). |
tau |
float |
0.8 |
Denominator temperature scaling factor (τ) for 2-buffer variance damping. |
lam |
float |
0.3 |
Triangle-defect penalty weight (λ) on abs(d_t) = abs(g_t - m_{t-1}) in 1-Buffer TD-CLM (buffer=1) and Triangle Family (buffer="T1", "T2"). |
cautious |
bool |
True |
Enables sign-aligned cautious update masking and lagged EMA scaling. |
cautious_clamp_min |
float |
0.5 |
Lower bound in (0.0, 1.0] for cautious alignment scaling. |
buffer |
int | str |
2 |
State mode: 2 for 2-Buffer CLM, 1 for 1-Buffer TD-CLM, "T2" ("t2") for 2-Buffer Triangle Family (tanh-free), or "T1" ("t1") for 1-Buffer Triangle Family (tanh-free). |
stochastic_rounding |
bool |
True |
Applies MurmurHash3 + 3D Weyl-Kronecker stochastic rounding when writing to bfloat16 / float16 weights and states. |
bound |
bool |
True |
Enables adaptive update bounding. |
bound_type |
str |
"coordinate" |
Bounding mode: "coordinate" (element-wise) or "radial" (global norm ratio). |
bound_ratio |
float |
0.05 |
Maximum update magnitude relative to parameter scale. |
bound_floor |
float |
1e-2 |
Coordinate bound floor radius f: rho * (abs(p) + f) ("T1", "T2") or rho * sqrt(p^2 + f^2) (1, 2). |
master_weights |
str |
"none" |
Mixed-precision master weight mode for bfloat16/float16: "none", "semi", or "full". |
execution |
str |
"auto" |
Hardware backend: "auto", "triton", "cubecl", "simd", "eager", or "scalar". |
fused_single_pass |
bool |
True |
Fuses parameter update and scalar reduction statistics into a single kernel pass. |
fuse_tensors |
bool |
False |
Coalesces parameters into contiguous 1D memory buffers to reduce kernel launch latency on fragmented architectures (e.g. Vision models / ViT). Not recommended for large LLMs or distributed FSDP training. |
bucket_cap_mb |
float |
500.0 |
Maximum memory capacity per contiguous bucket chunk in megabytes when fuse_tensors=True. Partitions large models into bounded chunks. Emits a UserWarning if set to a non-default value (!= 500.0) or overridden in a param group while fuse_tensors=False. |
prewarm_jit |
bool |
True |
Pre-compiles Triton GPU kernels on 64-element dummy buffers (lr=0.0) during initialization to avoid first-step JIT compilation delay. |
ema_decay |
str | float |
"auto" |
EMA decay for lagged cautious/radial scalars ("auto" resolves to 0.80 for buffer=2/"T2" and 0.95 for buffer=1/"T1"). |
fsdp_sync |
bool |
False |
Synchronizes global reduction scratch buffers across torch.distributed FSDP1, FSDP2 (DTensor), HSDP, and DDP shards. |
seed |
int |
1337 |
Base seed for deterministic MurmurHash3 + 3D Weyl-Kronecker stochastic rounding. |
tuning |
AutoTune | dict | None |
None |
Optional AutoTune(model[, loss_fn=...]) or override dict that replaces omitted defaults while preserving explicit arguments and saving resolved settings in state_dict()["luminav_tuning"]. |
Note on
torch.float16(FP16) Training: AlthoughLuminaVprotects its internal 16-bit state buffers from underflow via Bitwise-BF16 state promotion (8-bit exponent), the forward pass andloss.backward()across external model layers run outside the optimizer boundary. When training language models (Transformers/LLMs) or image/vision models (ViT, CNN, Diffusion) intorch.float16(5-bit exponent), enabletorch.amp.GradScalerso layer-to-layer gradients do not underflow to0.0or overflow duringloss.backward()before reachingoptimizer.step()(see the Mixed-Precision Guide).torch.bfloat16already has an 8-bit exponent across the model graph and does not requireGradScaler.
Software vs. Algorithm Versioning (v2.0.0rc1 / Math v2.0.0) & CLI Help
luminamoon tracks two read-only version identifiers (documented in changelogs/):
Software Package Version (
v2.0.0rc1):- Tracks the package distribution, Python FFI bindings, Rust crates,
luminamoon.nn, andluminamoon.data. - To run an older package release, install it directly via
pip install luminamoon==<version>or check out its git tag. - See
changelogs/SOFTWARE_CHANGELOG.md.
- Tracks the package distribution, Python FFI bindings, Rust crates,
LuminaV Algorithm Math Version (
v2.0.0):- Tracks the optimizer mathematical specification (Dual-Buffer CLM, Single-Buffer TD-CLM, Triangle Family
T1/T2, CWD, RTV, RPM, and MurmurHash3 + 3D Weyl-Kronecker stochastic rounding). - Exposed read-only via
LuminaV.MATH_VERSIONandLuminaV.get_math_version(). - See
changelogs/LUMINAV_ALGORITHM_CHANGELOG.md.
- Tracks the optimizer mathematical specification (Dual-Buffer CLM, Single-Buffer TD-CLM, Triangle Family
API 2.0 Stability & Deprecation Policy (Effective at
2.0.0GA):- Note that
v2.0.0rc1is a release candidate and public APIs may still adjust before2.0.0GA. - Starting from
2.0.0GA, public interfaces (LuminaV,luminamoon.nn,luminamoon.data, andluminamoon.cli) aim to keep backward compatibility across2.x.yreleases; any deprecated public symbol or parameter emits an explicitDeprecationWarningand remains supported for 5 to 8 minor releases (2.<minor>.x) before removal. - See
docs/en/03_configuration_api.md.
- Note that
import luminamoon as lm
from luminamoon import LuminaV
print(lm.__version__) # Software package version ("2.0.0rc1")
print(lm.get_version()) # Software package version (read-only helper)
print(LuminaV.MATH_VERSION) # "2.0.0" (optimizer math version)
print(LuminaV.get_math_version()) # "2.0.0"
lm.help("optimizer") # Print LuminaV parameter reference
lm.help("hardware") # Print detected CPU/GPU backend summary
# Terminal / notebook interactive API & hardware reference
luminamoon --help
luminamoon --topic=optimizer --output=luminav_help.txt
luminamoon --version
Basic Usage (LuminaMoon Data Engine: DataPipeline & Packed TokenBatch)
from luminamoon.data import DataPipeline
raw_data = [
"LuminaMoon streams, cleans, deduplicates, and packs training corpora.",
"Best-Fit packing avoids random document truncation across sequence boundaries.",
]
my_tokenizer = lambda text: [ord(ch) % 256 for ch in text]
# v2.0 streaming pipeline: clean, quality-filter, XXH3-128 dedup, pack, and checkpoint
pipe = DataPipeline(
source=raw_data,
tokenizer=my_tokenizer,
batch_size=1,
seq_len=64,
packing="best_fit", # Document-isolated Best-Fit packing
quality="pretraining", # Heuristic Shannon entropy, repetition, and symbol filters
dedup="exact", # 128-bit XXH3-128 with O(delta) append-only LMWL v2 WAL
checkpoint="./cache/train", # Resumable .state.json + .dedup checkpointing
)
for batch in pipe:
# Pass batch.doc_ids directly to RaAttention / ra_attention for Triton SRAM
# block-sparse document isolation without materializing an [N, N] mask.
# Or call batch.causal_doc_mask() for standard attention layers.
# Forward / backward / optimizer.step() ...
pipe.commit() # Saves consumed document positions atomically
For lower-level FusedPipeline, StringTensor (Arrow PyCapsule + GPU buffers), SequencePacker, TokenRingBuffer, and ResumablePipeline, see the Data Engine Guide.
Basic Usage (Ra-Family Rational Neural Architecture)
import torch
from luminamoon.nn import RaNorm, RaSwiGLU, RaAttention
# 1. Square-root-free token normalization (L1-mean)
norm = RaNorm(512)
x = torch.randn(2, 64, 512)
x_norm = norm(x)
# 2. Rational SwiGLU FFN block (strictly positive rational gate, 0 per-element exp)
mlp = RaSwiGLU(512, hidden_features=1365)
x_ffn = mlp(x_norm)
# 3. Cayley-Padé rational multi-head attention (SFU-free softmax)
attn = RaAttention(dim=512, num_heads=8, qk_norm=True, is_causal=True)
out = attn(x_norm)
For architecture details, Conv2d parameter folding, reversible/latent/memory modules, and standalone NumPy usage, see the Ra-Family Guide.
Verification & CI/CD
All pull requests and releases are tested across Linux, Windows, and macOS:
# Run static analysis across the Rust workspace
cargo clippy --workspace --all-targets -- -D warnings
# Run Rust workspace unit and parity tests (Optimizer + Data Engine)
cargo test --workspace
# Run Python static type check
npx pyright python/luminamoon
# Run Python tests
pytest -q tests/
python optimizer/tests/test_standalone_numpy.py
python optimizer/tests/test_end_to_end_training.py
python -B tests/test_gpu_vs_cpu_strings.py
# Run LSO-Eval verification
python -m eval
Developer Resources
For contributors working on Loomy (luminamoon):
- Changelogs (Software & Algorithm):
changelogs/ - Optimizer Modular Documentation:
docs/optimize/ - Data Engine Modular Documentation:
docs/dataloader/ - Workspace Dependency Notes:
docs/dependencies/ - Data Engine Architecture & User Guide:
data/README.md - User Documentation:
docs/en/
Theoretical References & Citation
LuminaMoon's algorithms are built upon published mathematical principles, including Maligranda's triangle inequality envelopes, rational neural networks, and decoupled weight decay.
For the full component mapping, literature comparisons, and BibTeX entries, see references/README.md and references/bibliography.bib.
To cite this repository in academic work:
@misc{loomy2026,
author = {Silver Moon and {Lumina Moon contributors}},
title = {Loomy: Low-Precision Numerical Optimization, Rational Neural Architecture, and Data Processing Repository},
year = {2026},
publisher = {GitHub},
howpublished = {\url{https://github.com/cloverx-id/luminamoon}},
doi = {10.5281/zenodo.23973325},
note = {Loomy repository}
}
Authors & Maintenance
Loomy (luminamoon) is developed and maintained by:
- Silver Moon (@cloverxion)
- Lumina Moon (@cloverx-id) contributors
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
- Downloads last month
- 991