eka-ai 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.
eka_ai-1.0.0/LICENSE ADDED
@@ -0,0 +1,159 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner.
50
+
51
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
52
+ whom a Contribution has been received by the Licensor and included
53
+ within the Work.
54
+
55
+ 2. Grant of Copyright License. Subject to the terms and conditions of
56
+ this License, each Contributor hereby grants to You a perpetual,
57
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
58
+ copyright license to reproduce, prepare Derivative Works of,
59
+ publicly display, publicly perform, sublicense, and distribute the
60
+ Work and such Derivative Works in Source or Object form.
61
+
62
+ 3. Grant of Patent License. Subject to the terms and conditions of
63
+ this License, each Contributor hereby grants to You a perpetual,
64
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
65
+ (except as stated in this section) patent license to make, have made,
66
+ use, offer to sell, sell, import, and otherwise transfer the Work,
67
+ where such license applies only to those patent claims licensable
68
+ by such Contributor that are necessarily infringed by their
69
+ Contribution(s) alone or by the combination of their Contribution(s)
70
+ with the Work to which such Contribution(s) was submitted.
71
+
72
+ 4. Redistribution. You may reproduce and distribute copies of the
73
+ Work or Derivative Works thereof in any medium, with or without
74
+ modifications, and in Source or Object form, provided that You
75
+ meet the following conditions:
76
+
77
+ (a) You must give any other recipients of the Work or
78
+ Derivative Works a copy of this License; and
79
+
80
+ (b) You must cause any modified files to carry prominent notices
81
+ stating that You changed the files; and
82
+
83
+ (c) You must retain, in the Source form of any Derivative Works
84
+ that You distribute, all copyright, patent, trademark, and
85
+ attribution notices from the Source form of the Work,
86
+ excluding those notices that do not pertain to any part of
87
+ the Derivative Works; and
88
+
89
+ (d) If the Work includes a "NOTICE" text file as part of its
90
+ distribution, You must include a readable copy of the
91
+ attribution notices contained within such NOTICE file, in
92
+ at least one of the following places: within a NOTICE text
93
+ file distributed as part of the Derivative Works; within
94
+ the Source form or documentation, if provided along with the
95
+ Derivative Works; or, within a display generated by the
96
+ Derivative Works, if and wherever such third-party notices
97
+ normally appear.
98
+
99
+ The contents of the NOTICE file are for informational purposes
100
+ only and do not modify the License.
101
+
102
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
103
+ any Contribution intentionally submitted for inclusion in the Work
104
+ by You to the Licensor shall be under the terms and conditions of
105
+ this License, without any additional terms or conditions.
106
+
107
+ 6. Trademarks. This License does not grant permission to use the trade
108
+ names, trademarks, service marks, or product names of the Licensor,
109
+ except as required for reasonable and customary use in describing the
110
+ origin of the Work.
111
+
112
+ 7. Disclaimer of Warranty. Unless required by applicable law or
113
+ agreed to in writing, Licensor provides the Work (and each
114
+ Contributor provides its Contributions) on an "AS IS" BASIS,
115
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
116
+ implied, including, without limitation, any warranties or conditions
117
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
118
+ PARTICULAR PURPOSE. You are solely responsible for determining the
119
+ appropriateness of using or reproducing the Work and assume any
120
+ risks associated with Your exercise of permissions under this License.
121
+
122
+ 8. Limitation of Liability. In no event and under no legal theory,
123
+ whether in tort (including negligence), contract, or otherwise,
124
+ unless required by applicable law (such as deliberate and grossly
125
+ negligent acts) or agreed to in writing, shall any Contributor be
126
+ liable to You for damages, including any direct, indirect, special,
127
+ incidental, or exemplary damages of any character arising as a
128
+ result of this License or out of the use or inability to use the
129
+ Work (including but not limited to damages for loss of goodwill,
130
+ work stoppage, computer failure or malfunction, or all other
131
+ commercial damages or losses), even if such Contributor has been
132
+ advised of the possibility of such damages.
133
+
134
+ 9. Accepting Warranty or Additional Liability. While redistributing
135
+ the Work or Derivative Works thereof, You may choose to offer,
136
+ and charge a fee for, acceptance of support, warranty, indemnity,
137
+ or other liability obligations and/or rights consistent with this
138
+ License. However, in accepting such obligations, You may act only
139
+ on Your own behalf and on Your sole responsibility, not on behalf
140
+ of any other Contributor, and only if You agree to indemnify,
141
+ defend, and hold each Contributor harmless for any liability
142
+ incurred by, or claims asserted against, such Contributor by reason
143
+ of your accepting any such warranty or additional liability.
144
+
145
+ END OF TERMS AND CONDITIONS
146
+
147
+ Copyright 2024 EKA-AI Contributors
148
+
149
+ Licensed under the Apache License, Version 2.0 (the "License");
150
+ you may not use this file except in compliance with the License.
151
+ You may obtain a copy of the License at
152
+
153
+ http://www.apache.org/licenses/LICENSE-2.0
154
+
155
+ Unless required by applicable law or agreed to in writing, software
156
+ distributed under the License is distributed on an "AS IS" BASIS,
157
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158
+ See the License for the specific language governing permissions and
159
+ limitations under the License.
@@ -0,0 +1,11 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include pyproject.toml
5
+ recursive-include eka_ai *.py *.typed
6
+ recursive-include tests *.py
7
+ recursive-include examples *.py
8
+ global-exclude __pycache__
9
+ global-exclude *.py[cod]
10
+ global-exclude *.so
11
+ global-exclude .DS_Store
eka_ai-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,424 @@
1
+ Metadata-Version: 2.4
2
+ Name: eka-ai
3
+ Version: 1.0.0
4
+ Summary: A 109M parameter historical language model trained from scratch on Project Gutenberg
5
+ Author: EKA-AI Contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/eka-ai/eka-ai
8
+ Project-URL: Repository, https://github.com/eka-ai/eka-ai
9
+ Project-URL: Issues, https://github.com/eka-ai/eka-ai/issues
10
+ Project-URL: Changelog, https://github.com/eka-ai/eka-ai/blob/main/CHANGELOG.md
11
+ Keywords: language-model,historical,transformer,nlp,pytorch,text-generation,gutenberg
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Text Processing :: Linguistic
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: torch>=2.1.0
27
+ Requires-Dist: sentencepiece>=0.1.99
28
+ Requires-Dist: gdown>=4.7.3
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.4; extra == "dev"
31
+ Requires-Dist: pytest-cov>=4.1; extra == "dev"
32
+ Requires-Dist: black>=23.0; extra == "dev"
33
+ Requires-Dist: isort>=5.12; extra == "dev"
34
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
35
+ Requires-Dist: mypy>=1.5; extra == "dev"
36
+ Provides-Extra: docs
37
+ Requires-Dist: sphinx>=7.0; extra == "docs"
38
+ Requires-Dist: sphinx-rtd-theme>=1.3; extra == "docs"
39
+ Requires-Dist: myst-parser>=2.0; extra == "docs"
40
+ Dynamic: license-file
41
+
42
+ <div align="center">
43
+
44
+ # EKA-1
45
+
46
+ **A 109M parameter historical language model trained from scratch on Project Gutenberg**
47
+
48
+ [![PyPI version](https://img.shields.io/pypi/v/eka-ai.svg)](https://pypi.org/project/eka-ai/)
49
+ [![Python](https://img.shields.io/pypi/pyversions/eka-ai.svg)](https://pypi.org/project/eka-ai/)
50
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
51
+ [![Tests](https://github.com/eka-ai/eka-ai/actions/workflows/tests.yml/badge.svg)](https://github.com/eka-ai/eka-ai/actions/workflows/tests.yml)
52
+
53
+ </div>
54
+
55
+ ---
56
+
57
+ EKA-1 is a **decoder-only Transformer** with **109,529,856 parameters**, trained entirely from scratch on classical texts from [Project Gutenberg](https://www.gutenberg.org/). It features a modern architecture — RMSNorm, Rotary Position Embeddings (RoPE), SwiGLU activation, multi-head causal attention via PyTorch SDPA, and weight tying — packed into a library with a clean, one-line API.
58
+
59
+ ---
60
+
61
+ ## Table of Contents
62
+
63
+ - [Features](#features)
64
+ - [Installation](#installation)
65
+ - [Quick Start](#quick-start)
66
+ - [API Reference](#api-reference)
67
+ - [Model Architecture](#model-architecture)
68
+ - [Model Configuration](#model-configuration)
69
+ - [Examples](#examples)
70
+ - [Development](#development)
71
+ - [Publishing to PyPI](#publishing-to-pypi)
72
+ - [License](#license)
73
+
74
+ ---
75
+
76
+ ## Features
77
+
78
+ | Feature | Status |
79
+ |---|---|
80
+ | Automatic model & tokenizer download | ✅ |
81
+ | CPU inference | ✅ |
82
+ | CUDA inference | ✅ |
83
+ | Text generation | ✅ |
84
+ | Chat interface (single & multi-turn) | ✅ |
85
+ | Streaming generation | ✅ |
86
+ | Temperature sampling | ✅ |
87
+ | Top-k sampling | ✅ |
88
+ | Top-p (nucleus) sampling | ✅ |
89
+ | Repetition penalty | ✅ |
90
+ | Context truncation | ✅ |
91
+ | PEP 561 typed package | ✅ |
92
+
93
+ ---
94
+
95
+ ## Installation
96
+
97
+ **From PyPI (recommended):**
98
+
99
+ ```bash
100
+ pip install eka-ai
101
+ ```
102
+
103
+ **From source:**
104
+
105
+ ```bash
106
+ git clone https://github.com/eka-ai/eka-ai.git
107
+ cd eka-ai
108
+ pip install -e ".[dev]"
109
+ ```
110
+
111
+ **Requirements:**
112
+
113
+ - Python ≥ 3.9
114
+ - PyTorch ≥ 2.1
115
+ - sentencepiece ≥ 0.1.99
116
+ - gdown ≥ 4.7.3
117
+
118
+ On first use, `EKA()` automatically downloads `eka_model.pt` (~424 MB) and `tokenizer.model` (~768 KB) to `~/.cache/eka_ai/`.
119
+
120
+ > **Custom cache location:** Set the `EKA_CACHE_DIR` environment variable to override the default cache directory.
121
+
122
+ ---
123
+
124
+ ## Quick Start
125
+
126
+ ```python
127
+ from eka_ai import EKA
128
+
129
+ # Loads model on first call — downloads files automatically
130
+ model = EKA()
131
+
132
+ # ── Text generation ────────────────────────────────────────
133
+ print(
134
+ model.generate(
135
+ "Tell me about the Roman Empire",
136
+ max_new_tokens=128,
137
+ )
138
+ )
139
+
140
+ # ── Single-turn chat ───────────────────────────────────────
141
+ print(
142
+ model.chat(
143
+ "Who was Ashoka?"
144
+ )
145
+ )
146
+
147
+ # ── Streaming generation ───────────────────────────────────
148
+ for token in model.stream(
149
+ "Tell me a story"
150
+ ):
151
+ print(token, end="", flush=True)
152
+ ```
153
+
154
+ ---
155
+
156
+ ## API Reference
157
+
158
+ ### `EKA(...)` — constructor
159
+
160
+ ```python
161
+ model = EKA(
162
+ device=None, # "cpu" | "cuda" | torch.device — auto-detected
163
+ dtype=None, # torch.bfloat16 on CPU by default
164
+ model_path=None, # override cached model path
165
+ tokenizer_path=None, # override cached tokenizer path
166
+ auto_download=True, # download files if not cached
167
+ system_prompt=None, # custom system prompt for chat()
168
+ verbose=True, # print loading progress
169
+ )
170
+ ```
171
+
172
+ ---
173
+
174
+ ### `model.generate(prompt, ...)` → `str`
175
+
176
+ Generate a text continuation for a plain prompt.
177
+
178
+ ```python
179
+ text = model.generate(
180
+ prompt,
181
+ max_new_tokens=256, # int — max tokens to generate
182
+ temperature=0.8, # float — sampling temperature (> 0)
183
+ top_k=50, # int — top-k cutoff (0 = disabled)
184
+ top_p=0.95, # float — nucleus threshold (1.0 = disabled)
185
+ repetition_penalty=1.1, # float — penalty for repeated tokens (1.0 = disabled)
186
+ return_result=False, # bool — return GenerationResult with metadata
187
+ )
188
+ ```
189
+
190
+ When `return_result=True`, returns a `GenerationResult` with attributes:
191
+ - `.text` — the generated text
192
+ - `.tokens_generated` — number of new tokens
193
+ - `.tokens_per_second` — generation throughput
194
+ - `.device` — device used
195
+
196
+ ---
197
+
198
+ ### `model.chat(message, ...)` → `str`
199
+
200
+ Single-turn or multi-turn chat using the built-in chat template.
201
+
202
+ ```python
203
+ reply = model.chat(
204
+ message,
205
+ history=None, # list of (user, assistant) tuples
206
+ system_prompt=None, # override instance system prompt
207
+ max_new_tokens=256,
208
+ temperature=0.8,
209
+ top_k=50,
210
+ top_p=0.95,
211
+ repetition_penalty=1.1,
212
+ )
213
+ ```
214
+
215
+ **Multi-turn example:**
216
+
217
+ ```python
218
+ history = []
219
+ reply1 = model.chat("Who was Julius Caesar?")
220
+ history.append(("Who was Julius Caesar?", reply1))
221
+
222
+ reply2 = model.chat("What were his greatest conquests?", history=history)
223
+ ```
224
+
225
+ ---
226
+
227
+ ### `model.stream(prompt, ...)` → `Iterator[str]`
228
+
229
+ Streaming generation — yields one decoded token piece at a time.
230
+
231
+ ```python
232
+ for piece in model.stream(
233
+ "The ancient library of",
234
+ max_new_tokens=128,
235
+ temperature=0.8,
236
+ ):
237
+ print(piece, end="", flush=True)
238
+ ```
239
+
240
+ ---
241
+
242
+ ### `model.stream_chat(message, ...)` → `Iterator[str]`
243
+
244
+ Like `stream()` but uses the chat template.
245
+
246
+ ```python
247
+ for piece in model.stream_chat("Tell me about Socrates"):
248
+ print(piece, end="", flush=True)
249
+ ```
250
+
251
+ ---
252
+
253
+ ### `model.info()` → `dict`
254
+
255
+ ```python
256
+ info = model.info()
257
+ # {
258
+ # "version": "1.0.0",
259
+ # "parameters": 109529856,
260
+ # "device": "cpu",
261
+ # "dtype": "torch.bfloat16",
262
+ # "vocab_size": 32000,
263
+ # "n_layers": 12,
264
+ # "n_heads": 12,
265
+ # "d_model": 768,
266
+ # "context_length": 512,
267
+ # }
268
+ ```
269
+
270
+ ---
271
+
272
+ ## Model Architecture
273
+
274
+ EKA-1 is a decoder-only Transformer with the following design choices:
275
+
276
+ | Component | Implementation |
277
+ |---|---|
278
+ | Normalisation | **RMSNorm** (no bias, no mean subtraction) |
279
+ | Position encoding | **Rotary Position Embeddings (RoPE)** — no learned position table |
280
+ | Feed-forward | **SwiGLU** — `down(silu(gate(x)) ⊙ up(x))` |
281
+ | Attention | **Multi-Head Causal Attention** via PyTorch `scaled_dot_product_attention` |
282
+ | Weight sharing | **Weight tying** — embedding and LM-head share parameters |
283
+ | Architecture | Pre-norm residual blocks |
284
+ | Bias | None (all linear layers are bias-free) |
285
+
286
+ The attention implementation uses PyTorch's built-in SDPA which automatically selects the optimal kernel: FlashAttention 2 (when available), memory-efficient attention, or the reference implementation.
287
+
288
+ ---
289
+
290
+ ## Model Configuration
291
+
292
+ ```json
293
+ {
294
+ "vocab_size": 32000,
295
+ "n_layers": 12,
296
+ "n_heads": 12,
297
+ "n_kv_heads": 12,
298
+ "d_model": 768,
299
+ "d_ffn": 3072,
300
+ "context_length": 512,
301
+ "dropout": 0.0,
302
+ "bias": false
303
+ }
304
+ ```
305
+
306
+ | Parameter | Value |
307
+ |---|---|
308
+ | Total parameters | **109,529,856** |
309
+ | Embedding dimension | 768 |
310
+ | Attention heads | 12 × 64-dim heads |
311
+ | Transformer layers | 12 |
312
+ | FFN hidden dim | 2048 (after SwiGLU 2/3 ratio) |
313
+ | Vocabulary | 32,000 BPE tokens (SentencePiece) |
314
+ | Context length | 512 tokens |
315
+ | Training data | Project Gutenberg |
316
+
317
+ ---
318
+
319
+ ## Examples
320
+
321
+ Run the provided example scripts from the repository root:
322
+
323
+ ```bash
324
+ # Interactive text generation
325
+ python examples/generation.py --prompt "The fall of Rome" --max_tokens 200
326
+
327
+ # Interactive chat REPL
328
+ python examples/chat.py
329
+ python examples/chat.py --stream # streaming mode
330
+ python examples/chat.py --device cuda # GPU
331
+
332
+ # Throughput benchmark
333
+ python examples/benchmark.py --runs 10 --max_tokens 256
334
+ python examples/benchmark.py --device cuda
335
+ ```
336
+
337
+ ---
338
+
339
+ ## Development
340
+
341
+ ```bash
342
+ # Clone and install in editable mode with dev extras
343
+ git clone https://github.com/eka-ai/eka-ai.git
344
+ cd eka-ai
345
+ pip install -e ".[dev]"
346
+
347
+ # Run the full test suite
348
+ pytest tests/ -v
349
+
350
+ # Run specific test file
351
+ pytest tests/test_model.py -v
352
+
353
+ # Lint
354
+ ruff check eka_ai/ tests/
355
+ black --check eka_ai/ tests/ examples/
356
+
357
+ # Auto-format
358
+ black eka_ai/ tests/ examples/
359
+ isort eka_ai/ tests/
360
+
361
+ # Type check
362
+ mypy eka_ai/
363
+ ```
364
+
365
+ ### Project Structure
366
+
367
+ ```
368
+ eka-ai/
369
+
370
+ ├── eka_ai/
371
+ │ ├── __init__.py # Public API exports
372
+ │ ├── config.py # EKAConfig dataclass
373
+ │ ├── model.py # EKA1Model architecture
374
+ │ ├── tokenizer.py # EKATokenizer (SentencePiece wrapper)
375
+ │ ├── downloader.py # Automatic model/tokenizer download
376
+ │ ├── generation.py # EKA high-level API
377
+ │ ├── utils.py # Sampling utilities
378
+ │ └── py.typed # PEP 561 marker
379
+
380
+ ├── examples/
381
+ │ ├── chat.py # Interactive chat REPL
382
+ │ ├── generation.py # Text generation demo
383
+ │ └── benchmark.py # Throughput benchmark
384
+
385
+ ├── tests/
386
+ │ ├── test_config.py # Config unit tests
387
+ │ ├── test_model.py # Architecture unit tests
388
+ │ ├── test_utils.py # Sampling utility tests
389
+ │ └── test_generation.py# API integration tests
390
+
391
+ ├── .github/workflows/
392
+ │ ├── publish.yml # PyPI publishing workflow
393
+ │ └── tests.yml # CI test matrix
394
+
395
+ ├── README.md
396
+ ├── LICENSE # Apache 2.0
397
+ ├── setup.py
398
+ ├── pyproject.toml
399
+ ├── requirements.txt
400
+ └── MANIFEST.in
401
+ ```
402
+
403
+
404
+ ## Citation
405
+
406
+ If you use EKA-1 in your research, please cite:
407
+
408
+ ```bibtex
409
+ @misc{eka1_2024,
410
+ title = {{EKA-1}: A 109M Parameter Historical Language Model},
411
+ author = {chvkrsubhash},
412
+ year = {2026},
413
+ url = {https://github.com/eka-ai/eka-ai},
414
+ note = {Trained from scratch on Project Gutenberg}
415
+ }
416
+ ```
417
+
418
+ ---
419
+
420
+ ## License
421
+
422
+ This project is licensed under the **Apache License 2.0** — see [LICENSE](LICENSE) for details.
423
+
424
+ The training data is sourced from [Project Gutenberg](https://www.gutenberg.org/), which consists of public-domain works.