oglodon-transformer 0.4.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 (132) hide show
  1. oglodon_transformer-0.4.0/.gitignore +21 -0
  2. oglodon_transformer-0.4.0/LICENSE +21 -0
  3. oglodon_transformer-0.4.0/PKG-INFO +168 -0
  4. oglodon_transformer-0.4.0/README.md +126 -0
  5. oglodon_transformer-0.4.0/benchmarks/run_comparison.py +35 -0
  6. oglodon_transformer-0.4.0/configs/compare_mha_gqa.yaml +23 -0
  7. oglodon_transformer-0.4.0/configs/compare_positions_ffn.yaml +18 -0
  8. oglodon_transformer-0.4.0/configs/gqa.yaml +10 -0
  9. oglodon_transformer-0.4.0/configs/mha.yaml +10 -0
  10. oglodon_transformer-0.4.0/configs/tiny_gqa.yaml +14 -0
  11. oglodon_transformer-0.4.0/docs/architecture.md +88 -0
  12. oglodon_transformer-0.4.0/docs/cli.md +101 -0
  13. oglodon_transformer-0.4.0/docs/configuration.md +45 -0
  14. oglodon_transformer-0.4.0/docs/contributing.md +40 -0
  15. oglodon_transformer-0.4.0/docs/data-and-tokenization.md +50 -0
  16. oglodon_transformer-0.4.0/docs/evaluation.md +54 -0
  17. oglodon_transformer-0.4.0/docs/experiments.md +66 -0
  18. oglodon_transformer-0.4.0/docs/generation.md +48 -0
  19. oglodon_transformer-0.4.0/docs/getting-started.md +81 -0
  20. oglodon_transformer-0.4.0/docs/index.md +40 -0
  21. oglodon_transformer-0.4.0/docs/interoperability.md +70 -0
  22. oglodon_transformer-0.4.0/docs/limitations.md +19 -0
  23. oglodon_transformer-0.4.0/docs/performance-and-scaling.md +68 -0
  24. oglodon_transformer-0.4.0/docs/publishing.md +40 -0
  25. oglodon_transformer-0.4.0/docs/quantization.md +53 -0
  26. oglodon_transformer-0.4.0/docs/reference.md +345 -0
  27. oglodon_transformer-0.4.0/docs/training.md +110 -0
  28. oglodon_transformer-0.4.0/docs/troubleshooting.md +61 -0
  29. oglodon_transformer-0.4.0/docs/validation.md +64 -0
  30. oglodon_transformer-0.4.0/docs/verify.md +71 -0
  31. oglodon_transformer-0.4.0/examples/01_train_algorithmic.py +71 -0
  32. oglodon_transformer-0.4.0/examples/02_char_language_model.py +71 -0
  33. oglodon_transformer-0.4.0/examples/03_generate.py +54 -0
  34. oglodon_transformer-0.4.0/examples/04_inspect_attention.py +42 -0
  35. oglodon_transformer-0.4.0/examples/05_compare_architectures.py +15 -0
  36. oglodon_transformer-0.4.0/examples/06_external_tokenizer.py +61 -0
  37. oglodon_transformer-0.4.0/examples/07_validate_and_compare.py +27 -0
  38. oglodon_transformer-0.4.0/examples/08_train_bpe_on_files.py +72 -0
  39. oglodon_transformer-0.4.0/examples/09_verify_any_model.py +29 -0
  40. oglodon_transformer-0.4.0/examples/_common.py +46 -0
  41. oglodon_transformer-0.4.0/pyproject.toml +66 -0
  42. oglodon_transformer-0.4.0/src/oglodon/__init__.py +13 -0
  43. oglodon_transformer-0.4.0/src/oglodon/__main__.py +8 -0
  44. oglodon_transformer-0.4.0/src/oglodon/benchmarks/__init__.py +5 -0
  45. oglodon_transformer-0.4.0/src/oglodon/benchmarks/compare.py +129 -0
  46. oglodon_transformer-0.4.0/src/oglodon/cli.py +680 -0
  47. oglodon_transformer-0.4.0/src/oglodon/config.py +175 -0
  48. oglodon_transformer-0.4.0/src/oglodon/convert/__init__.py +5 -0
  49. oglodon_transformer-0.4.0/src/oglodon/convert/hf.py +242 -0
  50. oglodon_transformer-0.4.0/src/oglodon/data/__init__.py +26 -0
  51. oglodon_transformer-0.4.0/src/oglodon/data/algorithmic.py +108 -0
  52. oglodon_transformer-0.4.0/src/oglodon/data/corpus.py +219 -0
  53. oglodon_transformer-0.4.0/src/oglodon/data/text.py +45 -0
  54. oglodon_transformer-0.4.0/src/oglodon/evaluation/__init__.py +20 -0
  55. oglodon_transformer-0.4.0/src/oglodon/evaluation/_util.py +17 -0
  56. oglodon_transformer-0.4.0/src/oglodon/evaluation/generation.py +90 -0
  57. oglodon_transformer-0.4.0/src/oglodon/evaluation/multiple_choice.py +127 -0
  58. oglodon_transformer-0.4.0/src/oglodon/evaluation/perplexity.py +108 -0
  59. oglodon_transformer-0.4.0/src/oglodon/experiments/__init__.py +19 -0
  60. oglodon_transformer-0.4.0/src/oglodon/experiments/compare.py +543 -0
  61. oglodon_transformer-0.4.0/src/oglodon/generation/__init__.py +19 -0
  62. oglodon_transformer-0.4.0/src/oglodon/generation/sampler.py +283 -0
  63. oglodon_transformer-0.4.0/src/oglodon/inspection/__init__.py +5 -0
  64. oglodon_transformer-0.4.0/src/oglodon/inspection/attention.py +108 -0
  65. oglodon_transformer-0.4.0/src/oglodon/layers/__init__.py +22 -0
  66. oglodon_transformer-0.4.0/src/oglodon/layers/attention.py +144 -0
  67. oglodon_transformer-0.4.0/src/oglodon/layers/cache.py +49 -0
  68. oglodon_transformer-0.4.0/src/oglodon/layers/embeddings.py +17 -0
  69. oglodon_transformer-0.4.0/src/oglodon/layers/feedforward.py +63 -0
  70. oglodon_transformer-0.4.0/src/oglodon/layers/normalization.py +32 -0
  71. oglodon_transformer-0.4.0/src/oglodon/layers/rope.py +55 -0
  72. oglodon_transformer-0.4.0/src/oglodon/models/__init__.py +6 -0
  73. oglodon_transformer-0.4.0/src/oglodon/models/gpt.py +220 -0
  74. oglodon_transformer-0.4.0/src/oglodon/models/transformer.py +53 -0
  75. oglodon_transformer-0.4.0/src/oglodon/quantization.py +239 -0
  76. oglodon_transformer-0.4.0/src/oglodon/testing/__init__.py +5 -0
  77. oglodon_transformer-0.4.0/src/oglodon/testing/validation.py +5 -0
  78. oglodon_transformer-0.4.0/src/oglodon/tokenization/__init__.py +6 -0
  79. oglodon_transformer-0.4.0/src/oglodon/tokenization/bpe.py +217 -0
  80. oglodon_transformer-0.4.0/src/oglodon/tokenization/tokenizer.py +133 -0
  81. oglodon_transformer-0.4.0/src/oglodon/training/__init__.py +17 -0
  82. oglodon_transformer-0.4.0/src/oglodon/training/checkpoint.py +72 -0
  83. oglodon_transformer-0.4.0/src/oglodon/training/distributed.py +78 -0
  84. oglodon_transformer-0.4.0/src/oglodon/training/scheduler.py +32 -0
  85. oglodon_transformer-0.4.0/src/oglodon/training/trainer.py +368 -0
  86. oglodon_transformer-0.4.0/src/oglodon/utils/__init__.py +5 -0
  87. oglodon_transformer-0.4.0/src/oglodon/utils/reproducibility.py +25 -0
  88. oglodon_transformer-0.4.0/src/oglodon/validation/__init__.py +21 -0
  89. oglodon_transformer-0.4.0/src/oglodon/validation/checks_attention.py +278 -0
  90. oglodon_transformer-0.4.0/src/oglodon/validation/checks_cache.py +220 -0
  91. oglodon_transformer-0.4.0/src/oglodon/validation/checks_model.py +240 -0
  92. oglodon_transformer-0.4.0/src/oglodon/validation/checks_training.py +249 -0
  93. oglodon_transformer-0.4.0/src/oglodon/validation/reference.py +186 -0
  94. oglodon_transformer-0.4.0/src/oglodon/validation/registry.py +129 -0
  95. oglodon_transformer-0.4.0/src/oglodon/validation/report.py +199 -0
  96. oglodon_transformer-0.4.0/src/oglodon/validation/runner.py +144 -0
  97. oglodon_transformer-0.4.0/src/oglodon/verify/__init__.py +16 -0
  98. oglodon_transformer-0.4.0/src/oglodon/verify/adapter.py +161 -0
  99. oglodon_transformer-0.4.0/src/oglodon/verify/checks.py +633 -0
  100. oglodon_transformer-0.4.0/src/oglodon/verify/equivalence.py +205 -0
  101. oglodon_transformer-0.4.0/src/oglodon/verify/runner.py +153 -0
  102. oglodon_transformer-0.4.0/src/oglodon/workflow.py +386 -0
  103. oglodon_transformer-0.4.0/tests/__init__.py +0 -0
  104. oglodon_transformer-0.4.0/tests/conftest.py +55 -0
  105. oglodon_transformer-0.4.0/tests/test_audit_fixes.py +181 -0
  106. oglodon_transformer-0.4.0/tests/test_bpe_data.py +231 -0
  107. oglodon_transformer-0.4.0/tests/test_checkpoint.py +60 -0
  108. oglodon_transformer-0.4.0/tests/test_cli.py +218 -0
  109. oglodon_transformer-0.4.0/tests/test_compare_report.py +108 -0
  110. oglodon_transformer-0.4.0/tests/test_config.py +52 -0
  111. oglodon_transformer-0.4.0/tests/test_convert_equivalence.py +273 -0
  112. oglodon_transformer-0.4.0/tests/test_data_tokenizer.py +98 -0
  113. oglodon_transformer-0.4.0/tests/test_distributed.py +100 -0
  114. oglodon_transformer-0.4.0/tests/test_docs.py +103 -0
  115. oglodon_transformer-0.4.0/tests/test_evaluation.py +201 -0
  116. oglodon_transformer-0.4.0/tests/test_experiments.py +105 -0
  117. oglodon_transformer-0.4.0/tests/test_export_hf.py +92 -0
  118. oglodon_transformer-0.4.0/tests/test_generation.py +126 -0
  119. oglodon_transformer-0.4.0/tests/test_generation_stream.py +189 -0
  120. oglodon_transformer-0.4.0/tests/test_inspection_validation_benchmarks.py +70 -0
  121. oglodon_transformer-0.4.0/tests/test_layers.py +143 -0
  122. oglodon_transformer-0.4.0/tests/test_model.py +140 -0
  123. oglodon_transformer-0.4.0/tests/test_performance_features.py +148 -0
  124. oglodon_transformer-0.4.0/tests/test_prepublish.py +39 -0
  125. oglodon_transformer-0.4.0/tests/test_qkv_bias.py +56 -0
  126. oglodon_transformer-0.4.0/tests/test_quantization.py +198 -0
  127. oglodon_transformer-0.4.0/tests/test_training.py +179 -0
  128. oglodon_transformer-0.4.0/tests/test_validation.py +392 -0
  129. oglodon_transformer-0.4.0/tests/test_variants.py +77 -0
  130. oglodon_transformer-0.4.0/tests/test_verify.py +358 -0
  131. oglodon_transformer-0.4.0/tests/test_workflow.py +227 -0
  132. oglodon_transformer-0.4.0/tests/tiny_lm.py +96 -0
