Skip to main content

Frankenstein Transformer

Python 3.10+ PyTorch 2.0+ License: MIT CI PyPI Docs

See frankenstein-transformer for a web interface to configure your YAML!

Frankenstein Transformer command and pipeline flow: define, validate, train, checkpoint, ship, use

One config, six stages in three phases. Define + validate → train + checkpoint → deploy/export + infer. The figure maps the four CLI commands onto the pipeline; deploy --format transformers|gguf additionally takes --yaml, and infer --task sbert takes --mode.

At a Glance

A schema-first, config-driven transformer experimentation toolkit: pick mixers, optimizers, norms and positional encodings from one strict JSON-Schema-validated YAML — no code changes needed.

Mixers Optimizers Pos. Encodings Activations Norms Model Classes Tasks Presets CLI Commands
49 36 12 43 6 4 9 189 4

49 mixer architectures — 48 mixer classes plus the mamba linear passthrough; the schema exposes all 49 layer_pattern values. The positional-encoding count includes none; 11 methods inject position.

How It Works

Stage What happens
1. YAML config Describe the model, task and optimizer in one schema-first file
2. Schema validation Strict JSON Schema plus cross-field rules; invalid configs are rejected before any compute
3. Train 36 optimizer families, AMP, schedulers and a GPU thermal guard
4. Checkpoint Save rolling checkpoints for resuming or deployment
5. Deploy Quantize (quantized/standard) or export to HuggingFace safetensors (q8_0/q4_0/i2_s) / GGUF
6. Infer / Export Batch, interactive and benchmark inference; SBERT similarity/search/cluster/encode

The Streamlit schema-driven YAML builder (web-server).

web capture

Model Classes & Tasks

Model Class Role Training Tasks
frankenstein_text_encoder Encoder (mixed attention) mlm, sbert, text_classification
frankenstein_text_decoder Causal decoder causal_lm
frankenstein_vit Vision transformer patch_prediction, classification, segmentation
frankenstein_audio Audio encoder asr, audio_classification

Quick Start

Python >= 3.10 required.

Method Command
uv (recommended, CUDA 11.8) git clone https://github.com/erickfmm/frankenstein-transformer.git && cd frankenstein-transformer && uv sync --extra cu118 --extra train
uv (CPU only) uv sync --extra cpu --extra train
pip (CPU) python -m venv .venv && source .venv/bin/activate && pip install -e ".[cpu,train]"
pip (CUDA 11.8) pip install -e ".[cu118,train]"
PyPI pip install frankenstein-transformer

Run uv-installed commands through uv run --extra cu118 --extra train <cmd> (e.g. uv run --extra cu118 --extra train frankenstein-transformer --help). Other torch extras: cu126 (driver ≥ 560), cu128 (driver ≥ 570). Always repeat the same extras, or uv will re-sync and swap the torch wheel.

Full installation reference (extras, CUDA selection, plugins, build, troubleshooting): INSTALL.md.

Verify: frankenstein-transformer --help

List available named presets: frankenstein-transformer train --list-configs

Plugins and the Component Registry

Every pluggable component (mixer, optimizer, norm, activation, residual, positional encoding, token embedding) is a declarative ComponentSpec registered through src/registry/. The schema enums, per-mixer parameter blocks, optimizer by_optimizer reference and if/then prefix rules are generated from the registry before validation, so a component is declared once and cannot drift across parallel lists.

Plugins use the same API. A local file needs no installation — reference it from the config:

plugins:
  - ./examples/plugins/window_mixer.py

model:
  attention:
    local_window: {window_size: 128}
  dims:
    layer_pattern: [local_window, standard]
from src.plugins.api import register_mixer

register_mixer(
    name="local_window",
    builder="my_plugin.window:LocalWindowAttention",   # or a callable
    description="Local windowed self-attention.",
    description_es="Autoatención local por ventana.",
    params_schema={
        "type": "object",
        "additionalProperties": False,
        "properties": {"window_size": {"type": "integer", "minimum": 1, "default": 128}},
    },
    defaults={"window_size": 128},
)

Distributable plugins advertise the frankenstein.plugins entry-point group and are installed as separate packages. See HOWTO_MAKE_PLUGIN.md for every family, the parameter contract, packaging, testing and pitfalls. A registered component validates strictly, renders in the Streamlit builder and is dispatched by the same core code as the built-ins.

Feature Matrix

