frankenstein-transformer 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. frankenstein_transformer-1.0.0/.gitignore +35 -0
  2. frankenstein_transformer-1.0.0/LICENSE +21 -0
  3. frankenstein_transformer-1.0.0/PKG-INFO +282 -0
  4. frankenstein_transformer-1.0.0/README.md +248 -0
  5. frankenstein_transformer-1.0.0/pyproject.toml +149 -0
  6. frankenstein_transformer-1.0.0/src/__init__.py +0 -0
  7. frankenstein_transformer-1.0.0/src/cli.py +581 -0
  8. frankenstein_transformer-1.0.0/src/deploy/README.md +349 -0
  9. frankenstein_transformer-1.0.0/src/deploy/__init__.py +29 -0
  10. frankenstein_transformer-1.0.0/src/deploy/bitnet_gguf_export.py +508 -0
  11. frankenstein_transformer-1.0.0/src/deploy/deploy.py +386 -0
  12. frankenstein_transformer-1.0.0/src/deploy/deploy_pipeline.bat +67 -0
  13. frankenstein_transformer-1.0.0/src/deploy/deploy_pipeline.sh +61 -0
  14. frankenstein_transformer-1.0.0/src/deploy/example.py +107 -0
  15. frankenstein_transformer-1.0.0/src/deploy/inference.py +507 -0
  16. frankenstein_transformer-1.0.0/src/deploy/quantization.py +479 -0
  17. frankenstein_transformer-1.0.0/src/deploy/transformers_export.py +587 -0
  18. frankenstein_transformer-1.0.0/src/engine.py +1094 -0
  19. frankenstein_transformer-1.0.0/src/model/__init__.py +27 -0
  20. frankenstein_transformer-1.0.0/src/model/activation_function/__init__.py +121 -0
  21. frankenstein_transformer-1.0.0/src/model/activation_function/common.py +295 -0
  22. frankenstein_transformer-1.0.0/src/model/activation_function/exponential.py +408 -0
  23. frankenstein_transformer-1.0.0/src/model/activation_function/factory.py +259 -0
  24. frankenstein_transformer-1.0.0/src/model/activation_function/glu.py +132 -0
  25. frankenstein_transformer-1.0.0/src/model/activation_function/learnable.py +397 -0
  26. frankenstein_transformer-1.0.0/src/model/activation_function/rectified.py +336 -0
  27. frankenstein_transformer-1.0.0/src/model/attention/__init__.py +80 -0
  28. frankenstein_transformer-1.0.0/src/model/attention/common.py +234 -0
  29. frankenstein_transformer-1.0.0/src/model/attention/engram.py +342 -0
  30. frankenstein_transformer-1.0.0/src/model/attention/gated/__init__.py +21 -0
  31. frankenstein_transformer-1.0.0/src/model/attention/gated/deltanet_attn.py +155 -0
  32. frankenstein_transformer-1.0.0/src/model/attention/gated/fox_attn.py +145 -0
  33. frankenstein_transformer-1.0.0/src/model/attention/gated/gated_deltanet2_attn.py +223 -0
  34. frankenstein_transformer-1.0.0/src/model/attention/gated/gated_deltanet_attn.py +159 -0
  35. frankenstein_transformer-1.0.0/src/model/attention/gated/gated_softmax_attn.py +138 -0
  36. frankenstein_transformer-1.0.0/src/model/attention/gated/gla_attn.py +159 -0
  37. frankenstein_transformer-1.0.0/src/model/attention/gated/hgrn2_attn.py +157 -0
  38. frankenstein_transformer-1.0.0/src/model/attention/gated/kda_attn.py +204 -0
  39. frankenstein_transformer-1.0.0/src/model/attention/gated/retnet_attn.py +73 -0
  40. frankenstein_transformer-1.0.0/src/model/attention/grouped_query_attention.py +90 -0
  41. frankenstein_transformer-1.0.0/src/model/attention/latent/__init__.py +73 -0
  42. frankenstein_transformer-1.0.0/src/model/attention/latent/cca_attn.py +569 -0
  43. frankenstein_transformer-1.0.0/src/model/attention/latent/gqla_attn.py +148 -0
  44. frankenstein_transformer-1.0.0/src/model/attention/latent/gta_attn.py +127 -0
  45. frankenstein_transformer-1.0.0/src/model/attention/latent/iha_attn.py +124 -0
  46. frankenstein_transformer-1.0.0/src/model/attention/latent/mla_attn.py +145 -0
  47. frankenstein_transformer-1.0.0/src/model/attention/latent/mlra_attn.py +131 -0
  48. frankenstein_transformer-1.0.0/src/model/attention/latent/mtla_attn.py +151 -0
  49. frankenstein_transformer-1.0.0/src/model/attention/latent/tucker_attn.py +115 -0
  50. frankenstein_transformer-1.0.0/src/model/attention/ode.py +161 -0
  51. frankenstein_transformer-1.0.0/src/model/attention/retnet.py +135 -0
  52. frankenstein_transformer-1.0.0/src/model/attention/sigmoid.py +105 -0
  53. frankenstein_transformer-1.0.0/src/model/attention/sparse/__init__.py +21 -0
  54. frankenstein_transformer-1.0.0/src/model/attention/sparse/bigbird_attn.py +178 -0
  55. frankenstein_transformer-1.0.0/src/model/attention/sparse/fasa_attn.py +191 -0
  56. frankenstein_transformer-1.0.0/src/model/attention/sparse/longformer_attn.py +157 -0
  57. frankenstein_transformer-1.0.0/src/model/attention/sparse/msa_attn.py +254 -0
  58. frankenstein_transformer-1.0.0/src/model/attention/sparse/nsa_attn.py +253 -0
  59. frankenstein_transformer-1.0.0/src/model/attention/sparse/sparda_attn.py +198 -0
  60. frankenstein_transformer-1.0.0/src/model/attention/sparse/sparge_attn.py +190 -0
  61. frankenstein_transformer-1.0.0/src/model/attention/sparse/sparse_transformer_attn.py +216 -0
  62. frankenstein_transformer-1.0.0/src/model/attention/sparse/sparsek_attn.py +217 -0
  63. frankenstein_transformer-1.0.0/src/model/attention/standard.py +101 -0
  64. frankenstein_transformer-1.0.0/src/model/attention/titan.py +132 -0
  65. frankenstein_transformer-1.0.0/src/model/config.py +637 -0
  66. frankenstein_transformer-1.0.0/src/model/embeddings/__init__.py +17 -0
  67. frankenstein_transformer-1.0.0/src/model/embeddings/factorized_embedding.py +82 -0
  68. frankenstein_transformer-1.0.0/src/model/embeddings/hope.py +105 -0
  69. frankenstein_transformer-1.0.0/src/model/embeddings/rope.py +99 -0
  70. frankenstein_transformer-1.0.0/src/model/frankenstein_decoder.py +166 -0
  71. frankenstein_transformer-1.0.0/src/model/frankenstein_encoder.py +230 -0
  72. frankenstein_transformer-1.0.0/src/model/frankenstein_vit.py +478 -0
  73. frankenstein_transformer-1.0.0/src/model/hybrid_layer.py +538 -0
  74. frankenstein_transformer-1.0.0/src/model/mhc.py +249 -0
  75. frankenstein_transformer-1.0.0/src/model/norm/__init__.py +25 -0
  76. frankenstein_transformer-1.0.0/src/model/norm/derf.py +53 -0
  77. frankenstein_transformer-1.0.0/src/model/norm/dynamic_tanh.py +51 -0
  78. frankenstein_transformer-1.0.0/src/model/norm/factory.py +56 -0
  79. frankenstein_transformer-1.0.0/src/model/norm/flash.py +371 -0
  80. frankenstein_transformer-1.0.0/src/model/norm/rms.py +84 -0
  81. frankenstein_transformer-1.0.0/src/model/optimizer/__init__.py +50 -0
  82. frankenstein_transformer-1.0.0/src/model/optimizer/adafactor.py +157 -0
  83. frankenstein_transformer-1.0.0/src/model/optimizer/adamw.py +37 -0
  84. frankenstein_transformer-1.0.0/src/model/optimizer/adan.py +50 -0
  85. frankenstein_transformer-1.0.0/src/model/optimizer/ademamix.py +40 -0
  86. frankenstein_transformer-1.0.0/src/model/optimizer/adopt.py +40 -0
  87. frankenstein_transformer-1.0.0/src/model/optimizer/anon.py +207 -0
  88. frankenstein_transformer-1.0.0/src/model/optimizer/apollo.py +354 -0
  89. frankenstein_transformer-1.0.0/src/model/optimizer/apollo_mini.py +93 -0
  90. frankenstein_transformer-1.0.0/src/model/optimizer/base.py +194 -0
  91. frankenstein_transformer-1.0.0/src/model/optimizer/cautious_adamw.py +77 -0
  92. frankenstein_transformer-1.0.0/src/model/optimizer/factory.py +305 -0
  93. frankenstein_transformer-1.0.0/src/model/optimizer/galore_adamw.py +168 -0
  94. frankenstein_transformer-1.0.0/src/model/optimizer/lamb.py +111 -0
  95. frankenstein_transformer-1.0.0/src/model/optimizer/lion.py +103 -0
  96. frankenstein_transformer-1.0.0/src/model/optimizer/mars_adamw.py +40 -0
  97. frankenstein_transformer-1.0.0/src/model/optimizer/muon.py +142 -0
  98. frankenstein_transformer-1.0.0/src/model/optimizer/prodigy.py +145 -0
  99. frankenstein_transformer-1.0.0/src/model/optimizer/q_apollo.py +210 -0
  100. frankenstein_transformer-1.0.0/src/model/optimizer/radam.py +39 -0
  101. frankenstein_transformer-1.0.0/src/model/optimizer/schedulefree_adamw.py +41 -0
  102. frankenstein_transformer-1.0.0/src/model/optimizer/sgd_momentum.py +45 -0
  103. frankenstein_transformer-1.0.0/src/model/optimizer/shampoo.py +36 -0
  104. frankenstein_transformer-1.0.0/src/model/optimizer/soap.py +38 -0
  105. frankenstein_transformer-1.0.0/src/model/optimizer/sophia.py +138 -0
  106. frankenstein_transformer-1.0.0/src/model/optimizer/turbo_muon.py +140 -0
  107. frankenstein_transformer-1.0.0/src/model/residuals/__init__.py +39 -0
  108. frankenstein_transformer-1.0.0/src/model/residuals/base.py +163 -0
  109. frankenstein_transformer-1.0.0/src/model/residuals/block_attn_res.py +299 -0
  110. frankenstein_transformer-1.0.0/src/model/residuals/factory.py +99 -0
  111. frankenstein_transformer-1.0.0/src/model/residuals/full_attn_res.py +275 -0
  112. frankenstein_transformer-1.0.0/src/model/residuals/no_residual.py +69 -0
  113. frankenstein_transformer-1.0.0/src/model/residuals/standard.py +63 -0
  114. frankenstein_transformer-1.0.0/src/sbert/README.md +407 -0
  115. frankenstein_transformer-1.0.0/src/sbert/__init__.py +18 -0
  116. frankenstein_transformer-1.0.0/src/sbert/example_usage.py +296 -0
  117. frankenstein_transformer-1.0.0/src/sbert/inference_sbert.py +581 -0
  118. frankenstein_transformer-1.0.0/src/sbert/train_sbert.py +1787 -0
  119. frankenstein_transformer-1.0.0/src/schema/_base_model.yaml +24 -0
  120. frankenstein_transformer-1.0.0/src/schema/_conditional_rules.yaml +141 -0
  121. frankenstein_transformer-1.0.0/src/schema/_dataset.yaml +126 -0
  122. frankenstein_transformer-1.0.0/src/schema/_examples.yaml +102 -0
  123. frankenstein_transformer-1.0.0/src/schema/_image.yaml +242 -0
  124. frankenstein_transformer-1.0.0/src/schema/_model/_attention_cca.yaml +226 -0
  125. frankenstein_transformer-1.0.0/src/schema/_model/_attention_engram.yaml +103 -0
  126. frankenstein_transformer-1.0.0/src/schema/_model/_attention_latent.yaml +259 -0
  127. frankenstein_transformer-1.0.0/src/schema/_model/_attention_sparse.yaml +101 -0
  128. frankenstein_transformer-1.0.0/src/schema/_model/_attention_titan.yaml +128 -0
  129. frankenstein_transformer-1.0.0/src/schema/_model/_dims.yaml +339 -0
  130. frankenstein_transformer-1.0.0/src/schema/_model/_embedding.yaml +90 -0
  131. frankenstein_transformer-1.0.0/src/schema/_model/_mhc.yaml +142 -0
  132. frankenstein_transformer-1.0.0/src/schema/_model/_model_flat.yaml +503 -0
  133. frankenstein_transformer-1.0.0/src/schema/_model/_norm.yaml +107 -0
  134. frankenstein_transformer-1.0.0/src/schema/_model/_residuals.yaml +335 -0
  135. frankenstein_transformer-1.0.0/src/schema/_model.yaml +116 -0
  136. frankenstein_transformer-1.0.0/src/schema/_model_class.yaml +29 -0
  137. frankenstein_transformer-1.0.0/src/schema/_optimizer.yaml +291 -0
  138. frankenstein_transformer-1.0.0/src/schema/_sbert.yaml +389 -0
  139. frankenstein_transformer-1.0.0/src/schema/_tokenizer.yaml +75 -0
  140. frankenstein_transformer-1.0.0/src/schema/_training.yaml +1334 -0
  141. frankenstein_transformer-1.0.0/src/schema/_vision_classification.yaml +81 -0
  142. frankenstein_transformer-1.0.0/src/schema/_vision_patch.yaml +69 -0
  143. frankenstein_transformer-1.0.0/src/schema/_vision_segmentation.yaml +107 -0
  144. frankenstein_transformer-1.0.0/src/schema.yaml +30 -0
  145. frankenstein_transformer-1.0.0/src/streamlit_gui/__init__.py +5 -0
  146. frankenstein_transformer-1.0.0/src/streamlit_gui/app.py +1446 -0
  147. frankenstein_transformer-1.0.0/src/tokenizer/__init__.py +0 -0
  148. frankenstein_transformer-1.0.0/src/tokenizer/spm_spa_redpajama35.py +284 -0
  149. frankenstein_transformer-1.0.0/src/training/__init__.py +0 -0
  150. frankenstein_transformer-1.0.0/src/training/config_loader.py +287 -0
  151. frankenstein_transformer-1.0.0/src/training/main.py +872 -0
  152. frankenstein_transformer-1.0.0/src/training/streaming_mlm_dataset.py +1021 -0
  153. frankenstein_transformer-1.0.0/src/training/trainer.py +2015 -0
  154. frankenstein_transformer-1.0.0/src/training/vision_dataset.py +352 -0
  155. frankenstein_transformer-1.0.0/src/utils/__init__.py +3 -0
  156. frankenstein_transformer-1.0.0/src/utils/config_flatten.py +343 -0
  157. frankenstein_transformer-1.0.0/src/utils/device.py +62 -0
  158. frankenstein_transformer-1.0.0/src/utils/gpu_temp_guard.py +890 -0
  159. frankenstein_transformer-1.0.0/src/utils/schema_loader.py +70 -0
  160. frankenstein_transformer-1.0.0/src/utils/storage_manager.py +85 -0
