Skip to main content

RaGLU

Pure Rational GLU (RaGLU) ve RaLU aktivasyon fonksiyonları için platform bağımsız PyTorch kütüphanesi. NVIDIA CUDA'da isteğe bağlı Triton çekirdekleri, Apple Silicon'da ise yerel MLX desteği sunar.

Paket iki nn.Module sınıfı sunar:

Sınıf Görevi
RaGLU() Kapılı (GLU) katman: Linear çıktısını gate/val olarak ikiye böler, f(g) * v uygular.
RaLU() Kapısız, element-wise aktivasyon: f(x) uygular, şekli değiştirmez.

Fonksiyonlar

Kapılı (gated) varyant:

$$ \operatorname{RaGLU}(g, v) = \frac{g^3 + g}{g^2 + 3} \cdot v $$

Kapısız varyant:

$$ \operatorname{RaLU}(x) = \frac{x^3 + x}{x^2 + 3} $$

Türev (her iki varyantın çekirdeği):

$$ \frac{d}{dx}\left(\frac{x^3 + x}{x^2 + 3}\right) = \frac{x^4 + 8x^2 + 3}{(x^2 + 3)^2} $$

Fonksiyon tek (odd) bir fonksiyondur: f(-x) = -f(x). Payda her zaman >= 3 olduğundan sayısal olarak kararlıdır.

Kurulum

pip install raglu

İsteğe bağlı hızlandırıcılar:

pip install "raglu[triton]"   # NVIDIA CUDA için Triton çekirdekleri
pip install "raglu[mlx]"      # Apple Silicon için MLX
pip install "raglu[dev]"      # test + derleme araçları

Kullanım

Fonksiyonel PyTorch API

import torch
from raglu import fused_pure_rational_glu, fused_pure_rational

gate = torch.randn(32, 128)
val = torch.randn(32, 128)

y = fused_pure_rational_glu(gate, val)  # (32, 128)
z = fused_pure_rational(gate)           # (32, 128)

fused_pure_rational_glu, CUDA + Triton mevcutsa füzyonlu çekirdeği kullanır. Aksi halde otomatik olarak CPU/MPS uyumlu PyTorch fallback'ine döner. Her iki yol da autograd desteklidir.

Katmanlar

import torch
from raglu import RaGLU, RaLU

# Girdiyi 2 * out_features boyutuna genişletip gate/val olarak böler.
layer = RaGLU(in_features=768, out_features=768)
x = torch.randn(8, 128, 768)
y = layer(x)  # (8, 128, 768)

# Kapısız aktivasyon
act = RaLU()
z = act(x)    # (8, 128, 768)

Hazır gate ve val modülleri de kullanılabilir:

from torch import nn
from raglu import RaGLU

layer = RaGLU(
    gate=nn.Linear(768, 1024),
    val=nn.Linear(768, 1024),
)

Apple MLX

import mlx.core as mx
from raglu import mlx_pure_rational_glu, mlx_pure_rational

gate = mx.random.normal((32, 128))
val = mx.random.normal((32, 128))

y = mlx_pure_rational_glu(gate, val)
z = mlx_pure_rational(gate)

MLX kurulu değilse bu semboller dışa aktarılmaz; raglu.HAS_MLX ile kontrol edebilirsiniz.

API

Sembol Açıklama
raglu.fused_pure_rational_glu(gate, val) Kapılı Pure Rational GLU (Triton/CUDA veya PyTorch fallback)
raglu.fused_pure_rational(x) Kapısız RaLU aktivasyonu
raglu.RaGLU Doğrusal katman + Pure Rational GLU nn.Module'ü
raglu.RaLU Element-wise RaLU nn.Module'ü
raglu.mlx_pure_rational_glu MLX kapılı varyant (MLX varsa)
raglu.mlx_pure_rational MLX kapısız varyant (MLX varsa)
raglu.HAS_TRITON Triton çekirdeklerinin kullanılabilirliği
raglu.HAS_MLX MLX'in kullanılabilirliği

Not: CUDA clamp

Triton çekirdekleri sayısal kararlılık için kapı değerini [-50, 50] aralığına kırpar. Bu aralığın dışındaki değerlerde Triton ve fallback çıktıları farklılaşabilir; pratik aktivasyon girdilerinde fark yoktur.

Geliştirme

git clone <repo-url>
cd RaGLU
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest -v

Triton testleri yalnızca CUDA + Triton mevcut olduğunda, MLX testleri ise yalnızca MLX kurulu olduğunda çalışır; diğer ortamlarda otomatik atlanır.

Paket derleme

python -m build
python -m twine check dist/*

Lisans

MIT — bkz. LICENSE.

Copyright (c) 2026 Ömer Faruk Solmaz

Metadata

Release files for raglu 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 raglu 0.1.0
File Size Uploaded Provenance Actions
raglu-0.1.0.tar.gz 9.3 kB Without provenance Details for raglu-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 16.8 kB

Release files / raglu-0.1.0.tar.gz

Download URL raglu-0.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e420da3bd00a85fba93c3a3d33d9cd3577ff07512f25543a95d85a3980099c6c
BLAKE2b-256 checksum
How to use checksums
1dea560882da4088ac43a49f8803fce2aa32e467a279ab203962716042181fe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / raglu-0.1.0-py3-none-any.whl

Download URL raglu-0.1.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72c62e98dfaed0f1a441024a1b1af7a5417b0fddec89d11a70000b72942370d7
BLAKE2b-256 checksum
How to use checksums
8f90a35ad9139d1aafb3f362e982c77e5d3525b479a5377dd0464f1ff9eabcd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for raglu 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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