Feature Scale
Sequence mixer architectures 49 across 10 families: Dense, GQA, Recurrent, Sparse, Gated, Fast-Weight, Latent, Geometric, Convolution-augmented, Memory
Optimizer families 36 across 8 categories
Positional encodings 12 model-wide (11 active + none): rope, hope, nope, alibi, bam, pape*, sinusoidal_*, learned_absolute, with per-mixer opt-out
FFN activations 43 (40 elementwise + swiglu, geglu, reglu)
Residual connections 6 exposed: standard, none, full_attn, block_attn, mHC, Hyperloop
Embedding variants 12 positional encodings + 4 structural optimizations (factorized, embedding conv, dynamic EELBERT, audio frontend)
Model classes frankenstein_text_encoder, frankenstein_text_decoder, frankenstein_vit, frankenstein_audio + reusable in-process engine API
Training tasks mlm, sbert, causal_lm, patch_prediction, classification, segmentation, text_classification, asr, audio_classification
Normalization types layer_norm, dynamic_tanh, derf, rms_norm, prms_norm, flash_norm
Config presets 54 named presets + 135 example configs (schema smoke-tested in CI)
CLI subcommands 4 (train, deploy, infer, web-server)
Web configuration UI Streamlit schema-driven YAML builder
Quantized deployment BitNet + checkpoint export pipeline (HF safetensors q8_0/q4_0/i2_s / GGUF)
SBERT workflows Training + inference (similarity, search, cluster, encode)
DashAI integration dashai-frankenstein plugin (MLM classifier, causal decoder, ViT classifier, ViT segmenter)

Architecture Decision Table

Model Class Mode Use Case
frankenstein_text_encoder Encoder Full-featured MLM pre-training with mixed attention, MoE, and all 49 mixer architectures
frankenstein_text_decoder Decoder Autoregressive causal decoder for LLM-style generation; forces mode: decoder
frankenstein_vit Encoder (vision) Vision Transformer (arXiv:2010.11929) for image understanding: patch prediction, classification, segmentation (arXiv:2503.19108); forces mode: encoder, requires image: + vision_dataset: blocks
frankenstein_audio Encoder (audio) Audio Transformer for ASR and audio/signal classification; log-mel/spectrogram/raw frontend, conv subsampling, CTC/RNN-T or classification heads; forces mode: encoder, requires audio: + audio_dataset: blocks

See configs/README.md for preset details and docs/architecture.md for the architecture spec and extension guide.

CLI Command Reference

Subcommand Purpose Example
train Run schema-validated training frankenstein-transformer train --config-name frankenstein_text_encoder --device auto
deploy Export checkpoint to deployment artifacts (quantized/standard) or formats (transformers, gguf) frankenstein-transformer deploy --checkpoint ckpt.pt --output deployed/ --format quantized
deploy --format transformers Safetensors-only HuggingFace export; optional block quantization frankenstein-transformer deploy --checkpoint ckpt.pt --yaml train.yaml --output hf/ --format transformers --quant q4_0 --quant-runtime quantized_linear
infer Batch/interactive/benchmark inference (--task mlm) or SBERT similarity/search/cluster/encode (--task sbert) frankenstein-transformer infer --model deployed/ --text "hello" --device auto
web-server Launch Streamlit config builder UI frankenstein-transformer web-server

All model-executing commands accept --device auto|cpu|cuda|mps.

Mixer Categories

Category Code Names Description
Dense (3) standard, sigmoid, ca Full quadratic attention variants: softmax, sigmoid gating, and exact continuum integration
GQA (1) gqa Grouped-query attention with configurable KV heads
Recurrent (5) retnet, mamba, ode, titan, engram Retention networks, state-space models, continuous-depth ODE layers, memory-augmented attention, and n-gram memory
Sparse (12) sparse_transformer, longformer, swa, bigbird, sparsek, nsa, sparge ⚠️, fasa ⚠️, msa, sparda, lsa, fastconformer Factorized, sliding-window, token-selection, block-sparse (GQA-based), semantic key-clustering, and head-pinned global-token long-form patterns
Gated (9) gla, deltanet, gated_deltanet, gated_deltanet2, hgrn2, fox, fpa, gated_softmax, kda Linear attention with multiplicative gates, delta rules, gated softmax, and path-extremum forgetting
Fast-Weight (6) falcon1, falcon2, falcon3, falcon1a, falcon2a, falcon3a Fast-weight / online-learning attention with per-layer fast-weight update rules
Latent (10) mla, gqla, mlra, tucker, iha, gta, mtla, cca, ccgqa, gma KV-compression and head-mixing variants generalising GQA (latent attention, Tucker factorisation, interleaved pseudo-heads, temporal merging, compressed convolutional attention, Gaussian mixture attention)
Geometric (1) ssog Separable Sum of Gaussians — geometric field attention
Convolution-augmented (1) conformer Macaron FFN₁ + MHSA + depthwise-conv module (arXiv:2005.08100)
Memory (1) memory Token-ID memory values: V = K + Norm(E[s]); removes the value projection (arXiv:2609.28399)