@@ -0,0 +1,35 @@
1
+ .venv/
2
+ uv.lock
3
+ wandb/
4
+ output/
5
+ **/__pycache__/
6
+ **/*.pyc
7
+ **/temp_data/
8
+ **/logs/
9
+
10
+ **/checkpoints
11
+ **/es_redpajama_50k.model
12
+ **/es_redpajama_50k.vocab
13
+ **/nohup.out**
14
+ **/training_metrics.csv
15
+
16
+ docs/**/*.aux
17
+ docs/**/*.log
18
+ docs/**/*.out
19
+ docs/**/*.toc
20
+ docs/**/*.bbl
21
+ docs/**/*.blg
22
+ docs/_build/
23
+ docs/pdoc/
24
+
25
+ *.csv
26
+
27
+ .opencode/node_modules/
28
+
29
+ # Exhaustive end-to-end harness workspace (generated tokenizers, checkpoints, deploys)
30
+ full_tests/tmp/
31
+ full_tests/runs/
32
+ full_tests/**/__pycache__/
33
+ full_tests/**/*.pyc
34
+ full_tests/**/*.model
35
+ full_tests/**/*.vocab
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Erick Merino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,282 @@
1
+ Metadata-Version: 2.5
2
+ Name: frankenstein-transformer
3
+ Version: 1.0.0
4
+ Summary: Config-driven, schema-validated training library and CLI for building, training, and deploying hybrid Transformer architectures (attention mixers, BitNet, MoE, SBERT, and Vision Transformers).
5
+ Author-email: Erick Merino <erickfmm@gmail.com>
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: <3.13,>=3.9
9
+ Requires-Dist: datasets>=3.0.0
10
+ Requires-Dist: numpy<3.0,>=1.26.0
11
+ Requires-Dist: psutil>=5.9.0
12
+ Requires-Dist: pyyaml>=6.0.1
13
+ Requires-Dist: torch>=2.0
14
+ Requires-Dist: tqdm>=4.66.0
15
+ Requires-Dist: transformers<5.0.0,>=4.45.0
16
+ Provides-Extra: cpu
17
+ Requires-Dist: torch==2.7.0+cpu; extra == 'cpu'
18
+ Provides-Extra: cu118
19
+ Requires-Dist: torch==2.6.0+cu118; extra == 'cu118'
20
+ Provides-Extra: cu126
21
+ Requires-Dist: torch==2.7.0+cu126; extra == 'cu126'
22
+ Provides-Extra: cu128
23
+ Requires-Dist: torch==2.7.0+cu128; extra == 'cu128'
24
+ Provides-Extra: sbert
25
+ Requires-Dist: sentence-transformers>=3.3.0; extra == 'sbert'
26
+ Requires-Dist: sentencepiece>=0.2.0; extra == 'sbert'
27
+ Provides-Extra: train
28
+ Requires-Dist: sentence-transformers>=3.3.0; extra == 'train'
29
+ Requires-Dist: sentencepiece>=0.2.0; extra == 'train'
30
+ Requires-Dist: streamlit>=1.39.0; extra == 'train'
31
+ Provides-Extra: web
32
+ Requires-Dist: streamlit>=1.39.0; extra == 'web'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Frankenstein Transformer
36
+
37
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
38
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-ee4c2c.svg)](https://pytorch.org/)
39
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
40
+ [![CI](https://img.shields.io/badge/CI-passing-brightgreen.svg)](https://github.com/erickfmm/frankenstein-transformer/actions)
41
+ [![Docs](https://img.shields.io/badge/docs-readthedocs-blue.svg)](https://frankenstein-transformer.readthedocs.io/en/latest/)
42
+
43
+ **See [frankenstein-transformer](https://erickfmm.github.io/frankenstein-transformer/index.html) for a web interface to configure your YAML!**
44
+
45
+ Config-driven transformer experimentation toolkit with 36 mixer architectures and 23 optimizer families.
46
+
47
+ ## Quick Start
48
+
49
+ | Method | Command |
50
+ |--------|---------|
51
+ | **uv** (recommended) | `git clone https://github.com/erickfmm/frankenstein-transformer.git && cd frankenstein-transformer && uv venv && source .venv/bin/activate && uv pip install -e ".[train]"` |
52
+ | **pip** | `python -m venv .venv && source .venv/bin/activate && pip install -e ".[train]"` |
53
+ | **conda** | `conda create -n frankenstein python=3.9 && conda activate frankenstein && pip install -e ".[train]"` |
54
+
55
+ Verify: `frankenstein-transformer --help`
56
+
57
+ ## Feature Matrix
58
+
59
+ | Feature | Scale |
60
+ |---------|-------|
61
+ | Sequence mixer architectures | 36 across 5 categories (Dense, Recurrent, Sparse, Gated, Latent) |
62
+ | Optimizer families | 23 across 6 categories |
63
+ | Model classes | `frankenstein`, `frankensteindecoder`, `frankenstein_vit` |
64
+ | Training modes | Encoder (MLM) / Decoder (autoregressive) / Vision (patch prediction, classification, segmentation) |
65
+ | Normalization types | `layer_norm`, `dynamic_tanh`, `derf`, `rms_norm`, `prms_norm`, `flash_norm` |
66
+ | CLI subcommands | 9 |
67
+ | Web configuration UI | Streamlit schema-driven YAML builder |
68
+ | Quantized deployment | BitNet + checkpoint export pipeline |
69
+ | SBERT workflows | Training + inference (similarity, search, cluster, encode) |
70
+
71
+ ## Architecture Decision Table
72
+
73
+ | Model Class | Mode | Use Case |
74
+ |-------------|------|----------|
75
+ | `frankenstein` | Encoder | Full-featured MLM pre-training with mixed attention, MoE, and all 36 mixer types |
76
+ | `frankensteindecoder` | Decoder | Autoregressive causal decoder for LLM-style generation; forces `mode: decoder` |
77
+ | `frankenstein_vit` | Encoder (vision) | Vision Transformer (arXiv:2010.11929) for image understanding: patch prediction, classification, segmentation (arXiv:2503.19108); forces `mode: encoder`, requires `image:` + `dataset:` blocks |
78
+
79
+ See [configs/README.md](configs/README.md) for preset details and [docs/specs/](docs/specs/) for architecture deep-dives.
80
+
81
+ ## CLI Command Reference
82
+
83
+ | Subcommand | Purpose | Example |
84
+ |------------|---------|---------|
85
+ | `train` | Run schema-validated training | `frankenstein-transformer train --config-name frankenstein --device auto` |
86
+ | `deploy` | Export checkpoint to deployment artifacts | `frankenstein-transformer deploy --checkpoint ckpt.pt --output deployed/ --format quantized` |
87
+ | `quantize` | Shortcut for quantized deployment | `frankenstein-transformer quantize --checkpoint ckpt.pt --output deployed_q/ --validate` |
88
+ | `infer` | Batch/interactive/benchmark inference | `frankenstein-transformer infer --model deployed/ --text "hello" --device auto` |
89
+ | `sbert-train` | Train sentence embedding model | `frankenstein-transformer sbert-train --output_dir ./sbert_out --batch_size 16 --epochs 4` |
90
+ | `sbert-infer` | SBERT similarity/search/cluster/encode | `frankenstein-transformer sbert-infer --model_path ./sbert_out --mode similarity --sentence1 "a" --sentence2 "b"` |
91
+ | `transformers-export` | Export to HuggingFace Transformers format | `frankenstein-transformer transformers-export --config-name frankenstein --output ./hf_export/` |
92
+ | `bitnet-gguf` | Export a BitNet model to GGUF (i2_s) for bitnet.cpp | `frankenstein-transformer bitnet-gguf --model ckpt.pt --yaml cfg.yaml --output out.gguf` |
93
+ | `web-server` | Launch Streamlit config builder UI | `frankenstein-transformer web-server` |
94
+
95
+ All model-executing commands accept `--device auto|cpu|cuda|mps`.
96
+
97
+ ## Mixer Categories
98
+
99
+ | Category | Code Names | Description |
100
+ |----------|------------|-------------|
101
+ | **Dense** | `standard_attn`, `sigmoid_attn` | Full quadratic attention variants |
102
+ | **GQA** | `gqa_attn` | Grouped-query attention with configurable KV heads |
103
+ | **Recurrent** | `retnet`, `retnet_attn`, `mamba`, `ode`, `titan_attn`, `engram_attn` | Retention networks, state-space models, continuous-depth ODE layers, memory-augmented attention, and n-gram memory |
104
+ | **Sparse** | `sparse_transformer_attn`, `longformer_attn`, `bigbird_attn`, `sparsek_attn`, `nsa_attn`, `sparge_attn` ⚠️, `fasa_attn` ⚠️, `msa_attn`, `sparda_attn` | Factorized, sliding-window, token-selection, and block-sparse (GQA-based) patterns |
105
+ | **Gated** | `gla_attn`, `deltanet_attn`, `gated_deltanet_attn`, `gated_deltanet2_attn`, `hgrn2_attn`, `fox_attn`, `gated_softmax_attn`, `kda_attn` | Linear attention with multiplicative gates, delta rules, and gated softmax |
106
+ | **Latent** | `mla_attn`, `gqla_attn`, `mlra_attn`, `tucker_attn`, `iha_attn`, `gta_attn`, `mtla_attn`, `cca_attn`, `ccgqa_attn` | KV-compression and head-mixing variants generalising GQA (latent attention, Tucker factorisation, interleaved pseudo-heads, temporal merging, compressed convolutional attention) |
107
+
108
+ ⚠️ `sparge_attn` and `fasa_attn` are **eval-only** — training raises a runtime error.
109
+
110
+ Configure via `layer_pattern` in YAML. See [src/schema.yaml](src/schema.yaml) for the full mixer reference table.
111
+
112
+ ## Optimizer Categories
113
+
114
+ | Category | Optimizers | Count |
115
+ |----------|------------|-------|
116
+ | **Classical** | `sgd_momentum`, `adamw`, `radam`, `adan`, `adopt`, `ademamix`, `lamb` | 7 |
117
+ | **Variance Reduction** | `mars_adamw`, `cautious_adamw` | 2 |
118
+ | **Memory-Efficient** | `adafactor`, `galore_adamw`, `lion`, `apollo`, `apollo_mini`, `q_apollo` | 6 |
119
+ | **Schedule-Free** | `schedulefree_adamw`, `prodigy` | 2 |
120
+ | **Second-Order** | `sophia`, `shampoo`, `soap` | 3 |
121
+ | **Geometry-Oriented** | `muon`, `turbo_muon`, `anon` | 3 |
122
+
123
+ Parameters use prefixed keys: `<optimizer_class>-<group>_<param>` (e.g. `adamw-lr_embeddings`, `muon-ns_steps`). See [configs/README.md](configs/README.md) for the full parameter reference.
124
+
125
+ ## Documentation Map
126
+
127
+ | Resource | Content |
128
+ |----------|---------|
129
+ | [configs/README.md](configs/README.md) | Schema walkthrough, preset details, optimizer parameter reference |
130
+ | [src/schema.yaml](src/schema.yaml) | Authoritative training config schema (source of truth) |
131
+ | [docs/README.md](docs/README.md) | CLI reference and workflow guide |
132
+ | [docs/paper.pdf](docs/paper.pdf) | Technical report (English) |
133
+ | [docs/paper-es.pdf](docs/paper-es.pdf) | Technical report (Spanish) |
134
+ | [docs/specs/](docs/specs/) | Architecture and feature specifications |
135
+ | [docs/specs/vision.md](docs/specs/vision.md) | Vision Transformer (frankenstein_vit) spec — patch prediction, classification, segmentation |
136
+ | [frankenstein-transformer.readthedocs.io](https://frankenstein-transformer.readthedocs.io/en/latest/) | Full hosted documentation (specs, API, papers, bibliography) |
137
+ | [docs/transformers_compatibility.md](docs/transformers_compatibility.md) | HuggingFace export compatibility guide |
138
+
139
+ ## Installation
140
+
141
+ ### uv (recommended)
142
+
143
+ ```bash
144
+ git clone https://github.com/erickfmm/frankenstein-transformer.git
145
+ cd frankenstein-transformer
146
+ uv venv
147
+ source .venv/bin/activate
148
+ uv pip install -e ".[train]"
149
+ ```
150
+
151
+ ### pip
152
+
153
+ ```bash
154
+ python -m venv .venv
155
+ source .venv/bin/activate
156
+ pip install -e ".[train]"
157
+ ```
158
+
159
+ ### conda
160
+
161
+ ```bash
162
+ conda create -n frankenstein python=3.9
163
+ conda activate frankenstein
164
+ pip install -e ".[train]"
165
+ ```
166
+
167
+ Verify installation:
168
+
169
+ ```bash
170
+ frankenstein-transformer --help
171
+ ```
172
+
173
+ ## Quick Training Example
174
+
175
+ Minimal YAML config (`my_config.yaml`) — only the 5 required model fields plus task; everything else uses FrankensteinModelConfig/TrainingConfig defaults:
176
+
177
+ ```yaml
178
+ model_class: frankenstein
179
+ model:
180
+ vocab_size: 30522
181
+ hidden_size: 256
182
+ num_layers: 4
183
+ num_heads: 8
184
+ layer_pattern: [standard_attn, standard_attn, standard_attn, standard_attn]
185
+ training:
186
+ task: mlm
187
+ batch_size: 8
188
+ max_length: 128
189
+ mlm_probability: 0.15
190
+ max_samples: 100000
191
+ dataset_batch_size: 10000
192
+ num_workers: 4
193
+ cache_dir: "./temp_data/cache"
194
+ optimizer:
195
+ optimizer_class: adamw
196
+ parameters:
197
+ adamw-lr_embeddings: 1e-4
198
+ adamw-lr_norms: 1e-4
199
+ adamw-lr_attention: 1e-4
200
+ adamw-lr_other: 1e-4
201
+ adamw-wd_embeddings: 0.01
202
+ adamw-wd_norms: 0.01
203
+ adamw-wd_attention: 0.01
204
+ adamw-wd_other: 0.01
205
+ adamw-betas_embeddings: [0.9, 0.95]
206
+ adamw-betas_norms: [0.9, 0.95]
207
+ adamw-betas_attention: [0.9, 0.95]
208
+ adamw-betas_other: [0.9, 0.95]
209
+ adamw-eps_embeddings: 1e-8
210
+ adamw-eps_norms: 1e-8
211
+ adamw-eps_attention: 1e-8
212
+ adamw-eps_other: 1e-8
213
+ scheduler_total_steps: 1000
214
+ ```
215
+
216
+ 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.
217
+
218
+ Run:
219
+
220
+ ```bash
221
+ frankenstein-transformer train --config my_config.yaml --device auto
222
+ ```
223
+
224
+ List available named presets:
225
+
226
+ ```bash
227
+ frankenstein-transformer train --list-configs
228
+ ```
229
+
230
+ ## Vision Transformer (frankenstein_vit) Example
231
+
232
+ 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).
233
+
234
+ Minimal classification YAML (`vit_config.yaml`):
235
+
236
+ ```yaml
237
+ model_class: frankenstein_vit
238
+ model:
239
+ dims:
240
+ hidden_size: 768
241
+ num_layers: 12
242
+ num_heads: 12
243
+ layer_pattern: [standard_attn]
244
+ mode: encoder
245
+ norm: {type: layer_norm}
246
+ use_moe: false
247
+ use_bitnet: false
248
+ ffn_activation: gelu
249
+ ffn_hidden_size: 3072
250
+ image:
251
+ image_size: {height: 224, width: 224}
252
+ patch_size: 16
253
+ in_channels: 3
254
+ pos_embedding_type: learned_1d
255
+ cls_token: true
256
+ pooling_mode: cls
257
+ num_classes: 10
258
+ dataset:
259
+ dataset_name: cifar10
260
+ rescale: {height: 224, width: 224}
261
+ training:
262
+ task: classification
263
+ batch_size: 512
264
+ num_epochs: 90
265
+ optimizer:
266
+ optimizer_class: adamw
267
+ parameters:
268
+ adamw-lr_other: 0.001
269
+ adamw-wd_other: 0.1
270
+ classification:
271
+ batch_size: 512
272
+ num_epochs: 90
273
+ learning_rate: 0.001
274
+ ```
275
+
276
+ Run: `frankenstein-transformer train --config vit_config.yaml --device auto`
277
+
278
+ See [configs/frankenstein_vit_base.yaml](configs/frankenstein_vit_base.yaml) for the full ViT-Base/16 preset and [docs/specs/vision.md](docs/specs/vision.md) for the complete specification.
279
+
280
+ ## License
281
+
282
+ Apache License 2.0 — see [LICENSE](LICENSE) for full text.
@@ -0,0 +1,248 @@
1
+ # Frankenstein Transformer
2
+
3
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
4
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-ee4c2c.svg)](https://pytorch.org/)
5
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
6
+ [![CI](https://img.shields.io/badge/CI-passing-brightgreen.svg)](https://github.com/erickfmm/frankenstein-transformer/actions)
7
+ [![Docs](https://img.shields.io/badge/docs-readthedocs-blue.svg)](https://frankenstein-transformer.readthedocs.io/en/latest/)
8
+
9
+ **See [frankenstein-transformer](https://erickfmm.github.io/frankenstein-transformer/index.html) for a web interface to configure your YAML!**
10
+
11
+ Config-driven transformer experimentation toolkit with 36 mixer architectures and 23 optimizer families.
12
+
13
+ ## Quick Start
14
+
15
+ | Method | Command |
16
+ |--------|---------|
17
+ | **uv** (recommended) | `git clone https://github.com/erickfmm/frankenstein-transformer.git && cd frankenstein-transformer && uv venv && source .venv/bin/activate && uv pip install -e ".[train]"` |
18
+ | **pip** | `python -m venv .venv && source .venv/bin/activate && pip install -e ".[train]"` |
19
+ | **conda** | `conda create -n frankenstein python=3.9 && conda activate frankenstein && pip install -e ".[train]"` |
20
+
21
+ Verify: `frankenstein-transformer --help`
22
+
23
+ ## Feature Matrix
24
+
25
+ | Feature | Scale |
26
+ |---------|-------|
27
+ | Sequence mixer architectures | 36 across 5 categories (Dense, Recurrent, Sparse, Gated, Latent) |
28
+ | Optimizer families | 23 across 6 categories |
29
+ | Model classes | `frankenstein`, `frankensteindecoder`, `frankenstein_vit` |
30
+ | Training modes | Encoder (MLM) / Decoder (autoregressive) / Vision (patch prediction, classification, segmentation) |
31
+ | Normalization types | `layer_norm`, `dynamic_tanh`, `derf`, `rms_norm`, `prms_norm`, `flash_norm` |
32
+ | CLI subcommands | 9 |
33
+ | Web configuration UI | Streamlit schema-driven YAML builder |
34
+ | Quantized deployment | BitNet + checkpoint export pipeline |
35
+ | SBERT workflows | Training + inference (similarity, search, cluster, encode) |
36
+
37
+ ## Architecture Decision Table
38
+
39
+ | Model Class | Mode | Use Case |
40
+ |-------------|------|----------|
41
+ | `frankenstein` | Encoder | Full-featured MLM pre-training with mixed attention, MoE, and all 36 mixer types |
42
+ | `frankensteindecoder` | Decoder | Autoregressive causal decoder for LLM-style generation; forces `mode: decoder` |
43
+ | `frankenstein_vit` | Encoder (vision) | Vision Transformer (arXiv:2010.11929) for image understanding: patch prediction, classification, segmentation (arXiv:2503.19108); forces `mode: encoder`, requires `image:` + `dataset:` blocks |
44
+
45
+ See [configs/README.md](configs/README.md) for preset details and [docs/specs/](docs/specs/) for architecture deep-dives.
46
+
47
+ ## CLI Command Reference
48
+
49
+ | Subcommand | Purpose | Example |
50
+ |------------|---------|---------|
51
+ | `train` | Run schema-validated training | `frankenstein-transformer train --config-name frankenstein --device auto` |
52
+ | `deploy` | Export checkpoint to deployment artifacts | `frankenstein-transformer deploy --checkpoint ckpt.pt --output deployed/ --format quantized` |
53
+ | `quantize` | Shortcut for quantized deployment | `frankenstein-transformer quantize --checkpoint ckpt.pt --output deployed_q/ --validate` |
54
+ | `infer` | Batch/interactive/benchmark inference | `frankenstein-transformer infer --model deployed/ --text "hello" --device auto` |
55
+ | `sbert-train` | Train sentence embedding model | `frankenstein-transformer sbert-train --output_dir ./sbert_out --batch_size 16 --epochs 4` |
56
+ | `sbert-infer` | SBERT similarity/search/cluster/encode | `frankenstein-transformer sbert-infer --model_path ./sbert_out --mode similarity --sentence1 "a" --sentence2 "b"` |
57
+ | `transformers-export` | Export to HuggingFace Transformers format | `frankenstein-transformer transformers-export --config-name frankenstein --output ./hf_export/` |
58
+ | `bitnet-gguf` | Export a BitNet model to GGUF (i2_s) for bitnet.cpp | `frankenstein-transformer bitnet-gguf --model ckpt.pt --yaml cfg.yaml --output out.gguf` |
59
+ | `web-server` | Launch Streamlit config builder UI | `frankenstein-transformer web-server` |
60
+
61
+ All model-executing commands accept `--device auto|cpu|cuda|mps`.
62
+
63
+ ## Mixer Categories
64
+
65
+ | Category | Code Names | Description |
66
+ |----------|------------|-------------|
67
+ | **Dense** | `standard_attn`, `sigmoid_attn` | Full quadratic attention variants |
68
+ | **GQA** | `gqa_attn` | Grouped-query attention with configurable KV heads |
69
+ | **Recurrent** | `retnet`, `retnet_attn`, `mamba`, `ode`, `titan_attn`, `engram_attn` | Retention networks, state-space models, continuous-depth ODE layers, memory-augmented attention, and n-gram memory |
70
+ | **Sparse** | `sparse_transformer_attn`, `longformer_attn`, `bigbird_attn`, `sparsek_attn`, `nsa_attn`, `sparge_attn` ⚠️, `fasa_attn` ⚠️, `msa_attn`, `sparda_attn` | Factorized, sliding-window, token-selection, and block-sparse (GQA-based) patterns |
71
+ | **Gated** | `gla_attn`, `deltanet_attn`, `gated_deltanet_attn`, `gated_deltanet2_attn`, `hgrn2_attn`, `fox_attn`, `gated_softmax_attn`, `kda_attn` | Linear attention with multiplicative gates, delta rules, and gated softmax |
72
+ | **Latent** | `mla_attn`, `gqla_attn`, `mlra_attn`, `tucker_attn`, `iha_attn`, `gta_attn`, `mtla_attn`, `cca_attn`, `ccgqa_attn` | KV-compression and head-mixing variants generalising GQA (latent attention, Tucker factorisation, interleaved pseudo-heads, temporal merging, compressed convolutional attention) |
73
+
74
+ ⚠️ `sparge_attn` and `fasa_attn` are **eval-only** — training raises a runtime error.
75
+
76
+ Configure via `layer_pattern` in YAML. See [src/schema.yaml](src/schema.yaml) for the full mixer reference table.
77
+
78
+ ## Optimizer Categories
79
+
80
+ | Category | Optimizers | Count |
81
+ |----------|------------|-------|
82
+ | **Classical** | `sgd_momentum`, `adamw`, `radam`, `adan`, `adopt`, `ademamix`, `lamb` | 7 |
83
+ | **Variance Reduction** | `mars_adamw`, `cautious_adamw` | 2 |
84
+ | **Memory-Efficient** | `adafactor`, `galore_adamw`, `lion`, `apollo`, `apollo_mini`, `q_apollo` | 6 |
85
+ | **Schedule-Free** | `schedulefree_adamw`, `prodigy` | 2 |
86
+ | **Second-Order** | `sophia`, `shampoo`, `soap` | 3 |
87
+ | **Geometry-Oriented** | `muon`, `turbo_muon`, `anon` | 3 |
88
+
89
+ Parameters use prefixed keys: `<optimizer_class>-<group>_<param>` (e.g. `adamw-lr_embeddings`, `muon-ns_steps`). See [configs/README.md](configs/README.md) for the full parameter reference.
90
+
91
+ ## Documentation Map
92
+
93
+ | Resource | Content |
94
+ |----------|---------|
95
+ | [configs/README.md](configs/README.md) | Schema walkthrough, preset details, optimizer parameter reference |
96
+ | [src/schema.yaml](src/schema.yaml) | Authoritative training config schema (source of truth) |
97
+ | [docs/README.md](docs/README.md) | CLI reference and workflow guide |
98
+ | [docs/paper.pdf](docs/paper.pdf) | Technical report (English) |
99
+ | [docs/paper-es.pdf](docs/paper-es.pdf) | Technical report (Spanish) |
100
+ | [docs/specs/](docs/specs/) | Architecture and feature specifications |
101
+ | [docs/specs/vision.md](docs/specs/vision.md) | Vision Transformer (frankenstein_vit) spec — patch prediction, classification, segmentation |
102
+ | [frankenstein-transformer.readthedocs.io](https://frankenstein-transformer.readthedocs.io/en/latest/) | Full hosted documentation (specs, API, papers, bibliography) |
103
+ | [docs/transformers_compatibility.md](docs/transformers_compatibility.md) | HuggingFace export compatibility guide |
104
+
105
+ ## Installation
106
+
107
+ ### uv (recommended)
108
+
109
+ ```bash
110
+ git clone https://github.com/erickfmm/frankenstein-transformer.git
111
+ cd frankenstein-transformer
112
+ uv venv
113
+ source .venv/bin/activate
114
+ uv pip install -e ".[train]"
115
+ ```
116
+
117
+ ### pip
118
+
119
+ ```bash
120
+ python -m venv .venv
121
+ source .venv/bin/activate
122
+ pip install -e ".[train]"
123
+ ```
124
+
125
+ ### conda
126
+
127
+ ```bash
128
+ conda create -n frankenstein python=3.9
129
+ conda activate frankenstein
130
+ pip install -e ".[train]"
131
+ ```
132
+
133
+ Verify installation:
134
+
135
+ ```bash
136
+ frankenstein-transformer --help
137
+ ```
138
+
139
+ ## Quick Training Example
140
+
141
+ Minimal YAML config (`my_config.yaml`) — only the 5 required model fields plus task; everything else uses FrankensteinModelConfig/TrainingConfig defaults:
142
+
143
+ ```yaml
144
+ model_class: frankenstein
145
+ model:
146
+ vocab_size: 30522
147
+ hidden_size: 256
148
+ num_layers: 4
149
+ num_heads: 8
150
+ layer_pattern: [standard_attn, standard_attn, standard_attn, standard_attn]
151
+ training:
152
+ task: mlm
153
+ batch_size: 8
154
+ max_length: 128
155
+ mlm_probability: 0.15
156
+ max_samples: 100000
157
+ dataset_batch_size: 10000
158
+ num_workers: 4
159
+ cache_dir: "./temp_data/cache"
160
+ optimizer:
161
+ optimizer_class: adamw
162
+ parameters:
163
+ adamw-lr_embeddings: 1e-4
164
+ adamw-lr_norms: 1e-4
165
+ adamw-lr_attention: 1e-4
166
+ adamw-lr_other: 1e-4
167
+ adamw-wd_embeddings: 0.01
168
+ adamw-wd_norms: 0.01
169
+ adamw-wd_attention: 0.01
170
+ adamw-wd_other: 0.01
171
+ adamw-betas_embeddings: [0.9, 0.95]
172
+ adamw-betas_norms: [0.9, 0.95]
173
+ adamw-betas_attention: [0.9, 0.95]
174
+ adamw-betas_other: [0.9, 0.95]
175
+ adamw-eps_embeddings: 1e-8
176
+ adamw-eps_norms: 1e-8
177
+ adamw-eps_attention: 1e-8
178
+ adamw-eps_other: 1e-8
179
+ scheduler_total_steps: 1000
180
+ ```
181
+
182
+ 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.
183
+
184
+ Run:
185
+
186
+ ```bash
187
+ frankenstein-transformer train --config my_config.yaml --device auto
188
+ ```
189
+
190
+ List available named presets:
191
+
192
+ ```bash
193
+ frankenstein-transformer train --list-configs
194
+ ```
195
+
196
+ ## Vision Transformer (frankenstein_vit) Example
197
+
198
+ 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).
199
+
200
+ Minimal classification YAML (`vit_config.yaml`):
201
+
202
+ ```yaml
203
+ model_class: frankenstein_vit
204
+ model:
205
+ dims:
206
+ hidden_size: 768
207
+ num_layers: 12
208
+ num_heads: 12
209
+ layer_pattern: [standard_attn]
210
+ mode: encoder
211
+ norm: {type: layer_norm}
212
+ use_moe: false
213
+ use_bitnet: false
214
+ ffn_activation: gelu
215
+ ffn_hidden_size: 3072
216
+ image:
217
+ image_size: {height: 224, width: 224}
218
+ patch_size: 16
219
+ in_channels: 3
220
+ pos_embedding_type: learned_1d
221
+ cls_token: true
222
+ pooling_mode: cls
223
+ num_classes: 10
224
+ dataset:
225
+ dataset_name: cifar10
226
+ rescale: {height: 224, width: 224}
227
+ training:
228
+ task: classification
229
+ batch_size: 512
230
+ num_epochs: 90
231
+ optimizer:
232
+ optimizer_class: adamw
233
+ parameters:
234
+ adamw-lr_other: 0.001
235
+ adamw-wd_other: 0.1
236
+ classification:
237
+ batch_size: 512
238
+ num_epochs: 90
239
+ learning_rate: 0.001
240
+ ```
241
+
242
+ Run: `frankenstein-transformer train --config vit_config.yaml --device auto`
243
+
244
+ See [configs/frankenstein_vit_base.yaml](configs/frankenstein_vit_base.yaml) for the full ViT-Base/16 preset and [docs/specs/vision.md](docs/specs/vision.md) for the complete specification.
245
+
246
+ ## License
247
+
248
+ Apache License 2.0 — see [LICENSE](LICENSE) for full text.