pytensorforge 0.1.0__py3-none-any.whl
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.
- cli.py +604 -0
- pytensorforge-0.1.0.dist-info/METADATA +103 -0
- pytensorforge-0.1.0.dist-info/RECORD +146 -0
- pytensorforge-0.1.0.dist-info/WHEEL +5 -0
- pytensorforge-0.1.0.dist-info/entry_points.txt +2 -0
- pytensorforge-0.1.0.dist-info/top_level.txt +2 -0
- src/__init__.py +0 -0
- src/activations/Activation.py +4 -0
- src/activations/ELU.py +11 -0
- src/activations/GELU.py +6 -0
- src/activations/ReLU.py +27 -0
- src/activations/SELU.py +14 -0
- src/activations/Sigmoid.py +27 -0
- src/activations/Softmax.py +84 -0
- src/activations/Tanh.py +29 -0
- src/activations/__init__.py +17 -0
- src/config.py +120 -0
- src/core/Matrix.py +3 -0
- src/core/Scalar.py +18 -0
- src/core/Tensor.py +866 -0
- src/core/Vector.py +31 -0
- src/core/__init__.py +0 -0
- src/data/__init__.py +0 -0
- src/data/chat_dataset.py +188 -0
- src/data/corpus.py +104 -0
- src/data/document_stream.py +178 -0
- src/data/parallel_encode.py +86 -0
- src/data/prefetch.py +62 -0
- src/data/shard_builder.py +119 -0
- src/data/shard_writer.py +81 -0
- src/data/sharded_dataset.py +112 -0
- src/data/streaming_dataset.py +132 -0
- src/data/validation.py +212 -0
- src/inference/__init__.py +0 -0
- src/inference/chat_template.py +384 -0
- src/inference/config.py +48 -0
- src/inference/engine.py +241 -0
- src/inference/export.py +133 -0
- src/inference/kv_cache.py +65 -0
- src/inference/runtime.py +161 -0
- src/inference/sampling.py +42 -0
- src/inference/scheduler.py +473 -0
- src/inference/text.py +67 -0
- src/initializers/Constant.py +9 -0
- src/initializers/GlorotNormal.py +15 -0
- src/initializers/GlorotUniform.py +26 -0
- src/initializers/HeNormal.py +15 -0
- src/initializers/HeUniform.py +14 -0
- src/initializers/Initializer.py +4 -0
- src/initializers/LecunNormal.py +16 -0
- src/initializers/LecunUniform.py +14 -0
- src/initializers/Ones.py +6 -0
- src/initializers/Orthogonal.py +14 -0
- src/initializers/RandomNormal.py +14 -0
- src/initializers/RandomUniform.py +14 -0
- src/initializers/Zeros.py +8 -0
- src/initializers/__init__.py +17 -0
- src/loss/CategoricalCrossEntropy.py +9 -0
- src/loss/CrossEntropyLoss.py +34 -0
- src/loss/CrossEntropyWithLogitsLoss.py +59 -0
- src/loss/Hinge.py +5 -0
- src/loss/Huber.py +22 -0
- src/loss/Loss.py +6 -0
- src/loss/MSE.py +7 -0
- src/loss/MSELoss.py +10 -0
- src/loss/SparseCategoricalCrossEntropy.py +15 -0
- src/loss/__init__.py +18 -0
- src/loss/bce.py +34 -0
- src/loss/mae.py +16 -0
- src/math/__init__.py +0 -0
- src/math/clip.py +37 -0
- src/math/exp.py +27 -0
- src/math/log.py +25 -0
- src/math/sigmoid.py +5 -0
- src/models/__init__.py +0 -0
- src/models/embedding/Embedding.py +65 -0
- src/models/embedding/__init__.py +0 -0
- src/models/gpt/__init__.py +0 -0
- src/models/gpt/attention.py +158 -0
- src/models/gpt/block.py +74 -0
- src/models/gpt/config.py +103 -0
- src/models/gpt/context.py +44 -0
- src/models/gpt/model.py +165 -0
- src/models/gpt/recompute.py +35 -0
- src/models/gpt/rope.py +84 -0
- src/models/regression/Linear.py +51 -0
- src/models/regression/Logistic.py +36 -0
- src/models/regression/__init__.py +0 -0
- src/models/seq/Sequential.py +297 -0
- src/models/seq/__init__.py +0 -0
- src/models/svm/__init__.py +0 -0
- src/models/tokenizer/BPETokenizer.py +228 -0
- src/models/tokenizer/__init__.py +0 -0
- src/models/transformers/Dropout.py +35 -0
- src/models/transformers/LastToken.py +10 -0
- src/models/transformers/LayerNorm.py +54 -0
- src/models/transformers/Linear.py +18 -0
- src/models/transformers/MultiHeadAttention.py +130 -0
- src/models/transformers/TransformerBlock.py +79 -0
- src/models/transformers/__init__.py +0 -0
- src/neural/Dense.py +58 -0
- src/neural/LSTM.py +167 -0
- src/neural/Layer.py +72 -0
- src/neural/Parameter.py +30 -0
- src/neural/RNN.py +83 -0
- src/neural/__init__.py +0 -0
- src/ops/__init__.py +0 -0
- src/ops/stack.py +40 -0
- src/optimizers/Adagrad.py +31 -0
- src/optimizers/Adam.py +98 -0
- src/optimizers/AdamW.py +84 -0
- src/optimizers/Batch.py +11 -0
- src/optimizers/Nesterov.py +35 -0
- src/optimizers/Optimizer.py +18 -0
- src/optimizers/RMSProp.py +35 -0
- src/optimizers/SGD.py +30 -0
- src/optimizers/SGDMomentum.py +28 -0
- src/optimizers/__init__.py +9 -0
- src/scaling/StandardScaler.py +15 -0
- src/scaling/__init__.py +0 -0
- src/serialization/__init__.py +0 -0
- src/serialization/checkpoint.py +58 -0
- src/serialization/modelio.py +132 -0
- src/serving/__init__.py +0 -0
- src/serving/app.py +792 -0
- src/serving/config.py +216 -0
- src/serving/errors.py +51 -0
- src/serving/http.py +599 -0
- src/serving/metrics.py +293 -0
- src/serving/model_server.py +287 -0
- src/serving/protocol.py +377 -0
- src/serving/security.py +200 -0
- src/serving/server.py +121 -0
- src/tokenization/__init__.py +0 -0
- src/tokenization/base.py +75 -0
- src/tokenization/bpe.py +190 -0
- src/tokenization/bytebpe.py +476 -0
- src/tokenization/registry.py +28 -0
- src/training/__init__.py +0 -0
- src/training/checkpoint_manager.py +101 -0
- src/training/experiment.py +71 -0
- src/training/losses.py +42 -0
- src/training/precision.py +141 -0
- src/training/profiler.py +38 -0
- src/training/scheduler.py +50 -0
- src/training/trainer.py +594 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytensorforge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deep Learning Framework
|
|
5
|
+
Author: Nnamdi Chidume
|
|
6
|
+
Project-URL: Homepage, http://github.com/philipszdavido/pytensorforge
|
|
7
|
+
Project-URL: Repository, http://github.com/philipszdavido/pytensorforge
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: numpy>=2.0
|
|
11
|
+
Requires-Dist: pyyaml>=6.0
|
|
12
|
+
|
|
13
|
+
# PyTensorForge
|
|
14
|
+
|
|
15
|
+
PyTensorForge is a machine learning framework. It provides a modular core for tensor operations, neural network layers, activation functions, optimizers, loss metrics, and model definitions. It is designed to build and train enterprise-level models for computer vision, forecasting, LLM, NLP, etc.
|
|
16
|
+
|
|
17
|
+
PyTensorForge is also designed for learning, experimentation, and rapid prototyping
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
- Core tensor and scalar abstractions for numerical computation
|
|
22
|
+
- Layer-based neural network support with dense and sequential model building
|
|
23
|
+
- Common activation functions such as ReLU, Sigmoid, Tanh, ELU, and SELU
|
|
24
|
+
- Standard optimization algorithms with SGD and batch optimization
|
|
25
|
+
- Loss functions including mean squared error, mean absolute error, and binary cross-entropy
|
|
26
|
+
- Weight initialization utilities with Glorot, He, LeCun, and zeros initializers
|
|
27
|
+
- Model implementations for regression and logistic classification
|
|
28
|
+
|
|
29
|
+
## Project Structure
|
|
30
|
+
|
|
31
|
+
- `src/core/` – Tensor, scalar, matrix, and vector primitives
|
|
32
|
+
- `src/neural/` – Neural layer abstractions, parameters, and dense layers
|
|
33
|
+
- `src/activations/` – Activation function implementations
|
|
34
|
+
- `src/optimizer/` – Optimizer base classes and SGD implementation
|
|
35
|
+
- `src/loss/` – Loss function abstractions and implementations
|
|
36
|
+
- `src/initializers/` – Weight initializer utilities
|
|
37
|
+
- `src/models/` – High-level model APIs for regression, classification, and sequential models
|
|
38
|
+
- `src/scaling/` – Data scaling utilities
|
|
39
|
+
- `src/models/gpt/` – decoder-only GPT Transformer (see `PHASE1_GPT_TRAINING.md`)
|
|
40
|
+
- `src/data/`, `src/training/` – streaming corpora, token shards, resumable trainer (`PHASE1_GPT_TRAINING.md`, `PHASE2_DATA_PIPELINE.md`)
|
|
41
|
+
- `src/tokenization/` – tokenizer abstraction, word-level and byte-level BPE (`TOKENIZER.md`)
|
|
42
|
+
- `src/inference/` – KV-cache inference runtime, continuous batching, chat templates (`PHASE3_INFERENCE.md`)
|
|
43
|
+
- `src/serving/` – OpenAI-compatible HTTP/SSE model server (`PHASE4_SERVING.md`)
|
|
44
|
+
- RoPE, activation checkpointing, bf16/fp16 numerics, parallel tokenization (`PHASE5_TRAINING_EFFICIENCY.md`)
|
|
45
|
+
- Context extension for RoPE models: extrapolate, linear, NTK (`PHASE6_CONTEXT_EXTENSION.md`)
|
|
46
|
+
- Fine-tuning (`init_from`) and chat training with assistant-only loss masking (`PHASE7_FINETUNING.md`)
|
|
47
|
+
- `web/` – TypeScript chat web client (prebuilt in `web/dist`)
|
|
48
|
+
- `predict/` – Prediction utilities and example datasets
|
|
49
|
+
- `test/` – Unit tests and example usage scripts
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
1. Clone the repository:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/philipsz-davido/PyTensorForge.git
|
|
57
|
+
cd PyTensorForge
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
2. Install dependencies:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install -e .
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This installs the `pytensorforge` command (`train`, `resume`, `evaluate`, `inspect`,
|
|
67
|
+
`tokenize`, `prepare-dataset`, `generate`, `export`, `serve`). Runtime dependencies are
|
|
68
|
+
`numpy` and `pyyaml` only.
|
|
69
|
+
|
|
70
|
+
> Note: This repository is intended for educational use and may require additional dependencies depending on the development environment.
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
Import components from the package and build models using the provided modules. Example:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from src.neural.Dense import Dense
|
|
78
|
+
from src.neural.Layer import Layer
|
|
79
|
+
from src.optimizers.SGD import SGD
|
|
80
|
+
from src.loss.MSE import MSE
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Refer to the `test/` directory for example scripts and usage patterns.
|
|
84
|
+
|
|
85
|
+
Serving a trained model:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pytensorforge export checkpoints/latest --output exports/my-gpt --tokenizer tokenizer/ --chat-template ptf-chat
|
|
89
|
+
pytensorforge serve exports/my-gpt --name my-gpt --api-key-file api_keys.txt
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then open `http://127.0.0.1:8000/` or point any OpenAI-compatible client at
|
|
93
|
+
`http://127.0.0.1:8000/v1`. See `serve.example.yaml` and `PHASE4_SERVING.md`.
|
|
94
|
+
|
|
95
|
+
## Contribution
|
|
96
|
+
|
|
97
|
+
Contributions are welcome. Please open an issue or submit a pull request for feature requests, bug fixes, or documentation improvements.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
This project is provided under the terms of the repository license. Check the project root for license details.
|
|
102
|
+
|
|
103
|
+
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
cli.py,sha256=MBqjNkIJOE2xBT48qw85mCiV-aTa_jhVAxuzcteERvk,21982
|
|
2
|
+
src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
src/config.py,sha256=136IZx99eEdTlroHrsqWtvz9qYDPPinHYDUvk6D2Xu0,3042
|
|
4
|
+
src/activations/Activation.py,sha256=v1DZXlrP3oAHj_HxtlcPC4kxBAH2jC6qApFQCEZKEBE,79
|
|
5
|
+
src/activations/ELU.py,sha256=H1nXwWoOB6YZ-ZoyfXccab8cAKUV66FNU9GCktqry2U,248
|
|
6
|
+
src/activations/GELU.py,sha256=gbfZPS744b4t2vDsSmijH-99vpXnFpp-h6nk_ZYrq7g,126
|
|
7
|
+
src/activations/ReLU.py,sha256=yeDrMxIIyxnKQWIwMrnh-Jzkn5TebzrLoCyFVD_Bpds,541
|
|
8
|
+
src/activations/SELU.py,sha256=QHQDTRelmiiYEJAjjxlUZfaFK-tiScJz3TCxgpgoCTY,308
|
|
9
|
+
src/activations/Sigmoid.py,sha256=knRXd320PfI7h2LdBOdutuoRQh80lpBO9cahLdreNtw,584
|
|
10
|
+
src/activations/Softmax.py,sha256=Gktg_NG8bWBkBLKhrQseuY6CJ6Xt5sB5S1FGVoVUlBM,1714
|
|
11
|
+
src/activations/Tanh.py,sha256=JZ8XgyBSfGpcprCfWrvEVZktbupjs_WzyTfg7mNiapk,551
|
|
12
|
+
src/activations/__init__.py,sha256=JL4lFByOmW5VCRWfbK_67OhZrNydNFPq3mf4OwZjEuk,343
|
|
13
|
+
src/core/Matrix.py,sha256=EANo7KDLzc1aQBrq7h9YL1bMCTiC3Hvyn8TIqv6hR2c,68
|
|
14
|
+
src/core/Scalar.py,sha256=H0cl7ajxgwWnbVF1Y_vmfIA0_EoWQl9Y5jfDRoxfDTE,322
|
|
15
|
+
src/core/Tensor.py,sha256=LDZoeSVJ18x-TdEK5XHW4D46jAd_YESM9rvFVrqzPSk,21085
|
|
16
|
+
src/core/Vector.py,sha256=fGQH68H1rM4cNR5k_x7x8sDQDaer5NE1XeTxeAaZls8,636
|
|
17
|
+
src/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
src/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
src/data/chat_dataset.py,sha256=EeNPqWnsuXFgkZ6mEsuEK_X8ANo9CgOp8f7e9oe8vmk,6326
|
|
20
|
+
src/data/corpus.py,sha256=EjLk1CAm8GAKTfZV-GnMvdWVSDm3Jnj6dUh2qaX0aUk,3053
|
|
21
|
+
src/data/document_stream.py,sha256=FZk9jhZjeIqcoXVcwPzb1iB-Lq5eW2GYeMYtfa7-xs4,4375
|
|
22
|
+
src/data/parallel_encode.py,sha256=WWfzP33Ji49f1IpXZKKFzzn78BJGwwDpwWzhQQESdm0,2664
|
|
23
|
+
src/data/prefetch.py,sha256=iLs1v15NbQmi--QBUHbKuRew5gnIm0GY5xHlImdOXsk,1606
|
|
24
|
+
src/data/shard_builder.py,sha256=zQhiIkdMaklzxtGFaed2MHLQKCGvhcyuibvzCnUq2ug,3176
|
|
25
|
+
src/data/shard_writer.py,sha256=y1skSHwbj6hMB657skDbUNKR4YafCl0AH_h8FY0NlVw,2076
|
|
26
|
+
src/data/sharded_dataset.py,sha256=oCkS9PnDJmqRHN8uJO1t273ZI3ZUxwnSHg_KskZdhLs,3765
|
|
27
|
+
src/data/streaming_dataset.py,sha256=A_1ZxuudRL8KqFwX8hpSEoLeKRBFlsOU-x5bQ7tEG3I,3858
|
|
28
|
+
src/data/validation.py,sha256=pl2mgI_minPI5lVFjBdlkhdKb43bE-wg_iJRBJOQ_S8,7056
|
|
29
|
+
src/inference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
|
+
src/inference/chat_template.py,sha256=_siKaBCimD0R9Be2ujDdcEai6HrE-S2QqCEsaIYSK5k,13060
|
|
31
|
+
src/inference/config.py,sha256=STgcXZOIqpY9bhpZ6jPp8nxch02A08X6x2VmrxCzQFM,1443
|
|
32
|
+
src/inference/engine.py,sha256=zRYkTKL4P70JcKwKGGi7Bw88PTkKGS2UyeSgQI7xV3w,7682
|
|
33
|
+
src/inference/export.py,sha256=9aJxQ6OeNGjff4wfs4Fa6Un4D8jlgrbHbDrBcse0LHg,4341
|
|
34
|
+
src/inference/kv_cache.py,sha256=eJR-fL3IvdUTVELjcdm9bdMJ4zq5avkFQW885GNJqUU,1904
|
|
35
|
+
src/inference/runtime.py,sha256=BOihJQPTym_D9f0KiyK1NhNvLLKbngqjXQul26m-hvk,5338
|
|
36
|
+
src/inference/sampling.py,sha256=JWI5UOkTlfmE3ASZfAmdFAyaez3BvvT8oARkSv2ycqI,1212
|
|
37
|
+
src/inference/scheduler.py,sha256=ArdrhwNEVc4M0whs0EOlyzKLAOWCR1Je505pqSn17vI,14407
|
|
38
|
+
src/inference/text.py,sha256=iB7BNQRRrEUkgeBoeL55LrtntGKS8GSnlr1MAW76Ry4,1877
|
|
39
|
+
src/initializers/Constant.py,sha256=_vIqP40_-CELGYlLRIETvO4peRH_XxPmB3M8A731u3Q,186
|
|
40
|
+
src/initializers/GlorotNormal.py,sha256=fdcKXnQYRq2TGFhgomAS6XVjBLxeRe66vQJ2GYleMAE,265
|
|
41
|
+
src/initializers/GlorotUniform.py,sha256=cgRvXpX6p6ay71JkY3S29FyAwDXQqQGDZ_-qELvNzcU,767
|
|
42
|
+
src/initializers/HeNormal.py,sha256=JKN5qTMcVkh_MqznUkA_G1jbkFa5p6QE6TB-wtOLDAw,243
|
|
43
|
+
src/initializers/HeUniform.py,sha256=QSqxROf_PizFhUps4jwaNOoVyEvBD2Zux7ZFck_1miI,320
|
|
44
|
+
src/initializers/Initializer.py,sha256=-BNYQaksqWjlEiz5QJKTQ11JG5Wkya_hiop3iowA6PU,84
|
|
45
|
+
src/initializers/LecunNormal.py,sha256=NtUKqMhqe7M-5IMJMQ_wl-UmiJGHxyrJ3ZB5zAEGbBo,247
|
|
46
|
+
src/initializers/LecunUniform.py,sha256=eTqeRMoW-WazmlR5oa-EkzUTDJJgb9hwsjA8hj9p3uI,323
|
|
47
|
+
src/initializers/Ones.py,sha256=_kViopeLVrYEw1R-XcwMeNd3CfvZH3SSUDnkeUFaDFg,111
|
|
48
|
+
src/initializers/Orthogonal.py,sha256=24OYxuwJO_cj6jarSjlOldaOEVb7PM6aG0bYgqDKWWA,208
|
|
49
|
+
src/initializers/RandomNormal.py,sha256=urxvesOUZ3GElpPpNnPUPP0oCK79qDVTF3Lb89oymZM,302
|
|
50
|
+
src/initializers/RandomUniform.py,sha256=_90_kBzrn9HDmolktOFxRoscWkcHYU6XRjM1Gsu1OlQ,294
|
|
51
|
+
src/initializers/Zeros.py,sha256=LdblqwgvijYw2Rd0vy7MNtYA_jb4Qc5q-dypLgBAVM0,180
|
|
52
|
+
src/initializers/__init__.py,sha256=2SHBsYIFetXTol9pLfzTiYGFZVJQXiWR-EulzOOj64Y,476
|
|
53
|
+
src/loss/CategoricalCrossEntropy.py,sha256=WSIELbAfaqM4M8jRRaeR-DXCEQrCCSTNkROLn_FLya8,205
|
|
54
|
+
src/loss/CrossEntropyLoss.py,sha256=u7kVDxwhrXcvKrsxlDzz3RM8AooSuHQZKlZPy584boI,622
|
|
55
|
+
src/loss/CrossEntropyWithLogitsLoss.py,sha256=cDT7TOieiCuoOWJHcp-RzBS5N8c_FOgt48H9I9kqubA,1152
|
|
56
|
+
src/loss/Hinge.py,sha256=oKzCsfcYr6qPVLB1J94hX-MJbDwU3AZ1IRjSwqR1gAI,117
|
|
57
|
+
src/loss/Huber.py,sha256=KoyTP8oqJtL1tVELG31StghWCwEj-lwlT_JmO1iDsy8,444
|
|
58
|
+
src/loss/Loss.py,sha256=Hwm2MHDZF3dGHKx27Ycz6ajmflFg4O8e62I9oyqemJ8,155
|
|
59
|
+
src/loss/MSE.py,sha256=Dj5M0RDpi8PKJ1KVczZ6ZS26tFDvIqLDbG4uuDscWHs,128
|
|
60
|
+
src/loss/MSELoss.py,sha256=EorNihrllTCPIEAqTPBA0Y5-XhmwoBbFyObDHs6auk4,229
|
|
61
|
+
src/loss/SparseCategoricalCrossEntropy.py,sha256=kDPk8fPfmVYmbhAfXhOuAyLbUTZrkLgonALyqrIv9DQ,284
|
|
62
|
+
src/loss/__init__.py,sha256=mu7eWxqmcwScwuiUGQZ5izM4Kp__WtnMWkbyuGH7VD4,708
|
|
63
|
+
src/loss/bce.py,sha256=fMHXG4rMhH9TK0Jp1XeqVJyDFvDIXGYHaD7A0J3p-YI,733
|
|
64
|
+
src/loss/mae.py,sha256=lox0XXvK2rjviATXhXDNXcuj92_GRlePbIRpP3-jKL8,340
|
|
65
|
+
src/math/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
66
|
+
src/math/clip.py,sha256=3qnqIJljFXvCpqms971UvP1fxsz-dc5zy8WhPCM8XDo,748
|
|
67
|
+
src/math/exp.py,sha256=bfzxSyHDg1UhWQ88w_vMStEC-VIimbtYNWLDw267fmY,426
|
|
68
|
+
src/math/log.py,sha256=0FfvD6j1M5EvAe9b8bkF37tgkMjvcbXZuOhMDOp5onM,416
|
|
69
|
+
src/math/sigmoid.py,sha256=-45QD8qMbhZUfwPxjZmEekzuX91t3KC6d9UXIOMv4cY,69
|
|
70
|
+
src/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
71
|
+
src/models/embedding/Embedding.py,sha256=0ntF7n2oXVg5hdz5i9I08bpTN6PJ7uTgulpTj-IPkro,1282
|
|
72
|
+
src/models/embedding/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
73
|
+
src/models/gpt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
74
|
+
src/models/gpt/attention.py,sha256=zWyzu6TTcrmDfWSJCSpYSimlqtGxUDPVFshOKjBt7GQ,4194
|
|
75
|
+
src/models/gpt/block.py,sha256=e2hlIC8X-8P06Xha628nGj0D6dH0tV8xiMeovbpvYCU,2305
|
|
76
|
+
src/models/gpt/config.py,sha256=tJ36n8m8929yb_EvnFeKVoWT7kB5zsT5711KpvQejio,3430
|
|
77
|
+
src/models/gpt/context.py,sha256=CcmJPDwxqcfWtKx_-L0T4GiaN9jvaodKbuXwpL4Js7Q,1526
|
|
78
|
+
src/models/gpt/model.py,sha256=CLw6qTrhttnFafaYg1tKCPilegdLfvu2sO51TNe5Lm8,4788
|
|
79
|
+
src/models/gpt/recompute.py,sha256=VIQ4BeviOuWF5lB6YHWu90PlxE7CVMBCP4neiSAFcnI,774
|
|
80
|
+
src/models/gpt/rope.py,sha256=ey3DsJGw4ZU1zmkD1mtfwf20SiNDoz_Iuc593NyZEAY,2555
|
|
81
|
+
src/models/regression/Linear.py,sha256=JDLXkvw7ozBTujY4C69p1RoCsKjEpv_GNI-oAMuUK-I,1293
|
|
82
|
+
src/models/regression/Logistic.py,sha256=IKtpLDvUdJqyHeaiZiH-9ZG5doJ_F1fk8D2wYAa9FxY,910
|
|
83
|
+
src/models/regression/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
84
|
+
src/models/seq/Sequential.py,sha256=ZyA7WzMPjU0wbK5-kRHN9BTD5od2l4ZTJum6ST9WfQQ,7218
|
|
85
|
+
src/models/seq/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
86
|
+
src/models/svm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
87
|
+
src/models/tokenizer/BPETokenizer.py,sha256=fZUmTZ4r6ZR8c-OXTF7wsjzSh-TurbSA9_wS2EuJJyo,4081
|
|
88
|
+
src/models/tokenizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
89
|
+
src/models/transformers/Dropout.py,sha256=1nCTQ9w2DHZ5zypxIT489aYi_0TTTC0ySczhRrBLvJ4,627
|
|
90
|
+
src/models/transformers/LastToken.py,sha256=8eWkLho2JfJyII5K0MWk-Uy0sTVeyfCgnXAKt8SAf-0,159
|
|
91
|
+
src/models/transformers/LayerNorm.py,sha256=6rkCNncEmPvcc6PIpSrZFawbts0PqnZXC8_KVUOEPPc,1410
|
|
92
|
+
src/models/transformers/Linear.py,sha256=PVTVOXBAE2d5MnVi6qN6cSrY602sZV2YJhC-3RwY-4I,325
|
|
93
|
+
src/models/transformers/MultiHeadAttention.py,sha256=Oe_HqyLwiiEgXl4ZxRBG6c-ej9UrB8W3RHYW3wc1_m4,2948
|
|
94
|
+
src/models/transformers/TransformerBlock.py,sha256=0QJfKB8aXhNrkAnwSiiDmzrZhMaLIggh8kZqbJ-8uKI,2137
|
|
95
|
+
src/models/transformers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
96
|
+
src/neural/Dense.py,sha256=TY1U_XB5kTmLaf7eJ5wcwENfWpwLOCX2F8AAgu1mWBY,1635
|
|
97
|
+
src/neural/LSTM.py,sha256=i56OsH65gHOLM63QU8UAE5LWdxJIgYdhWkKSaAOW8jY,3829
|
|
98
|
+
src/neural/Layer.py,sha256=mq18zU7R1idQD7TdKAjVBp69f9rTfyF8JEsay_uX6kQ,1563
|
|
99
|
+
src/neural/Parameter.py,sha256=InZ8a4xlOJVJN7TvywcnlZLeDri93uu8yotptGF1UjA,666
|
|
100
|
+
src/neural/RNN.py,sha256=G6zZhwrdpxzDY7RdkS0YiEdtEt4910HH3C9N8ZE0FZ4,1777
|
|
101
|
+
src/neural/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
102
|
+
src/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
103
|
+
src/ops/stack.py,sha256=mst87o6DP-Q1OTiyhYVyPE0u2MKgtXWv3c8-rH2RhEM,782
|
|
104
|
+
src/optimizers/Adagrad.py,sha256=56x-TkRGQ80J9NxRy9jTGxRnU9b9411vS6uO7pJAgzc,640
|
|
105
|
+
src/optimizers/Adam.py,sha256=OtSzZaMn-sTS8HwIR34xDjWMCZKoh0Ov57f870c5NTk,2297
|
|
106
|
+
src/optimizers/AdamW.py,sha256=v4NYJ6VQO9ezK8knMqmtAGp1be0rsD4s_7UwPV0p0-A,2112
|
|
107
|
+
src/optimizers/Batch.py,sha256=OGq78eoTkA2DfliwcvF5Fgc6LxZw1NXqCv-l40tTf-8,238
|
|
108
|
+
src/optimizers/Nesterov.py,sha256=cpVc1Gqn1c8RtDDCxXw7wxpiXDkYhhvP1jmqY5cCNBE,802
|
|
109
|
+
src/optimizers/Optimizer.py,sha256=KVCFneLdNiHb5BD1J4zdVA105roQxHVKmeCWV60o6gQ,475
|
|
110
|
+
src/optimizers/RMSProp.py,sha256=dU26xVf7F5-ENFJt2GfN6WM7s-ETYpThQC5zEgK0uOo,775
|
|
111
|
+
src/optimizers/SGD.py,sha256=dwSmXPeBR40PUbaOIOy_naK7VbL2rLxHLWHrPuGF83w,760
|
|
112
|
+
src/optimizers/SGDMomentum.py,sha256=b9MsuC1c1xwxU8dDD8lgA6e4Fjlm6USUIl_RL0cOXwk,594
|
|
113
|
+
src/optimizers/__init__.py,sha256=-_Mh-5WwPqzPGtVhQXzn4viiWeAx51y6j49ooNBzHhw,159
|
|
114
|
+
src/scaling/StandardScaler.py,sha256=kwXpvc_LNYvMYnm0x18VrEXeIWfTGkJ8KEcWBbdbIRM,335
|
|
115
|
+
src/scaling/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
116
|
+
src/serialization/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
117
|
+
src/serialization/checkpoint.py,sha256=CGIh6rA5_tXobnPlDwP8-Nof6qwvklj-LDQox479vls,1021
|
|
118
|
+
src/serialization/modelio.py,sha256=cvAtZOO3xK3I3w_ecvJtBz-F85lchbi2EIcwt5Y25xs,2298
|
|
119
|
+
src/serving/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
120
|
+
src/serving/app.py,sha256=fk1qBNEGMm-L--RaPK0K8T_SBXMWYYJlr8KTYMzu2mg,27919
|
|
121
|
+
src/serving/config.py,sha256=rBI6wmCfC7G1faZX4tM9UYiqm3XinyUev8RSDXleWu4,6781
|
|
122
|
+
src/serving/errors.py,sha256=i6jAmyPGMowp6KsBml060DriQn8ktY1uFytF6ljfkGs,1800
|
|
123
|
+
src/serving/http.py,sha256=GaJcC25GzxjxxWWEjaZ6r-APRwLfKfHTohZn3gOd-vc,18557
|
|
124
|
+
src/serving/metrics.py,sha256=czKMn7IDiylOL9RMERmQ1tJDrwo2JKRcA8JYiDVw-LY,10891
|
|
125
|
+
src/serving/model_server.py,sha256=PvAykqVOy6Kg_0A1YlMya2_CgGxuZeDpMvsJsVvaZO4,9195
|
|
126
|
+
src/serving/protocol.py,sha256=E70JnNhCzUL9RIEDoAKtUVI9Nxyc5rYc4HxPtu9XKXU,12029
|
|
127
|
+
src/serving/security.py,sha256=eI7B9hc5Kv6BQeztLl-T84ICne5CQirD0WSpCerC2QM,5417
|
|
128
|
+
src/serving/server.py,sha256=B99pSShkHjKwTtyvHNW7OT2KKlzwC9P4-I-g71_plew,4059
|
|
129
|
+
src/tokenization/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
130
|
+
src/tokenization/base.py,sha256=yYRljT8vESIqzXhs-M3prS680_a2Ch3hI2eFW8lwHB8,1699
|
|
131
|
+
src/tokenization/bpe.py,sha256=9Vjq4G-ApxMzeQCDCxCG7BYNOLIBp2fEEGJNOJQQ2H4,5435
|
|
132
|
+
src/tokenization/bytebpe.py,sha256=kpsvTK0wAGt8Ml2NzN_HTmtxWg4_Grhh456PD9BzNs0,12713
|
|
133
|
+
src/tokenization/registry.py,sha256=_qR0ILFeCtloEi1aAXtaMBvuAA7uecpXwqRZ_5Js4as,603
|
|
134
|
+
src/training/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
135
|
+
src/training/checkpoint_manager.py,sha256=vO0fVe6hTnxC84erQSZDHZ0HJvsJlwcT6vH4PdkEA3A,2827
|
|
136
|
+
src/training/experiment.py,sha256=FcG0el_2sYvL5tp2LBRXqLrusIg9KcZnBOYkeLTM0w8,1923
|
|
137
|
+
src/training/losses.py,sha256=-JABRvkn-AWfTljGWHaXcYOHO3oxaV68hjrZqneIhbg,1346
|
|
138
|
+
src/training/precision.py,sha256=A_7069FCGSlyj_J0Lr_tLCQquN1KNlYp-EnO0__Y_6c,4246
|
|
139
|
+
src/training/profiler.py,sha256=xJIUr4RMHfGj8LutYIySv_0u6uLQk--nuYzLZrykveA,919
|
|
140
|
+
src/training/scheduler.py,sha256=IHtqfeMXFGjriqa7hABFTj9krmeoFEatd92MhF8xEVY,1409
|
|
141
|
+
src/training/trainer.py,sha256=240L0zXy4OFJA02ifuPAc-jSTklL66gOBT7Cb9LKBfc,21091
|
|
142
|
+
pytensorforge-0.1.0.dist-info/METADATA,sha256=7EJC8VgNiGTj205NbaoodzBdsv823bbWmxqwMEr_C5c,4412
|
|
143
|
+
pytensorforge-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
144
|
+
pytensorforge-0.1.0.dist-info/entry_points.txt,sha256=xu-_dU6lBAUNmGEUWjVdM2E9upSAmT95eveWyhqy0-k,43
|
|
145
|
+
pytensorforge-0.1.0.dist-info/top_level.txt,sha256=cnbTmgy-9dPa7KK2pqKBQREjocvF6Y8MB_dF_HvtmP0,8
|
|
146
|
+
pytensorforge-0.1.0.dist-info/RECORD,,
|
src/__init__.py
ADDED
|
File without changes
|
src/activations/ELU.py
ADDED
src/activations/GELU.py
ADDED
src/activations/ReLU.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from src.activations.Activation import Activation
|
|
4
|
+
from src.core.Tensor import Tensor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ReLU(Activation):
|
|
8
|
+
|
|
9
|
+
@staticmethod
|
|
10
|
+
def forward(x):
|
|
11
|
+
out = Tensor(
|
|
12
|
+
np.maximum(0, x.data),
|
|
13
|
+
requires_grad=x.requires_grad,
|
|
14
|
+
parents=(x,),
|
|
15
|
+
op="ReLU",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def backward():
|
|
19
|
+
if x.requires_grad:
|
|
20
|
+
x.grad += out.grad * (x.data > 0)
|
|
21
|
+
|
|
22
|
+
out._backward = backward
|
|
23
|
+
|
|
24
|
+
return out
|
|
25
|
+
|
|
26
|
+
def __call__(self, x):
|
|
27
|
+
return x.relu()
|
src/activations/SELU.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from src.activations.Activation import Activation
|
|
4
|
+
|
|
5
|
+
class SELU(Activation):
|
|
6
|
+
SCALE = 1.0507009873554805
|
|
7
|
+
ALPHA = 1.6732632423543772
|
|
8
|
+
|
|
9
|
+
def __call__(self, x):
|
|
10
|
+
return self.SCALE * np.where(
|
|
11
|
+
x > 0,
|
|
12
|
+
x,
|
|
13
|
+
self.ALPHA * (np.exp(x) - 1),
|
|
14
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from src.activations.Activation import Activation
|
|
2
|
+
from src.core.Tensor import Tensor
|
|
3
|
+
from src.math.sigmoid import sigmoid
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Sigmoid(Activation):
|
|
7
|
+
@staticmethod
|
|
8
|
+
def forward(x):
|
|
9
|
+
sig = sigmoid(x.data)
|
|
10
|
+
|
|
11
|
+
out = Tensor(
|
|
12
|
+
sig,
|
|
13
|
+
requires_grad=x.requires_grad,
|
|
14
|
+
parents=(x,),
|
|
15
|
+
op="Sigmoid",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def _backward():
|
|
19
|
+
if x.requires_grad:
|
|
20
|
+
x.grad += out.grad * sig * (1 - sig)
|
|
21
|
+
|
|
22
|
+
out._backward = _backward
|
|
23
|
+
|
|
24
|
+
return out
|
|
25
|
+
|
|
26
|
+
def __call__(self, x):
|
|
27
|
+
return x.sigmoid()
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from src.core.Tensor import Tensor
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# class Softmax:
|
|
7
|
+
#
|
|
8
|
+
# @staticmethod
|
|
9
|
+
# def forward(x):
|
|
10
|
+
#
|
|
11
|
+
# shifted = x.data - np.max(x.data, axis=-1, keepdims=True)
|
|
12
|
+
#
|
|
13
|
+
# exp = np.exp(shifted)
|
|
14
|
+
#
|
|
15
|
+
# probs = exp / np.sum(exp, axis=-1, keepdims=True)
|
|
16
|
+
#
|
|
17
|
+
# out = Tensor(
|
|
18
|
+
# probs,
|
|
19
|
+
# requires_grad=x.requires_grad,
|
|
20
|
+
# parents=(x,),
|
|
21
|
+
# op="Softmax",
|
|
22
|
+
# )
|
|
23
|
+
#
|
|
24
|
+
# def _backward():
|
|
25
|
+
#
|
|
26
|
+
# if not x.requires_grad:
|
|
27
|
+
# return
|
|
28
|
+
#
|
|
29
|
+
# grad = np.empty_like(probs)
|
|
30
|
+
#
|
|
31
|
+
# for i in range(len(probs)):
|
|
32
|
+
# p = probs[i].reshape(-1, 1)
|
|
33
|
+
#
|
|
34
|
+
# jacobian = np.diagflat(p) - p @ p.T
|
|
35
|
+
#
|
|
36
|
+
# grad[i] = jacobian @ out.grad[i]
|
|
37
|
+
#
|
|
38
|
+
# x.grad += grad
|
|
39
|
+
#
|
|
40
|
+
# out._backward = _backward
|
|
41
|
+
#
|
|
42
|
+
# return out
|
|
43
|
+
#
|
|
44
|
+
# def __call__(self, x):
|
|
45
|
+
# return self.forward(x)
|
|
46
|
+
|
|
47
|
+
from src.activations.Activation import Activation
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Softmax(Activation):
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def forward(x, axis=-1):
|
|
54
|
+
|
|
55
|
+
shifted = x.data - np.max(x.data, axis=axis, keepdims=True)
|
|
56
|
+
|
|
57
|
+
exp = np.exp(shifted)
|
|
58
|
+
|
|
59
|
+
probs = exp / np.sum(exp, axis=axis, keepdims=True)
|
|
60
|
+
|
|
61
|
+
out = Tensor(
|
|
62
|
+
probs,
|
|
63
|
+
requires_grad=x.requires_grad,
|
|
64
|
+
parents=(x,),
|
|
65
|
+
op="Softmax",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def _backward():
|
|
69
|
+
|
|
70
|
+
if not x.requires_grad:
|
|
71
|
+
return
|
|
72
|
+
|
|
73
|
+
grad = out.grad
|
|
74
|
+
|
|
75
|
+
dot = np.sum(grad * probs, axis=axis, keepdims=True)
|
|
76
|
+
|
|
77
|
+
x.grad += probs * (grad - dot)
|
|
78
|
+
|
|
79
|
+
out._backward = _backward
|
|
80
|
+
|
|
81
|
+
return out
|
|
82
|
+
|
|
83
|
+
def __call__(self, x):
|
|
84
|
+
return Softmax.forward(x)
|
src/activations/Tanh.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from src.activations.Activation import Activation
|
|
4
|
+
from src.core.Tensor import Tensor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Tanh(Activation):
|
|
8
|
+
|
|
9
|
+
@staticmethod
|
|
10
|
+
def forward(x):
|
|
11
|
+
t = np.tanh(x.data)
|
|
12
|
+
|
|
13
|
+
out = Tensor(
|
|
14
|
+
t,
|
|
15
|
+
requires_grad=x.requires_grad,
|
|
16
|
+
parents=(x,),
|
|
17
|
+
op="Tanh",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
def _backward():
|
|
21
|
+
if x.requires_grad:
|
|
22
|
+
x.grad += out.grad * (1 - t * t)
|
|
23
|
+
|
|
24
|
+
out._backward = _backward
|
|
25
|
+
|
|
26
|
+
return out
|
|
27
|
+
|
|
28
|
+
def __call__(self, x):
|
|
29
|
+
return x.tanh()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .ELU import ELU
|
|
2
|
+
from .GELU import GELU
|
|
3
|
+
from .ReLU import ReLU
|
|
4
|
+
from .SELU import SELU
|
|
5
|
+
from .Sigmoid import Sigmoid
|
|
6
|
+
from .Tanh import Tanh
|
|
7
|
+
from .Softmax import Softmax
|
|
8
|
+
|
|
9
|
+
activation_fns = {
|
|
10
|
+
"relu": ReLU(),
|
|
11
|
+
"tanh": Tanh(),
|
|
12
|
+
"sigmoid": Sigmoid(),
|
|
13
|
+
"elu": ELU(),
|
|
14
|
+
"selu": SELU(),
|
|
15
|
+
"softmax": Softmax(),
|
|
16
|
+
"gelu": GELU(),
|
|
17
|
+
}
|
src/config.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from dataclasses import asdict, dataclass, field
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
|
|
4
|
+
import yaml
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class ModelSpec:
|
|
9
|
+
vocab_size: int
|
|
10
|
+
context_length: int = 1024
|
|
11
|
+
d_model: int = 768
|
|
12
|
+
n_layers: int = 12
|
|
13
|
+
n_heads: int = 12
|
|
14
|
+
ff_dim: int = 3072
|
|
15
|
+
activation: str = "gelu"
|
|
16
|
+
dropout: float = 0.0
|
|
17
|
+
norm_eps: float = 1e-5
|
|
18
|
+
tie_weights: bool = True
|
|
19
|
+
position_encoding: str = "learned"
|
|
20
|
+
rope_theta: float = 10000.0
|
|
21
|
+
rope_scaling: str = "none"
|
|
22
|
+
rope_scaling_factor: float = 1.0
|
|
23
|
+
trained_context_length: Optional[int] = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class DataSpec:
|
|
28
|
+
train: List[str] = field(default_factory=list)
|
|
29
|
+
validation: Optional[List[str]] = None
|
|
30
|
+
tokenizer: str = "tokenizer.json"
|
|
31
|
+
sequence_length: int = 1024
|
|
32
|
+
read_buffer_size: int = 1 << 20
|
|
33
|
+
insert_eos: bool = True
|
|
34
|
+
text_field: str = "text"
|
|
35
|
+
workers: int = 1
|
|
36
|
+
prefetch: int = 4
|
|
37
|
+
shuffle_files: bool = False
|
|
38
|
+
val_split_fraction: Optional[float] = None
|
|
39
|
+
format: str = "text"
|
|
40
|
+
chat_template: str = "plain"
|
|
41
|
+
chat_packing: str = "pack"
|
|
42
|
+
messages_field: str = "messages"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class TrainingSpec:
|
|
47
|
+
max_tokens: Optional[int] = None
|
|
48
|
+
max_epochs: Optional[int] = None
|
|
49
|
+
total_steps: Optional[int] = None
|
|
50
|
+
micro_batch_size: int = 8
|
|
51
|
+
gradient_accumulation_steps: int = 1
|
|
52
|
+
learning_rate: float = 3e-4
|
|
53
|
+
weight_decay: float = 0.01
|
|
54
|
+
warmup_steps: int = 0
|
|
55
|
+
decay: str = "cosine"
|
|
56
|
+
min_lr: float = 0.0
|
|
57
|
+
gradient_clip: float = 1.0
|
|
58
|
+
precision: str = "fp32"
|
|
59
|
+
loss_scaling: str = "auto"
|
|
60
|
+
initial_loss_scale: float = 65536.0
|
|
61
|
+
loss_scale_growth_interval: int = 2000
|
|
62
|
+
activation_checkpointing: bool = False
|
|
63
|
+
init_from: Optional[str] = None
|
|
64
|
+
seed: int = 1337
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class CheckpointSpec:
|
|
69
|
+
directory: str = "checkpoints"
|
|
70
|
+
interval_steps: int = 500
|
|
71
|
+
keep_last: int = 3
|
|
72
|
+
keep_every: Optional[int] = None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dataclass
|
|
76
|
+
class EvaluationSpec:
|
|
77
|
+
interval_steps: int = 500
|
|
78
|
+
interval_tokens: Optional[int] = None
|
|
79
|
+
max_batches: int = 50
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass
|
|
83
|
+
class RuntimeSpec:
|
|
84
|
+
device: str = "cpu"
|
|
85
|
+
seed: int = 1337
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass
|
|
89
|
+
class TrainConfig:
|
|
90
|
+
model: ModelSpec
|
|
91
|
+
data: DataSpec
|
|
92
|
+
training: TrainingSpec
|
|
93
|
+
checkpoint: CheckpointSpec
|
|
94
|
+
evaluation: EvaluationSpec
|
|
95
|
+
runtime: RuntimeSpec
|
|
96
|
+
|
|
97
|
+
def to_dict(self):
|
|
98
|
+
return asdict(self)
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def from_dict(cls, raw):
|
|
102
|
+
return cls(
|
|
103
|
+
model=ModelSpec(**raw.get("model", {})),
|
|
104
|
+
data=DataSpec(**raw.get("data", {})),
|
|
105
|
+
training=TrainingSpec(**raw.get("training", {})),
|
|
106
|
+
checkpoint=CheckpointSpec(**raw.get("checkpoint", {})),
|
|
107
|
+
evaluation=EvaluationSpec(**raw.get("evaluation", {})),
|
|
108
|
+
runtime=RuntimeSpec(**raw.get("runtime", {})),
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
@classmethod
|
|
112
|
+
def load(cls, path):
|
|
113
|
+
with open(path) as f:
|
|
114
|
+
raw = yaml.safe_load(f)
|
|
115
|
+
|
|
116
|
+
return cls.from_dict(raw)
|
|
117
|
+
|
|
118
|
+
def save(self, path):
|
|
119
|
+
with open(path, "w") as f:
|
|
120
|
+
yaml.safe_dump(self.to_dict(), f, sort_keys=False)
|
src/core/Matrix.py
ADDED
src/core/Scalar.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Scalar:
|
|
2
|
+
def __init__(self):
|
|
3
|
+
self.data = None
|
|
4
|
+
|
|
5
|
+
def log(self):
|
|
6
|
+
print(self.data)
|
|
7
|
+
|
|
8
|
+
def one(self):
|
|
9
|
+
self.data = 1
|
|
10
|
+
return self
|
|
11
|
+
|
|
12
|
+
def zero(self):
|
|
13
|
+
self.data = 0
|
|
14
|
+
return self
|
|
15
|
+
|
|
16
|
+
def add(self, other):
|
|
17
|
+
self.data = self.data + other.data
|
|
18
|
+
return self
|