⚠️ sparge and fasa are inference-sparse: they train as dense attention over their own projections, then activate their sparse heuristic in eval(). They are valid in training presets.

Configure via layer_pattern in YAML. The schema accepts 49 mixer values. See src/schema.yaml for the full mixer reference table and docs/architecture.md for the mixer registry and extension recipe.

Optimizer Categories

Category Optimizers Count
Classical sgd_momentum, adamw, radam 3
Momentum & Variance Reduction adan, adopt, ademamix, mars_adamw, cautious_adamw 5
Memory-Efficient & Low-Rank adafactor, galore_adamw, lion, apollo, apollo_mini, q_apollo, adam_pm 7
Schedule-Free & Parameter-Free schedulefree_adamw, prodigy, lamb 3
Second-Order sophia, shampoo, soap 3
Geometry-Oriented muon, turbo_muon, af_muon, ada_muon, dion3, root, muon2, nor_muon, conda, tuon, namo, namo_d 12
Adaptivity-Tunable anon 1
Evolutionary eve, ea4llm 2

Parameters use prefixed keys: <optimizer_class>-<group>_<param> (e.g. adamw-lr_embeddings, muon-ns_steps). See configs/README.md for the full parameter reference.

Optimizer state profile. State buffers range from 0 (EA4LLM, gradient-free) to 12 tensors per slot (EvE, population-based). GaLore, APOLLO and Q-APOLLO keep factored or quantized state; Shampoo and SOAP keep per-dimension preconditioners; Muon-family optimizers orthogonalise hidden 2-D matrices and fall back to AdamW for embeddings, heads, positional parameters and vectors.

Component Catalog

This section condenses the comprehensive summary tables annex. Counts and names are verified against the schema enums and the implementation registry.

Normalization (6)

Method Formula / transform Stats needed
layer_norm γ(x − μ)/√(σ² + ε) + β mean + variance
rms_norm γx/√(mean(x²) + ε) RMS
prms_norm RMS over the first ⌈d·p⌉ dimensions (norm.partial_ratio) partial RMS
dynamic_tanh tanh(αx) with learnable scalar/vector α none
derf erf(αx + s) with learnable α, s none
flash_norm weightless RMS; the per-dimension scale is folded into the following projection RMS

Residual connections (6 exposed)

Scheme Stream update Constraint
Standard x ← x + F(x) identity skip
None x ← F(x) experimental; no skip path
Full AttnRes softmax over all previous layer outputs learned zero-init pseudo-query; L·C parameters; RMSNorm on keys
Block AttnRes softmax over block representatives + partial sum learned zero-init pseudo-query; L·C parameters
mHC HC update with a learned residual mapping H_res doubly stochastic via Sinkhorn–Knopp (t_max = 20); gated pre/post maps
Hyperloop loop-level HC on a middle block per-loop weights; copy/average expansion; diagonal, Sinkhorn or identity H_res

Unconstrained Hyper-Connections (HC) appear in the paper as the reference scheme but are not exposed by this codebase.

Activation functions (43)

Family Count Names
Classical 12 silu, gelu, gelu_tanh, relu, sigmoid, tanh, arctan, softsign, elliott, identity, softplus, mish
Rectified 12 leaky_relu, relu6, hardswish, prelu, abs_relu, nl_relu, brelu, vrelu, hexpo, ptanh, dis_relu, lisht
Exponential 12 elu, selu, celu, pelu, mpelu, felu, eelu, pdelu, preu, softexp, elish, hardelish
Learnable 4 swish, swish_trainable, maxout, raf
Gated FFN 3 swiglu, geglu, reglu

