neuroforge-dl 0.2.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.
- neuroforge_dl-0.2.0/LICENSE +21 -0
- neuroforge_dl-0.2.0/PKG-INFO +182 -0
- neuroforge_dl-0.2.0/README.md +145 -0
- neuroforge_dl-0.2.0/pyproject.toml +81 -0
- neuroforge_dl-0.2.0/setup.cfg +4 -0
- neuroforge_dl-0.2.0/src/neuroforge/__init__.py +183 -0
- neuroforge_dl-0.2.0/src/neuroforge/core/__init__.py +29 -0
- neuroforge_dl-0.2.0/src/neuroforge/core/autograd.py +41 -0
- neuroforge_dl-0.2.0/src/neuroforge/core/exceptions.py +35 -0
- neuroforge_dl-0.2.0/src/neuroforge/core/tensor.py +481 -0
- neuroforge_dl-0.2.0/src/neuroforge/data/__init__.py +15 -0
- neuroforge_dl-0.2.0/src/neuroforge/data/dataloader.py +47 -0
- neuroforge_dl-0.2.0/src/neuroforge/data/dataset.py +29 -0
- neuroforge_dl-0.2.0/src/neuroforge/data/transforms.py +52 -0
- neuroforge_dl-0.2.0/src/neuroforge/experiments/__init__.py +5 -0
- neuroforge_dl-0.2.0/src/neuroforge/experiments/tracker.py +49 -0
- neuroforge_dl-0.2.0/src/neuroforge/inference/__init__.py +5 -0
- neuroforge_dl-0.2.0/src/neuroforge/inference/engine.py +75 -0
- neuroforge_dl-0.2.0/src/neuroforge/losses/__init__.py +14 -0
- neuroforge_dl-0.2.0/src/neuroforge/losses/bce.py +62 -0
- neuroforge_dl-0.2.0/src/neuroforge/losses/cross_entropy.py +66 -0
- neuroforge_dl-0.2.0/src/neuroforge/losses/loss.py +21 -0
- neuroforge_dl-0.2.0/src/neuroforge/losses/mse.py +13 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/__init__.py +30 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/bert.py +76 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/cnn.py +73 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/mlp.py +45 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/multimodal.py +57 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/resnet.py +115 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/rnn.py +46 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/transformer.py +124 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/unet.py +103 -0
- neuroforge_dl-0.2.0/src/neuroforge/models/vae.py +115 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/__init__.py +7 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/__init__.py +85 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/activations.py +54 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/attention.py +131 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/conv.py +428 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/dropout.py +31 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/embedding.py +56 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/linear.py +40 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/normalization.py +165 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/recurrent.py +193 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/layers/transformer.py +159 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/module.py +104 -0
- neuroforge_dl-0.2.0/src/neuroforge/nn/parameter.py +15 -0
- neuroforge_dl-0.2.0/src/neuroforge/optim/__init__.py +27 -0
- neuroforge_dl-0.2.0/src/neuroforge/optim/adam.py +56 -0
- neuroforge_dl-0.2.0/src/neuroforge/optim/adamw.py +57 -0
- neuroforge_dl-0.2.0/src/neuroforge/optim/lr_scheduler.py +120 -0
- neuroforge_dl-0.2.0/src/neuroforge/optim/optimizer.py +22 -0
- neuroforge_dl-0.2.0/src/neuroforge/optim/sgd.py +38 -0
- neuroforge_dl-0.2.0/src/neuroforge/registry/__init__.py +5 -0
- neuroforge_dl-0.2.0/src/neuroforge/registry/model_registry.py +67 -0
- neuroforge_dl-0.2.0/src/neuroforge/serving/__init__.py +5 -0
- neuroforge_dl-0.2.0/src/neuroforge/serving/app.py +146 -0
- neuroforge_dl-0.2.0/src/neuroforge/serving/schemas.py +47 -0
- neuroforge_dl-0.2.0/src/neuroforge/training/__init__.py +15 -0
- neuroforge_dl-0.2.0/src/neuroforge/training/callbacks.py +95 -0
- neuroforge_dl-0.2.0/src/neuroforge/training/metrics.py +47 -0
- neuroforge_dl-0.2.0/src/neuroforge/training/trainer.py +127 -0
- neuroforge_dl-0.2.0/src/neuroforge/utils/__init__.py +36 -0
- neuroforge_dl-0.2.0/src/neuroforge/utils/grad_utils.py +162 -0
- neuroforge_dl-0.2.0/src/neuroforge/utils/init.py +105 -0
- neuroforge_dl-0.2.0/src/neuroforge/utils/random.py +10 -0
- neuroforge_dl-0.2.0/src/neuroforge/utils/visualization.py +86 -0
- neuroforge_dl-0.2.0/src/neuroforge_dl.egg-info/PKG-INFO +182 -0
- neuroforge_dl-0.2.0/src/neuroforge_dl.egg-info/SOURCES.txt +70 -0
- neuroforge_dl-0.2.0/src/neuroforge_dl.egg-info/dependency_links.txt +1 -0
- neuroforge_dl-0.2.0/src/neuroforge_dl.egg-info/entry_points.txt +3 -0
- neuroforge_dl-0.2.0/src/neuroforge_dl.egg-info/requires.txt +13 -0
- neuroforge_dl-0.2.0/src/neuroforge_dl.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NeuroForge 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,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neuroforge-dl
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A full-featured deep learning framework and production AI platform built from first principles in Python & NumPy.
|
|
5
|
+
Author-email: NeuroForge Contributors <neuroforge@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/username/neuroforge
|
|
8
|
+
Project-URL: Documentation, https://github.com/username/neuroforge#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/username/neuroforge.git
|
|
10
|
+
Project-URL: Issues, https://github.com/username/neuroforge/issues
|
|
11
|
+
Keywords: deep-learning,autograd,neural-networks,transformers,gpt,vision-transformer,resnet,unet,bert,vae,fastapi-serving
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
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.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.26.0
|
|
25
|
+
Requires-Dist: pyyaml>=6.0
|
|
26
|
+
Requires-Dist: pydantic>=2.0
|
|
27
|
+
Requires-Dist: fastapi>=0.110.0
|
|
28
|
+
Requires-Dist: uvicorn[standard]>=0.28.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy>=1.10.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mkdocs>=1.5.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mkdocs-material>=9.5.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# NeuroForge 🧠⚡
|
|
39
|
+
|
|
40
|
+
> A full-featured deep learning framework and production AI platform — built entirely from first principles in Python/NumPy.
|
|
41
|
+
|
|
42
|
+
[](https://www.python.org/)
|
|
43
|
+
[](#testing)
|
|
44
|
+
[](LICENSE)
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## What is NeuroForge?
|
|
49
|
+
|
|
50
|
+
NeuroForge is a **complete, production-ready deep learning stack** implemented from scratch — no PyTorch, no TensorFlow, no Keras. Every component, from the tensor engine to the FastAPI model-serving layer, is hand-crafted:
|
|
51
|
+
|
|
52
|
+
| Layer | What's included |
|
|
53
|
+
|---|---|
|
|
54
|
+
| 🔢 **Tensor Engine** | NumPy-backed N-D arrays, dynamic autograd computation graph, full reverse-mode AD |
|
|
55
|
+
| 🧱 **Neural Modules** | Linear, Conv1D, Conv2D, ConvTranspose2D, MaxPool, AvgPool, RNN, LSTM, GRU, Attention, Transformer, Embedding, LayerNorm, BatchNorm, Dropout |
|
|
56
|
+
| 🏗️ **Model Zoo** | MLP, ConvNet, ResNet (ResNet18/34), U-Net, BERT, VAE, GPT, VisionTransformer, VisionLanguageModel |
|
|
57
|
+
| 📉 **Losses** | CrossEntropy, BCE, BCEWithLogits, MSE, VAE Loss (BCE + KL) |
|
|
58
|
+
| ⚙️ **Optimizers & Schedulers** | SGD (+ momentum), Adam, AdamW, StepLR, CosineAnnealingLR, WarmupCosineScheduler, WarmupLinearScheduler, ExponentialLR |
|
|
59
|
+
| 🛠️ **Training & Utilities** | Trainer, Gradient Clipping (norm & value), Numerical Gradient Checker, Weight Initialization (Xavier, Kaiming, Orthogonal), Callbacks |
|
|
60
|
+
| 📊 **Experiments & Visuals** | ExperimentTracker, Plot Training History, Gradient Norm Inspection |
|
|
61
|
+
| 📦 **Registry & Serving** | ModelRegistry (versioned save/load) + FastAPI REST server (`/health`, `/models`, `/predict`, `/generate`, `/metrics`) |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Architecture
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
69
|
+
│ NeuroForge Stack │
|
|
70
|
+
├───────────────────────────────────────────────────────────────────┤
|
|
71
|
+
│ neuroforge.core │ Tensor + Autograd Engine │
|
|
72
|
+
│ neuroforge.nn │ Module, Parameter, 16 Layer Types │
|
|
73
|
+
│ neuroforge.models │ MLP, ConvNet, ResNet, UNet, BERT, VAE... │
|
|
74
|
+
│ neuroforge.losses │ CrossEntropy, BCE, MSE, VAE Loss │
|
|
75
|
+
│ neuroforge.optim │ SGD, Adam, AdamW, Warmup Schedulers │
|
|
76
|
+
│ neuroforge.data │ TensorDataset, DataLoader │
|
|
77
|
+
│ neuroforge.training │ Trainer, Callbacks, Metrics │
|
|
78
|
+
│ neuroforge.utils │ Init, Grad Clipping, Grad Check, Plots │
|
|
79
|
+
│ neuroforge.experiments│ ExperimentTracker │
|
|
80
|
+
│ neuroforge.registry │ ModelRegistry (versioned persistence) │
|
|
81
|
+
│ neuroforge.inference │ InferenceEngine │
|
|
82
|
+
│ neuroforge.serving │ FastAPI production REST server │
|
|
83
|
+
└───────────────────────────────────────────────────────────────────┘
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
### Installation
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
cd NeuroForge
|
|
94
|
+
pip install -e .
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Train a ConvNet in 5 lines
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import numpy as np
|
|
101
|
+
from neuroforge import ConvNet, CrossEntropyLoss, Adam, TensorDataset, DataLoader, Trainer
|
|
102
|
+
|
|
103
|
+
X = np.random.randn(200, 1, 28, 28).astype("float32")
|
|
104
|
+
y = np.random.randint(0, 10, size=(200,)).astype("int64")
|
|
105
|
+
|
|
106
|
+
model = ConvNet(in_channels=1, num_classes=10, channels=[16, 32])
|
|
107
|
+
trainer = Trainer(model, CrossEntropyLoss(), Adam(model.parameters(), lr=0.005))
|
|
108
|
+
history = trainer.fit(DataLoader(TensorDataset(X, y), batch_size=32), epochs=5)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Advanced Models: ResNet18, U-Net, BERT & VAE
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import neuroforge as nf
|
|
115
|
+
|
|
116
|
+
# ResNet-18
|
|
117
|
+
resnet = nf.ResNet18(in_channels=3, num_classes=10)
|
|
118
|
+
nf.apply_init(resnet, init_fn=nf.kaiming_normal_)
|
|
119
|
+
|
|
120
|
+
# U-Net Image Segmentation
|
|
121
|
+
unet = nf.UNet(in_channels=1, out_channels=1, features=[32, 64])
|
|
122
|
+
|
|
123
|
+
# BERT Masked Language Model
|
|
124
|
+
bert = nf.BERT(vocab_size=1000, d_model=128, nhead=4, num_layers=4)
|
|
125
|
+
|
|
126
|
+
# VAE with Reparameterization
|
|
127
|
+
vae = nf.VAE(input_dim=784, hidden_dim=256, latent_dim=32)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Examples
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python examples/01_mnist_cnn.py # ConvNet image classification
|
|
136
|
+
python examples/02_text_gpt.py # GPT language model + text generation
|
|
137
|
+
python examples/03_multimodal_demo.py # Vision-Language multimodal model
|
|
138
|
+
python examples/04_advanced_models_demo.py # ResNet, U-Net, BERT, VAE, Grad Clipping & Warmup
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## CLI Training & Serving
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# CLI Training
|
|
147
|
+
python scripts/train.py --config configs/default_train.yaml
|
|
148
|
+
|
|
149
|
+
# REST Serving
|
|
150
|
+
python scripts/serve.py --host 0.0.0.0 --port 8000
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Testing
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
python -m pytest tests/ -v
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
36 passed in 1.45s ✅
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
| Test Suite | Tests | Status |
|
|
166
|
+
|---|---|---|
|
|
167
|
+
| `tests/unit/test_tensor.py` | 5 | ✅ |
|
|
168
|
+
| `tests/unit/test_autograd.py` | 3 | ✅ |
|
|
169
|
+
| `tests/unit/test_layers.py` | 5 | ✅ |
|
|
170
|
+
| `tests/unit/test_advanced_layers.py` | 2 | ✅ |
|
|
171
|
+
| `tests/unit/test_models.py` | 5 | ✅ |
|
|
172
|
+
| `tests/unit/test_advanced_models.py` | 4 | ✅ |
|
|
173
|
+
| `tests/unit/test_optimizers.py` | 3 | ✅ |
|
|
174
|
+
| `tests/unit/test_utils_and_schedulers.py` | 4 | ✅ |
|
|
175
|
+
| `tests/unit/test_serving.py` | 4 | ✅ |
|
|
176
|
+
| `tests/integration/test_pipeline.py` | 1 | ✅ |
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
MIT License. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# NeuroForge 🧠⚡
|
|
2
|
+
|
|
3
|
+
> A full-featured deep learning framework and production AI platform — built entirely from first principles in Python/NumPy.
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/)
|
|
6
|
+
[](#testing)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## What is NeuroForge?
|
|
12
|
+
|
|
13
|
+
NeuroForge is a **complete, production-ready deep learning stack** implemented from scratch — no PyTorch, no TensorFlow, no Keras. Every component, from the tensor engine to the FastAPI model-serving layer, is hand-crafted:
|
|
14
|
+
|
|
15
|
+
| Layer | What's included |
|
|
16
|
+
|---|---|
|
|
17
|
+
| 🔢 **Tensor Engine** | NumPy-backed N-D arrays, dynamic autograd computation graph, full reverse-mode AD |
|
|
18
|
+
| 🧱 **Neural Modules** | Linear, Conv1D, Conv2D, ConvTranspose2D, MaxPool, AvgPool, RNN, LSTM, GRU, Attention, Transformer, Embedding, LayerNorm, BatchNorm, Dropout |
|
|
19
|
+
| 🏗️ **Model Zoo** | MLP, ConvNet, ResNet (ResNet18/34), U-Net, BERT, VAE, GPT, VisionTransformer, VisionLanguageModel |
|
|
20
|
+
| 📉 **Losses** | CrossEntropy, BCE, BCEWithLogits, MSE, VAE Loss (BCE + KL) |
|
|
21
|
+
| ⚙️ **Optimizers & Schedulers** | SGD (+ momentum), Adam, AdamW, StepLR, CosineAnnealingLR, WarmupCosineScheduler, WarmupLinearScheduler, ExponentialLR |
|
|
22
|
+
| 🛠️ **Training & Utilities** | Trainer, Gradient Clipping (norm & value), Numerical Gradient Checker, Weight Initialization (Xavier, Kaiming, Orthogonal), Callbacks |
|
|
23
|
+
| 📊 **Experiments & Visuals** | ExperimentTracker, Plot Training History, Gradient Norm Inspection |
|
|
24
|
+
| 📦 **Registry & Serving** | ModelRegistry (versioned save/load) + FastAPI REST server (`/health`, `/models`, `/predict`, `/generate`, `/metrics`) |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
32
|
+
│ NeuroForge Stack │
|
|
33
|
+
├───────────────────────────────────────────────────────────────────┤
|
|
34
|
+
│ neuroforge.core │ Tensor + Autograd Engine │
|
|
35
|
+
│ neuroforge.nn │ Module, Parameter, 16 Layer Types │
|
|
36
|
+
│ neuroforge.models │ MLP, ConvNet, ResNet, UNet, BERT, VAE... │
|
|
37
|
+
│ neuroforge.losses │ CrossEntropy, BCE, MSE, VAE Loss │
|
|
38
|
+
│ neuroforge.optim │ SGD, Adam, AdamW, Warmup Schedulers │
|
|
39
|
+
│ neuroforge.data │ TensorDataset, DataLoader │
|
|
40
|
+
│ neuroforge.training │ Trainer, Callbacks, Metrics │
|
|
41
|
+
│ neuroforge.utils │ Init, Grad Clipping, Grad Check, Plots │
|
|
42
|
+
│ neuroforge.experiments│ ExperimentTracker │
|
|
43
|
+
│ neuroforge.registry │ ModelRegistry (versioned persistence) │
|
|
44
|
+
│ neuroforge.inference │ InferenceEngine │
|
|
45
|
+
│ neuroforge.serving │ FastAPI production REST server │
|
|
46
|
+
└───────────────────────────────────────────────────────────────────┘
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
### Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
cd NeuroForge
|
|
57
|
+
pip install -e .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Train a ConvNet in 5 lines
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import numpy as np
|
|
64
|
+
from neuroforge import ConvNet, CrossEntropyLoss, Adam, TensorDataset, DataLoader, Trainer
|
|
65
|
+
|
|
66
|
+
X = np.random.randn(200, 1, 28, 28).astype("float32")
|
|
67
|
+
y = np.random.randint(0, 10, size=(200,)).astype("int64")
|
|
68
|
+
|
|
69
|
+
model = ConvNet(in_channels=1, num_classes=10, channels=[16, 32])
|
|
70
|
+
trainer = Trainer(model, CrossEntropyLoss(), Adam(model.parameters(), lr=0.005))
|
|
71
|
+
history = trainer.fit(DataLoader(TensorDataset(X, y), batch_size=32), epochs=5)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Advanced Models: ResNet18, U-Net, BERT & VAE
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import neuroforge as nf
|
|
78
|
+
|
|
79
|
+
# ResNet-18
|
|
80
|
+
resnet = nf.ResNet18(in_channels=3, num_classes=10)
|
|
81
|
+
nf.apply_init(resnet, init_fn=nf.kaiming_normal_)
|
|
82
|
+
|
|
83
|
+
# U-Net Image Segmentation
|
|
84
|
+
unet = nf.UNet(in_channels=1, out_channels=1, features=[32, 64])
|
|
85
|
+
|
|
86
|
+
# BERT Masked Language Model
|
|
87
|
+
bert = nf.BERT(vocab_size=1000, d_model=128, nhead=4, num_layers=4)
|
|
88
|
+
|
|
89
|
+
# VAE with Reparameterization
|
|
90
|
+
vae = nf.VAE(input_dim=784, hidden_dim=256, latent_dim=32)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Examples
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
python examples/01_mnist_cnn.py # ConvNet image classification
|
|
99
|
+
python examples/02_text_gpt.py # GPT language model + text generation
|
|
100
|
+
python examples/03_multimodal_demo.py # Vision-Language multimodal model
|
|
101
|
+
python examples/04_advanced_models_demo.py # ResNet, U-Net, BERT, VAE, Grad Clipping & Warmup
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## CLI Training & Serving
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# CLI Training
|
|
110
|
+
python scripts/train.py --config configs/default_train.yaml
|
|
111
|
+
|
|
112
|
+
# REST Serving
|
|
113
|
+
python scripts/serve.py --host 0.0.0.0 --port 8000
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Testing
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
python -m pytest tests/ -v
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
36 passed in 1.45s ✅
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
| Test Suite | Tests | Status |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| `tests/unit/test_tensor.py` | 5 | ✅ |
|
|
131
|
+
| `tests/unit/test_autograd.py` | 3 | ✅ |
|
|
132
|
+
| `tests/unit/test_layers.py` | 5 | ✅ |
|
|
133
|
+
| `tests/unit/test_advanced_layers.py` | 2 | ✅ |
|
|
134
|
+
| `tests/unit/test_models.py` | 5 | ✅ |
|
|
135
|
+
| `tests/unit/test_advanced_models.py` | 4 | ✅ |
|
|
136
|
+
| `tests/unit/test_optimizers.py` | 3 | ✅ |
|
|
137
|
+
| `tests/unit/test_utils_and_schedulers.py` | 4 | ✅ |
|
|
138
|
+
| `tests/unit/test_serving.py` | 4 | ✅ |
|
|
139
|
+
| `tests/integration/test_pipeline.py` | 1 | ✅ |
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT License. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "neuroforge-dl"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "A full-featured deep learning framework and production AI platform built from first principles in Python & NumPy."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "NeuroForge Contributors", email = "neuroforge@example.com" }
|
|
13
|
+
]
|
|
14
|
+
keywords = [
|
|
15
|
+
"deep-learning",
|
|
16
|
+
"autograd",
|
|
17
|
+
"neural-networks",
|
|
18
|
+
"transformers",
|
|
19
|
+
"gpt",
|
|
20
|
+
"vision-transformer",
|
|
21
|
+
"resnet",
|
|
22
|
+
"unet",
|
|
23
|
+
"bert",
|
|
24
|
+
"vae",
|
|
25
|
+
"fastapi-serving",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Intended Audience :: Science/Research",
|
|
31
|
+
"License :: OSI Approved :: MIT License",
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3.10",
|
|
34
|
+
"Programming Language :: Python :: 3.11",
|
|
35
|
+
"Programming Language :: Python :: 3.12",
|
|
36
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
37
|
+
]
|
|
38
|
+
requires-python = ">=3.10"
|
|
39
|
+
|
|
40
|
+
dependencies = [
|
|
41
|
+
"numpy>=1.26.0",
|
|
42
|
+
"pyyaml>=6.0",
|
|
43
|
+
"pydantic>=2.0",
|
|
44
|
+
"fastapi>=0.110.0",
|
|
45
|
+
"uvicorn[standard]>=0.28.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
dev = [
|
|
50
|
+
"pytest>=8.0.0",
|
|
51
|
+
"pytest-cov>=5.0.0",
|
|
52
|
+
"ruff>=0.6.0",
|
|
53
|
+
"mypy>=1.10.0",
|
|
54
|
+
"mkdocs>=1.5.0",
|
|
55
|
+
"mkdocs-material>=9.5.0",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
[project.scripts]
|
|
59
|
+
neuroforge-train = "scripts.train:main"
|
|
60
|
+
neuroforge-serve = "scripts.serve:main"
|
|
61
|
+
|
|
62
|
+
[project.urls]
|
|
63
|
+
Homepage = "https://github.com/username/neuroforge"
|
|
64
|
+
Documentation = "https://github.com/username/neuroforge#readme"
|
|
65
|
+
Repository = "https://github.com/username/neuroforge.git"
|
|
66
|
+
Issues = "https://github.com/username/neuroforge/issues"
|
|
67
|
+
|
|
68
|
+
[tool.setuptools.packages.find]
|
|
69
|
+
where = ["src"]
|
|
70
|
+
|
|
71
|
+
[tool.pytest.ini_options]
|
|
72
|
+
pythonpath = ["src"]
|
|
73
|
+
testpaths = ["tests"]
|
|
74
|
+
|
|
75
|
+
[tool.ruff]
|
|
76
|
+
line-length = 100
|
|
77
|
+
target-version = "py310"
|
|
78
|
+
|
|
79
|
+
[tool.mypy]
|
|
80
|
+
python_version = "3.10"
|
|
81
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""NeuroForge: A deep learning framework and production AI platform built from first principles."""
|
|
2
|
+
|
|
3
|
+
from neuroforge.core import Tensor, zeros, ones, randn, rand, NeuroForgeError
|
|
4
|
+
from neuroforge.nn import (
|
|
5
|
+
Module,
|
|
6
|
+
Parameter,
|
|
7
|
+
Linear,
|
|
8
|
+
Conv1D,
|
|
9
|
+
Conv2D,
|
|
10
|
+
ConvTranspose2D,
|
|
11
|
+
MaxPool2D,
|
|
12
|
+
AvgPool2D,
|
|
13
|
+
Flatten,
|
|
14
|
+
LayerNorm,
|
|
15
|
+
BatchNorm1d,
|
|
16
|
+
BatchNorm2d,
|
|
17
|
+
Dropout,
|
|
18
|
+
Embedding,
|
|
19
|
+
PositionalEncoding,
|
|
20
|
+
ScaledDotProductAttention,
|
|
21
|
+
MultiHeadAttention,
|
|
22
|
+
Transformer,
|
|
23
|
+
)
|
|
24
|
+
from neuroforge.losses import Loss, MSELoss, CrossEntropyLoss, BCELoss, BCEWithLogitsLoss
|
|
25
|
+
from neuroforge.optim import (
|
|
26
|
+
Optimizer,
|
|
27
|
+
SGD,
|
|
28
|
+
Adam,
|
|
29
|
+
AdamW,
|
|
30
|
+
LRScheduler,
|
|
31
|
+
StepLR,
|
|
32
|
+
CosineAnnealingLR,
|
|
33
|
+
WarmupCosineScheduler,
|
|
34
|
+
WarmupLinearScheduler,
|
|
35
|
+
ExponentialLR,
|
|
36
|
+
)
|
|
37
|
+
from neuroforge.data import Dataset, TensorDataset, DataLoader, Compose, ToTensor, Normalize, Rescale
|
|
38
|
+
from neuroforge.models import (
|
|
39
|
+
MLP,
|
|
40
|
+
ConvNet,
|
|
41
|
+
ResidualBlock,
|
|
42
|
+
ResNet,
|
|
43
|
+
ResNet18,
|
|
44
|
+
ResNet34,
|
|
45
|
+
UNet,
|
|
46
|
+
BERT,
|
|
47
|
+
VAE,
|
|
48
|
+
vae_loss,
|
|
49
|
+
SequenceClassifier,
|
|
50
|
+
GPT,
|
|
51
|
+
VisionTransformer,
|
|
52
|
+
VisionLanguageModel,
|
|
53
|
+
)
|
|
54
|
+
from neuroforge.training import accuracy, precision_recall_f1, Callback, EarlyStopping, ModelCheckpoint, LoggingCallback, Trainer
|
|
55
|
+
from neuroforge.experiments import ExperimentTracker
|
|
56
|
+
from neuroforge.registry import ModelRegistry
|
|
57
|
+
from neuroforge.inference import InferenceEngine
|
|
58
|
+
from neuroforge.utils import (
|
|
59
|
+
set_seed,
|
|
60
|
+
summary,
|
|
61
|
+
plot_history,
|
|
62
|
+
plot_gradient_norms,
|
|
63
|
+
clip_grad_norm_,
|
|
64
|
+
clip_grad_value_,
|
|
65
|
+
numerical_gradient,
|
|
66
|
+
grad_check,
|
|
67
|
+
xavier_uniform_,
|
|
68
|
+
xavier_normal_,
|
|
69
|
+
kaiming_uniform_,
|
|
70
|
+
kaiming_normal_,
|
|
71
|
+
orthogonal_,
|
|
72
|
+
apply_init,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
from neuroforge import losses
|
|
76
|
+
from neuroforge import optim
|
|
77
|
+
from neuroforge import data
|
|
78
|
+
from neuroforge import models
|
|
79
|
+
from neuroforge import training
|
|
80
|
+
from neuroforge import experiments
|
|
81
|
+
from neuroforge import registry
|
|
82
|
+
from neuroforge import inference
|
|
83
|
+
from neuroforge import serving
|
|
84
|
+
from neuroforge import utils
|
|
85
|
+
|
|
86
|
+
__version__ = "0.2.0"
|
|
87
|
+
|
|
88
|
+
__all__ = [
|
|
89
|
+
"Tensor",
|
|
90
|
+
"zeros",
|
|
91
|
+
"ones",
|
|
92
|
+
"randn",
|
|
93
|
+
"rand",
|
|
94
|
+
"NeuroForgeError",
|
|
95
|
+
"Module",
|
|
96
|
+
"Parameter",
|
|
97
|
+
"Linear",
|
|
98
|
+
"Conv1D",
|
|
99
|
+
"Conv2D",
|
|
100
|
+
"ConvTranspose2D",
|
|
101
|
+
"MaxPool2D",
|
|
102
|
+
"AvgPool2D",
|
|
103
|
+
"Flatten",
|
|
104
|
+
"LayerNorm",
|
|
105
|
+
"BatchNorm1d",
|
|
106
|
+
"BatchNorm2d",
|
|
107
|
+
"Dropout",
|
|
108
|
+
"Embedding",
|
|
109
|
+
"PositionalEncoding",
|
|
110
|
+
"ScaledDotProductAttention",
|
|
111
|
+
"MultiHeadAttention",
|
|
112
|
+
"Transformer",
|
|
113
|
+
"Loss",
|
|
114
|
+
"MSELoss",
|
|
115
|
+
"CrossEntropyLoss",
|
|
116
|
+
"BCELoss",
|
|
117
|
+
"BCEWithLogitsLoss",
|
|
118
|
+
"Optimizer",
|
|
119
|
+
"SGD",
|
|
120
|
+
"Adam",
|
|
121
|
+
"AdamW",
|
|
122
|
+
"LRScheduler",
|
|
123
|
+
"StepLR",
|
|
124
|
+
"CosineAnnealingLR",
|
|
125
|
+
"WarmupCosineScheduler",
|
|
126
|
+
"WarmupLinearScheduler",
|
|
127
|
+
"ExponentialLR",
|
|
128
|
+
"Dataset",
|
|
129
|
+
"TensorDataset",
|
|
130
|
+
"DataLoader",
|
|
131
|
+
"Compose",
|
|
132
|
+
"ToTensor",
|
|
133
|
+
"Normalize",
|
|
134
|
+
"Rescale",
|
|
135
|
+
"MLP",
|
|
136
|
+
"ConvNet",
|
|
137
|
+
"ResidualBlock",
|
|
138
|
+
"ResNet",
|
|
139
|
+
"ResNet18",
|
|
140
|
+
"ResNet34",
|
|
141
|
+
"UNet",
|
|
142
|
+
"BERT",
|
|
143
|
+
"VAE",
|
|
144
|
+
"vae_loss",
|
|
145
|
+
"SequenceClassifier",
|
|
146
|
+
"GPT",
|
|
147
|
+
"VisionTransformer",
|
|
148
|
+
"VisionLanguageModel",
|
|
149
|
+
"accuracy",
|
|
150
|
+
"precision_recall_f1",
|
|
151
|
+
"Callback",
|
|
152
|
+
"EarlyStopping",
|
|
153
|
+
"ModelCheckpoint",
|
|
154
|
+
"LoggingCallback",
|
|
155
|
+
"Trainer",
|
|
156
|
+
"ExperimentTracker",
|
|
157
|
+
"ModelRegistry",
|
|
158
|
+
"InferenceEngine",
|
|
159
|
+
"set_seed",
|
|
160
|
+
"summary",
|
|
161
|
+
"plot_history",
|
|
162
|
+
"plot_gradient_norms",
|
|
163
|
+
"clip_grad_norm_",
|
|
164
|
+
"clip_grad_value_",
|
|
165
|
+
"numerical_gradient",
|
|
166
|
+
"grad_check",
|
|
167
|
+
"xavier_uniform_",
|
|
168
|
+
"xavier_normal_",
|
|
169
|
+
"kaiming_uniform_",
|
|
170
|
+
"kaiming_normal_",
|
|
171
|
+
"orthogonal_",
|
|
172
|
+
"apply_init",
|
|
173
|
+
"losses",
|
|
174
|
+
"optim",
|
|
175
|
+
"data",
|
|
176
|
+
"models",
|
|
177
|
+
"training",
|
|
178
|
+
"experiments",
|
|
179
|
+
"registry",
|
|
180
|
+
"inference",
|
|
181
|
+
"serving",
|
|
182
|
+
"utils",
|
|
183
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Core tensor and autograd components of NeuroForge."""
|
|
2
|
+
|
|
3
|
+
from neuroforge.core.exceptions import (
|
|
4
|
+
NeuroForgeError,
|
|
5
|
+
TensorError,
|
|
6
|
+
ShapeMismatchError,
|
|
7
|
+
AutogradError,
|
|
8
|
+
ModelError,
|
|
9
|
+
ServingError,
|
|
10
|
+
ConfigError,
|
|
11
|
+
)
|
|
12
|
+
from neuroforge.core.autograd import unbroadcast
|
|
13
|
+
from neuroforge.core.tensor import Tensor, zeros, ones, randn, rand
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"NeuroForgeError",
|
|
17
|
+
"TensorError",
|
|
18
|
+
"ShapeMismatchError",
|
|
19
|
+
"AutogradError",
|
|
20
|
+
"ModelError",
|
|
21
|
+
"ServingError",
|
|
22
|
+
"ConfigError",
|
|
23
|
+
"unbroadcast",
|
|
24
|
+
"Tensor",
|
|
25
|
+
"zeros",
|
|
26
|
+
"ones",
|
|
27
|
+
"randn",
|
|
28
|
+
"rand",
|
|
29
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Autograd engine primitives and shape handling for NeuroForge."""
|
|
2
|
+
|
|
3
|
+
from typing import Tuple, Union, Any
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def unbroadcast(grad: np.ndarray, target_shape: Tuple[int, ...]) -> np.ndarray:
|
|
8
|
+
"""Sum out broadcasted dimensions in `grad` to match `target_shape`.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
grad: Gradient array with potentially broadcasted shape.
|
|
12
|
+
target_shape: Target shape of the input tensor.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
np.ndarray gradient reshaped/reduced to match target_shape.
|
|
16
|
+
"""
|
|
17
|
+
if grad.shape == target_shape:
|
|
18
|
+
return grad
|
|
19
|
+
|
|
20
|
+
# If target is a scalar (empty shape)
|
|
21
|
+
if target_shape == ():
|
|
22
|
+
return np.sum(grad)
|
|
23
|
+
|
|
24
|
+
grad_ndim = grad.ndim
|
|
25
|
+
target_ndim = len(target_shape)
|
|
26
|
+
|
|
27
|
+
# Sum leading extra dimensions added by broadcasting
|
|
28
|
+
diff_ndim = grad_ndim - target_ndim
|
|
29
|
+
if diff_ndim > 0:
|
|
30
|
+
grad = np.sum(grad, axis=tuple(range(diff_ndim)))
|
|
31
|
+
|
|
32
|
+
# Sum dimensions where target_shape was 1 (singleton dimensions)
|
|
33
|
+
axes_to_sum = []
|
|
34
|
+
for i, (g_dim, t_dim) in enumerate(zip(grad.shape, target_shape)):
|
|
35
|
+
if t_dim == 1 and g_dim > 1:
|
|
36
|
+
axes_to_sum.append(i)
|
|
37
|
+
|
|
38
|
+
if axes_to_sum:
|
|
39
|
+
grad = np.sum(grad, axis=tuple(axes_to_sum), keepdims=True)
|
|
40
|
+
|
|
41
|
+
return grad.reshape(target_shape)
|