@@ -0,0 +1,21 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ *.pt
9
+ checkpoint*/
10
+ site/
11
+ .mypy_cache/
12
+ *.pyc
13
+ .DS_Store
14
+ Thumbs.db
15
+ .vscode/
16
+ .idea/
17
+ .ipynb_checkpoints/
18
+ oglodon_runs/
19
+ runs/
20
+ *.bin
21
+ *.safetensors
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oglodon contributors
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,168 @@
1
+ Metadata-Version: 2.5
2
+ Name: oglodon-transformer
3
+ Version: 0.4.0
4
+ Summary: Oglodon: build, train and behaviour-verify Transformers; `oglodon verify` checks any causal LM (Hugging Face, custom PyTorch) for causality, padding, KV-cache, numerics and gradient bugs.
5
+ Project-URL: Homepage, https://github.com/Dhruvg0/Oglodon
6
+ Project-URL: Issues, https://github.com/Dhruvg0/Oglodon/issues
7
+ Author-email: Dhruv Puri <dhruvpurigoswami2004@gmail.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: education,gpt,gqa,kv-cache,llm,pytorch,rope,transformer
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: numpy>=1.26
23
+ Requires-Dist: safetensors>=0.4
24
+ Requires-Dist: torch>=2.2
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.0; extra == 'dev'
27
+ Requires-Dist: matplotlib>=3.8; extra == 'dev'
28
+ Requires-Dist: mypy>=1.8; extra == 'dev'
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: pyyaml>=6; extra == 'dev'
31
+ Requires-Dist: ruff>=0.5; extra == 'dev'
32
+ Requires-Dist: transformers>=4.46; extra == 'dev'
33
+ Provides-Extra: docs
34
+ Requires-Dist: mkdocs>=1.6; extra == 'docs'
35
+ Provides-Extra: hf
36
+ Requires-Dist: transformers>=4.46; extra == 'hf'
37
+ Provides-Extra: viz
38
+ Requires-Dist: matplotlib>=3.8; extra == 'viz'
39
+ Provides-Extra: yaml
40
+ Requires-Dist: pyyaml>=6; extra == 'yaml'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # Oglodon
44
+
45
+ **Build. Train. Understand. Verify.**
46
+
47
+ [![Python](https://img.shields.io/badge/python-3.11%2B-3776AB)](https://www.python.org/)
48
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.2%2B-EE4C2C)](https://pytorch.org/)
49
+ [![License](https://img.shields.io/badge/license-MIT-yellow)](https://github.com/Dhruvg0/oglodon/blob/main/LICENSE)
50
+ [![Tests](https://github.com/Dhruvg0/oglodon/actions/workflows/tests.yml/badge.svg)](https://github.com/Dhruvg0/oglodon/actions/workflows/tests.yml)
51
+ [![PyPI](https://img.shields.io/pypi/v/oglodon-transformer)](https://pypi.org/project/oglodon-transformer/)
52
+
53
+ Oglodon is a small PyTorch library for building, training and checking decoder-only Transformers (GPT-style, with
54
+ RoPE, RMSNorm, SwiGLU, grouped-query attention and a KV cache).
55
+
56
+ Its most useful part is **`oglodon verify`**: it tests *any* causal language model (Hugging Face, your own PyTorch
57
+ module, or Oglodon) for bugs that still train but quietly make the model worse, such as a token seeing the future,
58
+ padding changing the answer, or a KV cache that disagrees with a full forward pass.
59
+
60
+ > **Status: alpha, for learning and research at small scale.** Not production-ready and not a replacement for large-scale
61
+ > frameworks. See [what has and has not been tested](#what-has-been-tested).
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ pip install oglodon-transformer
67
+ ```
68
+
69
+ Needs Python 3.11+ and PyTorch. Optional extras: `[hf]` Hugging Face import, export and verification, `[viz]` plots,
70
+ `[yaml]` YAML configs, `[dev]` tests and linters. Working from a clone: `pip install -e ".[dev]"`.
71
+
72
+ ## Try it in two minutes
73
+
74
+ Put a few `.txt` or `.md` files in a folder, then:
75
+
76
+ ```bash
77
+ oglodon train my_texts/ --out run1 --steps 500
78
+ oglodon generate run1 --prompt "Once upon a time" --seed 1
79
+ oglodon eval run1 --text my_texts/some_file.txt
80
+ ```
81
+
82
+ `train` builds a tokenizer, trains a small model and saves a checkpoint; `eval` prints perplexity next to the score of
83
+ a model that guesses at random, so you can see whether it learned anything. A model trained for minutes learns your
84
+ text's vocabulary and local patterns, not fluent language. No Python code is needed.
85
+
86
+ ## How it fits together
87
+
88
+ ```text
89
+ text files ──► BPE tokenizer ──► token file ──► train ──► CHECKPOINT
90
+ │
91
+ ┌─────────────┬──────────────┬──────────────┬─────────┴────────┐
92
+ ▼ ▼ ▼ ▼ ▼
93
+ generate eval verify quantize export to
94
+ (stream text) (perplexity) (behaviour) (int8 copy) Hugging Face
95
+ ▲
96
+ any Hugging Face / PyTorch model ───┘ verify accepts any causal LM
97
+ ```
98
+
99
+ Inside the model:
100
+
101
+ ```text
102
+ tokens ─► Embedding ─► [ Norm ─► Attention (RoPE, KV cache) ─► + ─► Norm ─► FFN ─► + ] × N ─► Norm ─► LM head ─► logits
103
+ MHA / GQA / MQA SwiGLU / GELU
104
+ ```
105
+
106
+ ## What you can do
107
+
108
+ | Command | What it does |
109
+ |---|---|
110
+ | `oglodon train` | Text files to tokenizer, trained model and report. Exact `--resume`, data-parallel under `torchrun` |
111
+ | `oglodon generate` | Streams text: temperature, top-k, top-p, min-p, repetition penalty, stop strings, KV cache |
112
+ | `oglodon eval` | Perplexity, multiple-choice accuracy, generation sanity checks, saved as JSON |
113
+ | `oglodon verify` | Behaviour checks on any causal LM; `--cross-check` compares against a Hugging Face model |
114
+ | `oglodon validate` | Compares an Oglodon model with an independent float64 reference implementation |
115
+ | `oglodon compare` | Trains variants on identical data and seeds and writes reproducible comparison reports |
116
+ | `oglodon quantize` | Int8 weight-only copy of a checkpoint with a measured accuracy drift |
117
+ | `oglodon info` | Versions and whether CUDA is available |
118
+
119
+ Architecture options: MHA, GQA or MQA attention, RoPE, learned or ALiBi positions, RMSNorm or LayerNorm, SwiGLU,
120
+ GeGLU, GELU or ReLU² feed-forward, sliding window, qkv bias. Export to Llama, Mistral or Qwen2 format for
121
+ Hugging Face with `export_hf(model, "hf_dir")`.
122
+
123
+ ## Verify any model
124
+
125
+ ```bash
126
+ oglodon verify --checkpoint run1 # an Oglodon checkpoint
127
+ oglodon verify --hf HuggingFaceTB/SmolLM2-135M --cross-check --dtype float32
128
+ ```
129
+
130
+ | Check | What it catches |
131
+ |---|---|
132
+ | Causality | A token's prediction changes when later tokens change |
133
+ | Padding and batching | Padded or batched inputs giving different answers than single ones |
134
+ | KV cache | Cached decoding disagreeing with a full forward pass |
135
+ | Numerics | float32 vs float64 drift, non-finite values |
136
+ | Gradients | Autograd disagreeing with finite differences, dead parameters |
137
+ | Cross-check | An Oglodon model and its Hugging Face twin producing different logits |
138
+
139
+ Skipped or unsupported checks are reported as such and are never counted as passed.
140
+
141
+ ## What has been tested
142
+
143
+ | Verified | Not yet |
144
+ |---|---|
145
+ | Test suite on CPU: Python 3.11, 3.12 and 3.13 (Linux) and the suite on Windows | macOS |
146
+ | Test suite, `validate`, `verify`, bf16 and fp16 steps on one Tesla T4 (Colab) | Multi-GPU, FlashAttention kernels, other GPUs |
147
+ | `verify --cross-check` on SmolLM2-135M in float32: logits agree to about 1e-4, greedy output identical | Other pretrained models |
148
+ | Int8 drift measured on a small trained model (perplexity change about 0.001%) | Int8 on large models or on a GPU |
149
+ | Hugging Face export matches logits to about 1e-6 | Gemma, Phi, Mixtral converters, FSDP, 4-bit quantization |
150
+
151
+ Details and exact numbers: [Limitations](https://github.com/Dhruvg0/oglodon/blob/main/docs/limitations.md) and [Performance and scaling](https://github.com/Dhruvg0/oglodon/blob/main/docs/performance-and-scaling.md).
152
+
153
+ ## Documentation
154
+
155
+ * [Getting started](https://github.com/Dhruvg0/oglodon/blob/main/docs/getting-started.md) and [command reference](https://github.com/Dhruvg0/oglodon/blob/main/docs/cli.md)
156
+ * [Training](https://github.com/Dhruvg0/oglodon/blob/main/docs/training.md), [data and tokenizers](https://github.com/Dhruvg0/oglodon/blob/main/docs/data-and-tokenization.md), [generation](https://github.com/Dhruvg0/oglodon/blob/main/docs/generation.md),
157
+ [evaluation](https://github.com/Dhruvg0/oglodon/blob/main/docs/evaluation.md)
158
+ * [Verify](https://github.com/Dhruvg0/oglodon/blob/main/docs/verify.md), [validation](https://github.com/Dhruvg0/oglodon/blob/main/docs/validation.md), [experiments](https://github.com/Dhruvg0/oglodon/blob/main/docs/experiments.md),
159
+ [quantization](https://github.com/Dhruvg0/oglodon/blob/main/docs/quantization.md), [Hugging Face interop](https://github.com/Dhruvg0/oglodon/blob/main/docs/interoperability.md)
160
+ * [Python and feature reference](https://github.com/Dhruvg0/oglodon/blob/main/docs/reference.md), [architecture](https://github.com/Dhruvg0/oglodon/blob/main/docs/architecture.md),
161
+ [configuration](https://github.com/Dhruvg0/oglodon/blob/main/docs/configuration.md), [troubleshooting](https://github.com/Dhruvg0/oglodon/blob/main/docs/troubleshooting.md)
162
+ * Runnable scripts in [`examples/`](https://github.com/Dhruvg0/oglodon/tree/main/examples)
163
+
164
+ ## Contributing and licence
165
+
166
+ Contributions are welcome; see [docs/contributing.md](https://github.com/Dhruvg0/oglodon/blob/main/docs/contributing.md). Released under the [MIT licence](https://github.com/Dhruvg0/oglodon/blob/main/LICENSE).
167
+
168
+ Oglodon is an independent project. It is not affiliated with, endorsed by or derived from NVIDIA or any hardware vendor.
@@ -0,0 +1,126 @@
1
+ # Oglodon
2
+
3
+ **Build. Train. Understand. Verify.**
4
+
5
+ [![Python](https://img.shields.io/badge/python-3.11%2B-3776AB)](https://www.python.org/)
6
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.2%2B-EE4C2C)](https://pytorch.org/)
7
+ [![License](https://img.shields.io/badge/license-MIT-yellow)](https://github.com/Dhruvg0/oglodon/blob/main/LICENSE)
8
+ [![Tests](https://github.com/Dhruvg0/oglodon/actions/workflows/tests.yml/badge.svg)](https://github.com/Dhruvg0/oglodon/actions/workflows/tests.yml)
9
+ [![PyPI](https://img.shields.io/pypi/v/oglodon-transformer)](https://pypi.org/project/oglodon-transformer/)
10
+
11
+ Oglodon is a small PyTorch library for building, training and checking decoder-only Transformers (GPT-style, with
12
+ RoPE, RMSNorm, SwiGLU, grouped-query attention and a KV cache).
13
+
14
+ Its most useful part is **`oglodon verify`**: it tests *any* causal language model (Hugging Face, your own PyTorch
15
+ module, or Oglodon) for bugs that still train but quietly make the model worse, such as a token seeing the future,
16
+ padding changing the answer, or a KV cache that disagrees with a full forward pass.
17
+
18
+ > **Status: alpha, for learning and research at small scale.** Not production-ready and not a replacement for large-scale
19
+ > frameworks. See [what has and has not been tested](#what-has-been-tested).
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install oglodon-transformer
25
+ ```
26
+
27
+ Needs Python 3.11+ and PyTorch. Optional extras: `[hf]` Hugging Face import, export and verification, `[viz]` plots,
28
+ `[yaml]` YAML configs, `[dev]` tests and linters. Working from a clone: `pip install -e ".[dev]"`.
29
+
30
+ ## Try it in two minutes
31
+
32
+ Put a few `.txt` or `.md` files in a folder, then:
33
+
34
+ ```bash
35
+ oglodon train my_texts/ --out run1 --steps 500
36
+ oglodon generate run1 --prompt "Once upon a time" --seed 1
37
+ oglodon eval run1 --text my_texts/some_file.txt
38
+ ```
39
+
40
+ `train` builds a tokenizer, trains a small model and saves a checkpoint; `eval` prints perplexity next to the score of
41
+ a model that guesses at random, so you can see whether it learned anything. A model trained for minutes learns your
42
+ text's vocabulary and local patterns, not fluent language. No Python code is needed.
43
+
44
+ ## How it fits together
45
+
46
+ ```text
47
+ text files ──► BPE tokenizer ──► token file ──► train ──► CHECKPOINT
48
+ │
49
+ ┌─────────────┬──────────────┬──────────────┬─────────┴────────┐
50
+ ▼ ▼ ▼ ▼ ▼
51
+ generate eval verify quantize export to
52
+ (stream text) (perplexity) (behaviour) (int8 copy) Hugging Face
53
+ ▲
54
+ any Hugging Face / PyTorch model ───┘ verify accepts any causal LM
55
+ ```
56
+
57
+ Inside the model:
58
+
59
+ ```text
60
+ tokens ─► Embedding ─► [ Norm ─► Attention (RoPE, KV cache) ─► + ─► Norm ─► FFN ─► + ] × N ─► Norm ─► LM head ─► logits
61
+ MHA / GQA / MQA SwiGLU / GELU
62
+ ```
63
+
64
+ ## What you can do
65
+
66
+ | Command | What it does |
67
+ |---|---|
68
+ | `oglodon train` | Text files to tokenizer, trained model and report. Exact `--resume`, data-parallel under `torchrun` |
69
+ | `oglodon generate` | Streams text: temperature, top-k, top-p, min-p, repetition penalty, stop strings, KV cache |
70
+ | `oglodon eval` | Perplexity, multiple-choice accuracy, generation sanity checks, saved as JSON |
71
+ | `oglodon verify` | Behaviour checks on any causal LM; `--cross-check` compares against a Hugging Face model |
72
+ | `oglodon validate` | Compares an Oglodon model with an independent float64 reference implementation |
73
+ | `oglodon compare` | Trains variants on identical data and seeds and writes reproducible comparison reports |
74
+ | `oglodon quantize` | Int8 weight-only copy of a checkpoint with a measured accuracy drift |
75
+ | `oglodon info` | Versions and whether CUDA is available |
76
+
77
+ Architecture options: MHA, GQA or MQA attention, RoPE, learned or ALiBi positions, RMSNorm or LayerNorm, SwiGLU,
78
+ GeGLU, GELU or ReLU² feed-forward, sliding window, qkv bias. Export to Llama, Mistral or Qwen2 format for
79
+ Hugging Face with `export_hf(model, "hf_dir")`.
80
+
81
+ ## Verify any model
82
+
83
+ ```bash
84
+ oglodon verify --checkpoint run1 # an Oglodon checkpoint
85
+ oglodon verify --hf HuggingFaceTB/SmolLM2-135M --cross-check --dtype float32
86
+ ```
87
+
88
+ | Check | What it catches |
89
+ |---|---|
90
+ | Causality | A token's prediction changes when later tokens change |
91
+ | Padding and batching | Padded or batched inputs giving different answers than single ones |
92
+ | KV cache | Cached decoding disagreeing with a full forward pass |
93
+ | Numerics | float32 vs float64 drift, non-finite values |
94
+ | Gradients | Autograd disagreeing with finite differences, dead parameters |
95
+ | Cross-check | An Oglodon model and its Hugging Face twin producing different logits |
96
+
97
+ Skipped or unsupported checks are reported as such and are never counted as passed.
98
+
99
+ ## What has been tested
100
+
101
+ | Verified | Not yet |
102
+ |---|---|
103
+ | Test suite on CPU: Python 3.11, 3.12 and 3.13 (Linux) and the suite on Windows | macOS |
104
+ | Test suite, `validate`, `verify`, bf16 and fp16 steps on one Tesla T4 (Colab) | Multi-GPU, FlashAttention kernels, other GPUs |
105
+ | `verify --cross-check` on SmolLM2-135M in float32: logits agree to about 1e-4, greedy output identical | Other pretrained models |
106
+ | Int8 drift measured on a small trained model (perplexity change about 0.001%) | Int8 on large models or on a GPU |
107
+ | Hugging Face export matches logits to about 1e-6 | Gemma, Phi, Mixtral converters, FSDP, 4-bit quantization |
108
+
109
+ Details and exact numbers: [Limitations](https://github.com/Dhruvg0/oglodon/blob/main/docs/limitations.md) and [Performance and scaling](https://github.com/Dhruvg0/oglodon/blob/main/docs/performance-and-scaling.md).
110
+
111
+ ## Documentation
112
+
113
+ * [Getting started](https://github.com/Dhruvg0/oglodon/blob/main/docs/getting-started.md) and [command reference](https://github.com/Dhruvg0/oglodon/blob/main/docs/cli.md)
114
+ * [Training](https://github.com/Dhruvg0/oglodon/blob/main/docs/training.md), [data and tokenizers](https://github.com/Dhruvg0/oglodon/blob/main/docs/data-and-tokenization.md), [generation](https://github.com/Dhruvg0/oglodon/blob/main/docs/generation.md),
115
+ [evaluation](https://github.com/Dhruvg0/oglodon/blob/main/docs/evaluation.md)
116
+ * [Verify](https://github.com/Dhruvg0/oglodon/blob/main/docs/verify.md), [validation](https://github.com/Dhruvg0/oglodon/blob/main/docs/validation.md), [experiments](https://github.com/Dhruvg0/oglodon/blob/main/docs/experiments.md),
117
+ [quantization](https://github.com/Dhruvg0/oglodon/blob/main/docs/quantization.md), [Hugging Face interop](https://github.com/Dhruvg0/oglodon/blob/main/docs/interoperability.md)
118
+ * [Python and feature reference](https://github.com/Dhruvg0/oglodon/blob/main/docs/reference.md), [architecture](https://github.com/Dhruvg0/oglodon/blob/main/docs/architecture.md),
119
+ [configuration](https://github.com/Dhruvg0/oglodon/blob/main/docs/configuration.md), [troubleshooting](https://github.com/Dhruvg0/oglodon/blob/main/docs/troubleshooting.md)
120
+ * Runnable scripts in [`examples/`](https://github.com/Dhruvg0/oglodon/tree/main/examples)
121
+
122
+ ## Contributing and licence
123
+
124
+ Contributions are welcome; see [docs/contributing.md](https://github.com/Dhruvg0/oglodon/blob/main/docs/contributing.md). Released under the [MIT licence](https://github.com/Dhruvg0/oglodon/blob/main/LICENSE).
125
+
126
+ Oglodon is an independent project. It is not affiliated with, endorsed by or derived from NVIDIA or any hardware vendor.
@@ -0,0 +1,35 @@
1
+ """Measure MHA vs GQA vs MQA on this machine (nothing here is a pre-recorded number).
2
+
3
+ python benchmarks/run_comparison.py --hidden 256 --layers 6 --heads 8 --seq 128 --batch 4
4
+ """
5
+
6
+ import argparse
7
+
8
+ from oglodon import OglodonConfig
9
+ from oglodon.benchmarks import compare_architectures, format_results
10
+
11
+ p = argparse.ArgumentParser()
12
+ p.add_argument("--hidden", type=int, default=256)
13
+ p.add_argument("--layers", type=int, default=6)
14
+ p.add_argument("--heads", type=int, default=8)
15
+ p.add_argument("--seq", type=int, default=128)
16
+ p.add_argument("--new-tokens", type=int, default=32)
17
+ p.add_argument("--batch", type=int, default=4)
18
+ p.add_argument("--repeats", type=int, default=5)
19
+ a = p.parse_args()
20
+
21
+ kv_options = {"mha": a.heads, "gqa": max(1, a.heads // 4), "mqa": 1}
22
+ configs = [
23
+ OglodonConfig(
24
+ vocab_size=1000,
25
+ hidden_size=a.hidden,
26
+ num_layers=a.layers,
27
+ num_heads=a.heads,
28
+ num_kv_heads=kv,
29
+ max_seq_len=a.seq + a.new_tokens,
30
+ )
31
+ for kv in kv_options.values()
32
+ ]
33
+ results = compare_architectures(configs, a.batch, a.seq, a.new_tokens, list(kv_options), a.repeats)
34
+ print(format_results(results))
35
+ print("\nforward/generate times and cache sizes are measured; 'kv (est)' is the analytic formula.")
@@ -0,0 +1,23 @@
1
+ # oglodon compare configs/compare_mha_gqa.yaml --out comparison.json
2
+ model:
3
+ vocab_size: 1 # replaced by the tokenizer's size
4
+ hidden_size: 64
5
+ num_layers: 2
6
+ num_heads: 8
7
+ num_kv_heads: 8
8
+ max_seq_len: 96
9
+ variants:
10
+ mha: {num_kv_heads: 8}
11
+ gqa: {num_kv_heads: 2}
12
+ mqa: {num_kv_heads: 1}
13
+ baseline: mha
14
+ data:
15
+ block_size: 32 # built-in synthetic corpus; set `path: my.txt` for your own text
16
+ val_fraction: 0.1
17
+ train:
18
+ steps: 300
19
+ batch_size: 16
20
+ learning_rate: 0.003
21
+ seeds: [0, 1, 2]
22
+ match_params: true
23
+ validate: true
@@ -0,0 +1,18 @@
1
+ # Position methods and feed-forward variants on the same data and budget:
2
+ # oglodon compare configs/compare_positions_ffn.yaml --out positions.json --plot
3
+ model:
4
+ vocab_size: 1
5
+ hidden_size: 64
6
+ num_layers: 2
7
+ num_heads: 8
8
+ num_kv_heads: 8
9
+ max_seq_len: 96
10
+ variants:
11
+ rope: {}
12
+ learned: {use_rope: false}
13
+ alibi: {use_rope: false, use_alibi: true}
14
+ geglu: {ffn_activation: gelu}
15
+ relu2: {ffn_activation: relu2}
16
+ baseline: rope
17
+ data: {block_size: 32, val_fraction: 0.1}
18
+ train: {steps: 200, batch_size: 16, learning_rate: 0.003, seeds: [0, 1, 2], match_params: true, validate: true}
@@ -0,0 +1,10 @@
1
+ # oglodon compare configs/mha.yaml configs/gqa.yaml --out comparison.json
2
+ model:
3
+ vocab_size: 1 # replaced by the tokenizer's size
4
+ hidden_size: 64
5
+ num_layers: 2
6
+ num_heads: 8
7
+ num_kv_heads: 2
8
+ max_seq_len: 96
9
+ data: {block_size: 32, val_fraction: 0.1}
10
+ train: {steps: 200, batch_size: 16, learning_rate: 0.003, seeds: [0, 1, 2], match_params: true, validate: true}
@@ -0,0 +1,10 @@
1
+ # oglodon compare configs/mha.yaml configs/gqa.yaml --out comparison.json
2
+ model:
3
+ vocab_size: 1 # replaced by the tokenizer's size
4
+ hidden_size: 64
5
+ num_layers: 2
6
+ num_heads: 8
7
+ num_kv_heads: 8
8
+ max_seq_len: 96
9
+ data: {block_size: 32, val_fraction: 0.1}
10
+ train: {steps: 200, batch_size: 16, learning_rate: 0.003, seeds: [0, 1, 2], match_params: true, validate: true}
@@ -0,0 +1,14 @@
1
+ # oglodon validate configs/tiny_gqa.yaml --out validation_report.json
2
+ model:
3
+ vocab_size: 64
4
+ hidden_size: 64
5
+ num_layers: 2
6
+ num_heads: 8
7
+ num_kv_heads: 2 # GQA; 8 = MHA, 1 = MQA
8
+ max_seq_len: 64
9
+ eos_token_id: 1
10
+ pad_token_id: 0
11
+ validation:
12
+ device: cpu
13
+ dtype: float32
14
+ seed: 0
@@ -0,0 +1,88 @@
1
+ # Architecture
2
+
3
+ ```
4
+ tokens (B,T)
5
+ | embed_tokens (+ learned positions if use_rope=False and not use_alibi)
6
+ v
7
+ x (B,T,d) --+--------------------------------------------------------------+
8
+ | TransformerBlock x num_layers |
9
+ | h = x + Attn(Norm1(x)) q,k RoPE (or ALiBi bias) |
10
+ | y = h + FFN(Norm2(h)) FFN = gated or plain MLP |
11
+ +--------------------------------------------------------------+
12
+ | final_norm
13
+ v
14
+ lm_head (tied with embed_tokens by default) -> logits (B,T,V)
15
+ ```
16
+
17
+ ## Attention layouts
18
+
19
+ `num_heads` query heads share `num_kv_heads` key/value heads; query head `h` reads K/V head
20
+ `h // (num_heads // num_kv_heads)`.
21
+
22
+ | layout | `num_kv_heads` | KV-cache size vs MHA |
23
+ |---|---|---|
24
+ | MHA | `num_heads` | 1x |
25
+ | GQA | `1 < k < num_heads` | `k / num_heads` |
26
+ | MQA | `1` | `1 / num_heads` |
27
+
28
+ ## Position methods and feed-forward variants
29
+
30
+ | option | effect |
31
+ |---|---|
32
+ | `use_rope=True` (default) | rotary positions applied to q and k |
33
+ | `use_rope=False` | learned absolute position embeddings |
34
+ | `use_rope=False, use_alibi=True` | no position parameters; a linear distance penalty (per-head slope) is added to the attention scores |
35
+ | `use_swiglu=True` with `ffn_activation` `silu` / `gelu` / `relu2` | gated feed-forward: SwiGLU / GeGLU / ReLU²-gated |
36
+ | `use_swiglu=False` with `ffn_activation` `gelu` / `silu` / `relu2` | plain two-matrix MLP |
37
+
38
+ With `attn_impl="sdpa"`, plain causal attention (no padding mask, window or ALiBi) calls PyTorch's fused attention with
39
+ `is_causal=True`; every other case passes an explicit mask. Both give the same result (tested).
40
+
41
+ ## Package map
42
+
43
+ | package | role |
44
+ |---|---|
45
+ | `oglodon.layers`, `oglodon.models` | attention, RoPE, norms, feed-forward, KV cache, the model |
46
+ | `oglodon.generation` | sampling, streaming, stop criteria |
47
+ | `oglodon.training` | `Trainer`, checkpoints, distributed helpers |
48
+ | `oglodon.workflow` | text files to checkpoint (`train_from_files`), `complete` |
49
+ | `oglodon.data`, `oglodon.tokenization` | token files, datasets, BPE/char tokenizers |
50
+ | `oglodon.evaluation` | perplexity, multiple choice, generation checks |
51
+ | `oglodon.validation` | float64 reference checks for Oglodon models |
52
+ | `oglodon.verify` | model-agnostic behavioural checks, cross-implementation equivalence |
53
+ | `oglodon.convert` | Hugging Face import and export |
54
+ | `oglodon.experiments` | controlled comparisons and reports |
55
+
56
+ ## Where each notebook component went
57
+
58
+ | MiniGPT notebook | Oglodon |
59
+ |---|---|
60
+ | `RMSNorm` | `oglodon.layers.normalization.RMSNorm` (+ `nn.LayerNorm` option) |
61
+ | `rope_tables`, `apply_rope` | `oglodon.layers.rope.RotaryEmbedding`, `apply_rope` (same interleaved pairing) |
62
+ | `Attention` (GQA, concat cache) | `oglodon.layers.attention.CausalSelfAttention` + `oglodon.layers.cache.KVCache` |
63
+ | `SwiGLU` | `oglodon.layers.feedforward.SwiGLU` (+ `GELUMLP`) |
64
+ | `Block`, `MiniGPT` | `oglodon.models.transformer.TransformerBlock`, `oglodon.models.gpt.Oglodon` |
65
+ | char vocab, `enc`/`dec` | `oglodon.tokenization.CharTokenizer` |
66
+ | `make`, `batch`, `acc` | `oglodon.data.algorithmic` (`make_example`, `AlgorithmicDataset`, `exact_match`) |
67
+ | training loop | `oglodon.training.Trainer` |
68
+ | causality / cache checks | `oglodon.validation.validate_model` and `tests/` |
69
+
70
+ ## Changes relative to the notebook (deliberate)
71
+
72
+ * **Masking uses the dtype's most negative finite value instead of `-inf`**, so a fully masked row
73
+ (a padding query) gives a uniform softmax instead of NaN. This enabled padding masks.
74
+ * **Padding masks and `position_ids`** (the notebook only handled equal-length batches).
75
+ * **Dropout, optional learned positions, LayerNorm and GELU options**, all configurable.
76
+ * **GPT-2-style initialisation** (`N(0, 0.02)`, residual projections scaled by `1/sqrt(2L)`).
77
+ * **EOS handling** in generation (the notebook generated a fixed number of tokens), plus
78
+ temperature / top-k / top-p sampling.
79
+ * **Trainer** averages loss over supervised tokens and weights gradient-accumulation micro-batches by
80
+ token count, so accumulation is equivalent to a larger batch.
81
+ * The notebook's answer terminator `;` became a real `<eos>` token.
82
+
83
+ ## Design rules
84
+
85
+ * Attention knows nothing about positions: RoPE is applied to `q`/`k` by the caller-supplied
86
+ `rope` tuple, so swapping position schemes does not touch attention code.
87
+ * Attention maps are only returned when `output_attentions=True`; they are never stored on modules.
88
+ * The Trainer only calls `model(**batch)` and reads `.loss`; any module with that contract trains.
@@ -0,0 +1,101 @@
1
+ # Command-line reference
2
+
3
+ `oglodon <command> [options]` (also `python -m oglodon ...`). Run `oglodon <command> --help` for the authoritative
4
+ list; this page explains what each command does.
5
+
6
+ **Exit codes**: `0` success; `1` a check failed (`validate`, `verify`; with `--strict` also when something was
7
+ skipped or unsupported); `2` usage or configuration error (bad flag, missing file, unusable settings).
8
+ Errors print one `error: ...` line, not a traceback.
9
+
10
+ ## `oglodon train DATA... --out DIR`
11
+
12
+ Train on text files. `DATA` is any mix of files, folders (searched recursively for text-like extensions such as
13
+ `.txt .md .py .json .csv .tex`) and glob patterns.
14
+
15
+ | option | default | meaning |
16
+ |---|---|---|
17
+ | `--out DIR` | required | checkpoint folder |
18
+ | `--config FILE` | | YAML/JSON with `model:`, `data:`, `train:` sections; flags override it |
19
+ | `--tokenizer {bpe,char}` | `bpe` | byte-level BPE trained on the training split, or one symbol per character |
20
+ | `--vocab-size N` | 1024 | BPE vocabulary (the result can be smaller on a small corpus) |
21
+ | `--val-fraction F` | 0.05 | held-out share of the tokens |
22
+ | `--workers N` | 1 | parallel tokenization processes |
23
+ | `--block-size N` | 128 | context length (`max_seq_len`) |
24
+ | `--hidden-size N`, `--layers N`, `--heads N` | 128, 4, 8 | model size |
25
+ | `--kv-heads N` | heads // 4 | key/value heads (GQA); `--kv-heads` equal to `--heads` is MHA |
26
+ | `--steps N` | 1000 | optimizer steps |
27
+ | `--batch-size N` | 16 | per process |
28
+ | `--grad-accum N` | 1 | micro-batches per step |
29
+ | `--lr F`, `--weight-decay F`, `--warmup N` | 1e-3, 0.1, 5% of steps | optimization |
30
+ | `--seed N` | 0 | seeds data order and initialization |
31
+ | `--precision {fp32,bf16,fp16}` | `fp32` | autocast; `fp16` needs CUDA |
32
+ | `--eval-interval N`, `--save-interval N` | 10 evals/run, end only | evaluation and checkpoint cadence |
33
+ | `--grad-checkpointing` | off | recompute activations: less memory, more compute |
34
+ | `--compile` | off | `torch.compile` (first step is slow) |
35
+ | `--device D` | cuda if available | `cpu`, `cuda`, `cuda:1`, ... |
36
+ | `--resume` | off | continue the run in `--out` exactly where it stopped |
37
+ | `--overwrite` | off | allow replacing a model already in `--out` |
38
+
39
+ Without `--resume` or `--overwrite`, `train` refuses to touch a folder that already holds a model. Under
40
+ `torchrun` it trains data-parallel automatically: see [Performance and scaling](performance-and-scaling.md).
41
+ Details: [Training](training.md).
42
+
43
+ ## `oglodon generate CHECKPOINT`
44
+
45
+ Stream text from a checkpoint made by `oglodon train` (or `save_pretrained(..., tokenizer=...)`).
46
+
47
+ | option | default | meaning |
48
+ |---|---|---|
49
+ | `--prompt`, `-p TEXT` | stdin | text to continue; empty means unconditional |
50
+ | `--max-new-tokens N` | 100 | must be below the model's context length |
51
+ | `--temperature F` | 0.8 | `0` is greedy |
52
+ | `--top-k N`, `--top-p F`, `--min-p F` | 40, off, off | sampling filters (`--top-k 0` disables) |
53
+ | `--repetition-penalty F` | 1.0 | above 1 discourages repeats |
54
+ | `--stop TEXT` | | stop after this text; repeatable |
55
+ | `--seed N` | | reproducible sampling |
56
+ | `--only-new` | off | do not echo the prompt |
57
+ | `--no-stream` | off | print once at the end |
58
+
59
+ Details: [Generation](generation.md).
60
+
61
+ ## `oglodon eval CHECKPOINT`
62
+
63
+ At least one of: `--text FILE` (perplexity; `--block-size`, `--stride`, `--batch-size`), `--choices FILE.jsonl`
64
+ (log-likelihood multiple choice), `--prompt P [P ...]` (greedy generation sanity check, `--max-new-tokens`).
65
+ `--out FILE` writes a JSON report. Details: [Evaluation](evaluation.md).
66
+
67
+ ## `oglodon quantize CHECKPOINT --out DIR`
68
+
69
+ Writes an int8 weight-only copy of a checkpoint (about 4x smaller linear weights; see [Quantization](quantization.md)).
70
+
71
+ | flag | default | meaning |
72
+ |---|---|---|
73
+ | `--out DIR` | required | where the int8 checkpoint goes |
74
+ | `--group-size N` | per channel | one scale per N input channels; must divide every quantized layer's input width |
75
+ | `--include-lm-head` | off | also quantize the output matrix (only when embeddings are not tied) |
76
+ | `--text FILE` | none | measure perplexity, KL and top-1 agreement on this text; without it drift is **not** measured |
77
+ | `--block-size N` | model maximum | window length for that measurement |
78
+
79
+ The result loads with `Oglodon.from_pretrained`, `oglodon generate` and `oglodon eval`.
80
+
81
+ ## `oglodon compare CONFIG [CONFIG ...]`
82
+
83
+ Train architecture variants under identical conditions and report. One config with a `variants:` map, or several
84
+ config files (one variant each; the first is the baseline). `--out FILE.json` (also writes `.md`), `--plot`
85
+ (validation-loss curves as PNG, needs the `[viz]` extra), `--device`. Details: [Experiments](experiments.md).
86
+
87
+ ## `oglodon verify`
88
+
89
+ Behavioural checks on any causal LM. Choose the model with exactly one of `--hf ID_OR_DIR`, `--hf-config FILE_OR_DIR`
90
+ (random weights, offline), `--factory package.module:function`, `--checkpoint DIR`, `--config FILE`. Other options:
91
+ `--cross-check`, `--categories`, `--exclude`, `--no-stress`, `--max-fp64-params`, `--device`, `--dtype`, `--seed`,
92
+ `--vocab-size`, `--strict`, `--out`. Details: [verify](verify.md).
93
+
94
+ ## `oglodon validate CONFIG`
95
+
96
+ Compare an Oglodon model against the independent float64 reference. `--checkpoint DIR`, `--categories`, `--device`,
97
+ `--dtype`, `--seed`, `--strict`, `--out`. Details: [validation](validation.md).
98
+
99
+ ## `oglodon info`
100
+
101
+ Prints versions, CUDA availability and bf16 support as JSON.