pytinytensor 0.1.4__tar.gz → 0.1.5__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.
- {pytinytensor-0.1.4/pytinytensor.egg-info → pytinytensor-0.1.5}/PKG-INFO +1 -1
- {pytinytensor-0.1.4 → pytinytensor-0.1.5/pytinytensor.egg-info}/PKG-INFO +1 -1
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/pytinytensor.egg-info/SOURCES.txt +2 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/setup.py +1 -2
- pytinytensor-0.1.5/tinytensor/nn/__init__.py +14 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/nn/modules.py +32 -1
- pytinytensor-0.1.5/tinytensor/nn/utils.py +23 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/optim/__init__.py +6 -3
- pytinytensor-0.1.5/tinytensor/optim/lr_scheduler.py +13 -0
- pytinytensor-0.1.4/tinytensor/nn/__init__.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/LICENSE +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/README.md +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/pyproject.toml +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/pytinytensor.egg-info/dependency_links.txt +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/pytinytensor.egg-info/requires.txt +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/pytinytensor.egg-info/top_level.txt +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/setup.cfg +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tests/test_autograd.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tests/test_data.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tests/test_losses.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tests/test_nn.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tests/test_optim.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tests/test_tensor_math.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/__init__.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/backends/__init__.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/backends/cpu_numpy.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/backends/cuda_binding.cpp +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/backends/cuda_gpu.cu +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/backends/cuda_gpu.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/config.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/core/__init__.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/core/autograd.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/core/ops.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/core/tensor.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/data/__init__.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/data/dataloader.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/data/dataset.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/nn/activations.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/nn/dropout.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/nn/linear.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/nn/losses.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/optim/optimizer.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/utils/__init__.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/utils/bar.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/utils/early_stopping.py +0 -0
- {pytinytensor-0.1.4 → pytinytensor-0.1.5}/tinytensor/utils/summary.py +0 -0
|
@@ -33,7 +33,9 @@ tinytensor/nn/dropout.py
|
|
|
33
33
|
tinytensor/nn/linear.py
|
|
34
34
|
tinytensor/nn/losses.py
|
|
35
35
|
tinytensor/nn/modules.py
|
|
36
|
+
tinytensor/nn/utils.py
|
|
36
37
|
tinytensor/optim/__init__.py
|
|
38
|
+
tinytensor/optim/lr_scheduler.py
|
|
37
39
|
tinytensor/optim/optimizer.py
|
|
38
40
|
tinytensor/utils/__init__.py
|
|
39
41
|
tinytensor/utils/bar.py
|
|
@@ -35,7 +35,6 @@ def find_cuda_lib_dirs():
|
|
|
35
35
|
found.append(lib_dir)
|
|
36
36
|
return found
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
def check_cuda():
|
|
40
39
|
try:
|
|
41
40
|
subprocess.check_output(["nvcc", "--version"])
|
|
@@ -113,7 +112,7 @@ else:
|
|
|
113
112
|
|
|
114
113
|
setup(
|
|
115
114
|
name="pytinytensor",
|
|
116
|
-
version="0.1.
|
|
115
|
+
version="0.1.5",
|
|
117
116
|
description="мини ИИ фреймворк от IbrokimN ( github/IbrokhimN )",
|
|
118
117
|
long_description=long_description,
|
|
119
118
|
long_description_content_type="text/markdown",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from tinytensor.nn.modules import Module, Sequential
|
|
2
|
+
from tinytensor.nn.linear import Linear
|
|
3
|
+
from tinytensor.nn.activations import ReLU, LeReLU, Sigmod, Tanh, GELU
|
|
4
|
+
from tinytensor.nn.dropout import Dropout
|
|
5
|
+
from tinytensor.nn.losses import MSELoss
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"Module",
|
|
9
|
+
"Sequential",
|
|
10
|
+
"Linear",
|
|
11
|
+
"ReLU", "LeReLU", "Sigmod", "Tanh", "GELU",
|
|
12
|
+
"Dropout",
|
|
13
|
+
"MSELoss"
|
|
14
|
+
]
|
|
@@ -37,7 +37,7 @@ class Module:
|
|
|
37
37
|
sdict = {}
|
|
38
38
|
for name, param in self._get_named_params().items():
|
|
39
39
|
sdict[name] = param.data
|
|
40
|
-
return sdict
|
|
40
|
+
return sdict
|
|
41
41
|
|
|
42
42
|
def load_state_dict(self, sdict):
|
|
43
43
|
#запихиваем обратно
|
|
@@ -63,3 +63,34 @@ class Module:
|
|
|
63
63
|
with open(filepath, "rb") as f:
|
|
64
64
|
sd = pickle.load(f)
|
|
65
65
|
self.load_state_dict(sd)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class Sequential(Module):
|
|
69
|
+
def __init__(self, *args):
|
|
70
|
+
super().__init__()
|
|
71
|
+
self.layers = list(args)
|
|
72
|
+
|
|
73
|
+
def parameters(self):
|
|
74
|
+
params = []
|
|
75
|
+
for layer in self.layers:
|
|
76
|
+
params.extend(layer.parameters())
|
|
77
|
+
return params
|
|
78
|
+
|
|
79
|
+
def _get_named_params(self, prefix=""):
|
|
80
|
+
named = {}
|
|
81
|
+
for i, layer in enumerate(self.layers):
|
|
82
|
+
key = f"{prefix}.layers.{i}" if prefix else f"layers.{i}"
|
|
83
|
+
named.update(layer._get_named_params(prefix=key))
|
|
84
|
+
return named
|
|
85
|
+
|
|
86
|
+
def forward(self, x):
|
|
87
|
+
# закидываем x по слоям
|
|
88
|
+
for layer in self.layers:
|
|
89
|
+
x = layer(x)
|
|
90
|
+
return x
|
|
91
|
+
|
|
92
|
+
def __getitem__(self, idx):
|
|
93
|
+
return self.layers[idx]
|
|
94
|
+
|
|
95
|
+
def __len__(self):
|
|
96
|
+
return len(self.layers)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def clip_grad_norm_(parameters, max_norm=1.0):
|
|
4
|
+
if isinstance(parameters, Exception): # тп защита
|
|
5
|
+
return
|
|
6
|
+
|
|
7
|
+
params = [p for p in parameters if p.grad is not None]
|
|
8
|
+
if len(params) == 0:
|
|
9
|
+
return 0.0
|
|
10
|
+
|
|
11
|
+
total_norm_sq = 0.0
|
|
12
|
+
for p in params:
|
|
13
|
+
total_norm_sq += np.sum(p.grad ** 2)
|
|
14
|
+
|
|
15
|
+
total_norm = np.sqrt(total_norm_sq)
|
|
16
|
+
|
|
17
|
+
clip_coef = max_norm / (total_norm + 1e-6)
|
|
18
|
+
|
|
19
|
+
if clip_coef < 1.0:
|
|
20
|
+
for p in params:
|
|
21
|
+
p.grad *= clip_coef
|
|
22
|
+
|
|
23
|
+
return total_norm
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
from tinytensor.optim.optimizer import Optimizer, SGD, AdamW
|
|
2
|
-
|
|
3
|
-
__all__ = [
|
|
2
|
+
from tinytensor.optim.lr_scheduler import StepLR
|
|
3
|
+
__all__ = [
|
|
4
|
+
"Optimizer", "SGD", "AdamW",
|
|
5
|
+
"StepLR"
|
|
6
|
+
]
|
|
4
7
|
|
|
5
8
|
#эт для удобства
|
|
6
9
|
#чтоб можно было писать вот так:
|
|
@@ -8,4 +11,4 @@ __all__ = ["Optimizer", "SGD", "AdamW"]
|
|
|
8
11
|
from tinytensor.optim import AdamW
|
|
9
12
|
|
|
10
13
|
optimizer = AdamW(model.parameters(), lr=1e-3)
|
|
11
|
-
"""
|
|
14
|
+
"""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#уменьшаем lr каждые n эпох чтоб модель обучилась более плавно
|
|
2
|
+
class StepLR:
|
|
3
|
+
def __init__(self, optimizer, step_size: int, gamma: float = 0.1):
|
|
4
|
+
self.optimizer = optimizer
|
|
5
|
+
self.step_size = step_size
|
|
6
|
+
self.gamma = gamma
|
|
7
|
+
self.last_epoch = 0
|
|
8
|
+
|
|
9
|
+
def step(self):
|
|
10
|
+
self.last_epoch += 1
|
|
11
|
+
if self.last_epoch % self.step_size == 0:
|
|
12
|
+
# уменьшаем условно в 10 раз
|
|
13
|
+
self.optimizer.lr *= self.gamma
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|