swish uses a fixed β; swish_trainable learns it. The GLU variants are implemented by GatedFFN, not by get_activation().

Positional encodings (12)

Encoding Profile
rope Rotary Q/K rotation; relative position through inner-product geometry
hope Hyperbolic rotary encoding with monotonic distance decay; RoPE is a special case
nope No explicit PE; position is learned from the causal mask
alibi Static distance-proportional penalty on attention scores
bam Generalised-Gaussian relative bias with learnable per-head shape/scale; recovers ALiBi at β = 1
pape Parabolic position basis appended to Q/K; n-D, vision-centric
pape_efficient Pure-PyTorch PaPE with a pre-computed layout
pape_ri Rotation-invariant, distance-only PaPE
sinusoidal_absolute Fixed sin/cos added to token embeddings
sinusoidal_rotary Absolute sin/cos rotation applied to Q/K
learned_absolute Learnable absolute position matrix added to embeddings
none Explicit null encoding

Structural embedding optimizations (4)

Variant Profile Control
Factorized embeddings V×H table decomposed into V×R and R×H factors factorized_embedding_dim
Embedding convolution Depthwise Conv1d over the embedding stream before the first block embedding_conv_kernel
Dynamic embeddings (EELBERT) On-the-fly n-gram hash pooling; frozen, no trainable embedding table embedding.dynamic.*
Audio frontend Log-mel/spectrogram/raw frames → two stride-2 Conv2d stages → linear projection audio.*

Engine API & DashAI Plugin

Beyond the CLI, a thin in-process engine API (src/engine.py) exposes model construction, tokenizer setup, dataset wiring, and the training loop as plain Python functions — no argparse, no subprocesses:

from src.engine import build_model, train_from_config, save_checkpoint, load_checkpoint

This engine powers the dashai-frankenstein plugin, which registers Frankenstein's model classes as DashAI components (9 dashai.plugins entry points): FrankensteinMLMModel (classification via the MLM encoder), FrankensteinPretrainer (MLM pre-training), FrankensteinDecoderModel (generative), FrankensteinCausalLMModel (causal-LM pre-training), FrankensteinViTClassifier, FrankensteinViTSegmenter, plus the plugin-provided MaskedLanguageModelingTask, CausalLMPretrainingTask and SegmentationTask. Both packages are published on PyPI (frankenstein-transformer, dashai-frankenstein); see docs/dashai-plugin-audit.md for the integration design.

Documentation Map

Resource Content
INSTALL.md Installation matrix: uv/pip, CPU/CUDA extras, plugins, verification, troubleshooting
HOWTO_MAKE_PLUGIN.md Plugin authoring guide: specs, all seven families, packaging, testing, pitfalls
configs/README.md Schema walkthrough, preset details, optimizer parameter reference
src/schema.yaml Hand-authored training schema; component enums/fragments are injected by src/registry/schema_assembly.py
docs/schema.assembled.yaml Fully assembled schema snapshot (what validation and the website consume)
docs/README.md Documentation index and build instructions
docs/paper/paper.pdf Technical report (English)
docs/paper-es/paper-es.pdf Technical report (Spanish)
docs/paper/appendices/annex-summary-tables.tex Comprehensive component catalog: all mixers, optimizers, norms, residuals, activations and embeddings
docs/figures/readme-command-flow.mmd Source for the README command/pipeline figure
docs/architecture.md Canonical implementation spec: architecture, state, extension guide
docs/architecture.md Vision Transformer (frankenstein_vit) — patch prediction, classification, segmentation
docs/architecture.md Component registry, plugin schema assembly, and mixer selection guide (49 architectures / 10 families)
docs/dashai-plugin-audit.md DashAI plugin integration design and status
frankenstein-transformer.readthedocs.io Full hosted documentation (specification, API, papers, bibliography)
docs/transformers_compatibility.md HuggingFace export compatibility guide

Quick Training Example

Minimal YAML config (my_config.yaml) — only the 5 required model fields plus task; everything else uses FrankensteinModelConfig/TrainingConfig defaults:

model_class: frankenstein_text_encoder
model:
  vocab_size: 30522
  hidden_size: 256
  num_layers: 4
  num_heads: 8
  layer_pattern: [standard, standard, standard, standard]
training:
  task: mlm
  batch_size: 8
  max_length: 128
  mlm_probability: 0.15
  max_samples: 100000
  dataset_batch_size: 10000
  num_workers: 4
  cache_dir: "./temp_data/cache"
  optimizer:
    optimizer_class: adamw
    parameters:
      adamw-lr_embeddings: 1e-4
      adamw-lr_norms: 1e-4
      adamw-lr_attention: 1e-4
      adamw-lr_other: 1e-4
      adamw-wd_embeddings: 0.01
      adamw-wd_norms: 0.01
      adamw-wd_attention: 0.01
      adamw-wd_other: 0.01
      adamw-betas_embeddings: [0.9, 0.95]
      adamw-betas_norms: [0.9, 0.95]
      adamw-betas_attention: [0.9, 0.95]
      adamw-betas_other: [0.9, 0.95]
      adamw-eps_embeddings: 1e-8
      adamw-eps_norms: 1e-8
      adamw-eps_attention: 1e-8
      adamw-eps_other: 1e-8
  scheduler_total_steps: 1000

Unspecified model fields fall back to FrankensteinModelConfig defaults (num_loops=2, dropout=0.1, norm_type=dynamic_tanh, use_moe=true, ffn_activation=silu, etc.). Unspecified training fields fall back to TrainingConfig defaults (scheduler_type=cosine, grad_clip_max_norm=5.0, gpu_temp_guard_enabled=true, etc.). Override only what you need to change.

Run:

frankenstein-transformer train --config my_config.yaml --device auto

Vision Transformer (frankenstein_vit) Example

The frankenstein_vit model class (arXiv:2010.11929) splits images into patches, embeds them, and processes the sequence through the same HybridLayer stack as the text models. It supports three tasks: patch_prediction (autosupervised masked patch prediction), classification (image classification), and segmentation (per-pixel or EoMT query-based, arXiv:2503.19108).

Minimal classification YAML (vit_config.yaml):

model_class: frankenstein_vit
model:
  dims:
    hidden_size: 768
    num_layers: 12
    num_heads: 12
    layer_pattern: [standard]
    mode: encoder
  norm: {type: layer_norm}
  use_moe: false
  use_bitnet: false
  ffn_activation: gelu
  ffn_hidden_size: 3072
image:
  image_size: {height: 224, width: 224}
  patch_size: 16
  in_channels: 3
  pos_embedding_type: learned_1d
  cls_token: true
  pooling_mode: cls
  num_classes: 10
dataset:
  dataset_name: cifar10
  rescale: {height: 224, width: 224}
training:
  task: classification
  batch_size: 512
  num_epochs: 90
  optimizer:
    optimizer_class: adamw
    parameters:
      adamw-lr_other: 0.001
      adamw-wd_other: 0.1
  classification:
    batch_size: 512
    num_epochs: 90
    learning_rate: 0.001

Run: frankenstein-transformer train --config vit_config.yaml --device auto

See configs/frankenstein_vit_base.yaml for the full ViT-Base/16 preset and docs/architecture.md for the complete specification.

License

MIT License — Copyright (c) 2026 Erick Merino. See LICENSE for full text.

Metadata

Release files for frankenstein-transformer 2.0.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 frankenstein-transformer 2.0.0
File Size Uploaded Provenance Actions
frankenstein_transformer-2.0.0.tar.gz 805.4 kB With provenance Details for frankenstein_transformer-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for frankenstein-transformer 2.0.0
File Interpreter ABI Platform Actions
frankenstein_transformer-2.0.0-py3-none-any.whl Python 3 none any Details for frankenstein_transformer-2.0.0-py3-none-any.whl

Total release size: 1.8 MB

Release files / frankenstein_transformer-2.0.0.tar.gz

Download URL frankenstein_transformer-2.0.0.tar.gz
Size 805.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e7dd2897da225e29f89d4640f2521a9d814c238985a585d01a4b372819812d98
BLAKE2b-256 checksum
How to use checksums
038d203827197ed5e683b369c7fddf92bdddeee7f2d72e1f4850ff197a9488f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / frankenstein_transformer-2.0.0-py3-none-any.whl

Download URL frankenstein_transformer-2.0.0-py3-none-any.whl
Size 958.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99058f3009ee089679a2aadb15f95338af05ed664da6821993e03586a7f274af
BLAKE2b-256 checksum
How to use checksums
3de1d8f06127df234fd08743e0f3f8ca8ea25de2edea75974644ad52065f638c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for frankenstein-transformer 2.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for frankenstein_transformer-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

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.

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