zengrad-pytorch 0.0.1__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.
- zengrad_pytorch-0.0.1/PKG-INFO +52 -0
- zengrad_pytorch-0.0.1/README.md +34 -0
- zengrad_pytorch-0.0.1/setup.cfg +4 -0
- zengrad_pytorch-0.0.1/setup.py +27 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch/__init__.py +1 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch/zengrad_pytorch.py +62 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch.egg-info/PKG-INFO +52 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch.egg-info/SOURCES.txt +9 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch.egg-info/dependency_links.txt +1 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch.egg-info/requires.txt +1 -0
- zengrad_pytorch-0.0.1/zengrad_pytorch.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: zengrad-pytorch
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: ZenGrad Optimizer - Pytorch
|
|
5
|
+
Home-page: https://github.com/XenReZ/ZenGrad-PyTorch
|
|
6
|
+
Author: Rishi Chaitanya
|
|
7
|
+
Author-email: rishichaitanya888@gmail.com
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.6
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: torch>=1.6.0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
To install ZenGrad, run the following command:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install zengrad-pytorch
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Implementation
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import torch
|
|
32
|
+
from zengrad_pytorch import ZenGrad # Custom optimizer
|
|
33
|
+
|
|
34
|
+
# Define the model
|
|
35
|
+
|
|
36
|
+
# Instantiate the model
|
|
37
|
+
model = SimpleModel()
|
|
38
|
+
|
|
39
|
+
# Define loss function
|
|
40
|
+
criterion = nn.CrossEntropyLoss()
|
|
41
|
+
|
|
42
|
+
# Instantiate optimizer
|
|
43
|
+
optimizer = ZenGrad(model.parameters(), lr=0.01, weight_decay=1e-4, epsilon=1e-8) # <---- In This Way
|
|
44
|
+
|
|
45
|
+
# Model summary (optional)
|
|
46
|
+
print(model)
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
ZenGrad_pytorch is released under the [Apache License 2.0](https://github.com/XenReZ/ZenGrad-PyTorch/blob/main/LICENSE).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
## Installation
|
|
3
|
+
|
|
4
|
+
To install ZenGrad, run the following command:
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install zengrad-pytorch
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Implementation
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import torch
|
|
14
|
+
from zengrad_pytorch import ZenGrad # Custom optimizer
|
|
15
|
+
|
|
16
|
+
# Define the model
|
|
17
|
+
|
|
18
|
+
# Instantiate the model
|
|
19
|
+
model = SimpleModel()
|
|
20
|
+
|
|
21
|
+
# Define loss function
|
|
22
|
+
criterion = nn.CrossEntropyLoss()
|
|
23
|
+
|
|
24
|
+
# Instantiate optimizer
|
|
25
|
+
optimizer = ZenGrad(model.parameters(), lr=0.01, weight_decay=1e-4, epsilon=1e-8) # <---- In This Way
|
|
26
|
+
|
|
27
|
+
# Model summary (optional)
|
|
28
|
+
print(model)
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
ZenGrad_pytorch is released under the [Apache License 2.0](https://github.com/XenReZ/ZenGrad-PyTorch/blob/main/LICENSE).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name='zengrad-pytorch',
|
|
6
|
+
version='0.0.1',
|
|
7
|
+
description='ZenGrad Optimizer - Pytorch',
|
|
8
|
+
long_description=open('README.md', encoding='utf-8').read(),
|
|
9
|
+
long_description_content_type='text/markdown',
|
|
10
|
+
author= 'Rishi Chaitanya',
|
|
11
|
+
author_email='rishichaitanya888@gmail.com',
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
url='https://github.com/XenReZ/ZenGrad-PyTorch',
|
|
14
|
+
license="Apache-2.0",
|
|
15
|
+
install_requires=[
|
|
16
|
+
"torch>=1.6.0"
|
|
17
|
+
],
|
|
18
|
+
classifiers=[
|
|
19
|
+
'Programming Language :: Python :: 3',
|
|
20
|
+
"License :: OSI Approved :: Apache Software License",
|
|
21
|
+
'Operating System :: OS Independent',
|
|
22
|
+
'Intended Audience :: Developers',
|
|
23
|
+
'Intended Audience :: Science/Research',
|
|
24
|
+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
|
25
|
+
],
|
|
26
|
+
python_requires='>=3.6',
|
|
27
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .zengrad_pytorch import ZenGrad
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from torch.optim import Optimizer
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
class ZenGrad(Optimizer):
|
|
6
|
+
def __init__(self, params, lr=0.01, initial_accumulator_value=0.1, weight_decay=1e-4, epsilon=1e-8):
|
|
7
|
+
if lr <= 0.0:
|
|
8
|
+
raise ValueError(f"Invalid learning rate: {lr}")
|
|
9
|
+
if initial_accumulator_value < 0.0:
|
|
10
|
+
raise ValueError(f"Invalid accumulator value: {initial_accumulator_value}")
|
|
11
|
+
if weight_decay < 0.0:
|
|
12
|
+
raise ValueError(f"Invalid weight decay: {weight_decay}")
|
|
13
|
+
if epsilon <= 0.0:
|
|
14
|
+
raise ValueError(f"Invalid epsilon value: {epsilon}")
|
|
15
|
+
|
|
16
|
+
defaults = dict(
|
|
17
|
+
lr=lr,
|
|
18
|
+
initial_accumulator_value=initial_accumulator_value,
|
|
19
|
+
weight_decay=weight_decay,
|
|
20
|
+
epsilon=epsilon
|
|
21
|
+
)
|
|
22
|
+
super(ZenGrad, self).__init__(params, defaults)
|
|
23
|
+
|
|
24
|
+
def step(self, closure=None):
|
|
25
|
+
loss = None
|
|
26
|
+
if closure is not None:
|
|
27
|
+
loss = closure()
|
|
28
|
+
|
|
29
|
+
for group in self.param_groups:
|
|
30
|
+
lr = group['lr']
|
|
31
|
+
acc_init = group['initial_accumulator_value']
|
|
32
|
+
weight_decay = group['weight_decay']
|
|
33
|
+
epsilon = group['epsilon']
|
|
34
|
+
|
|
35
|
+
for p in group['params']:
|
|
36
|
+
if p.grad is None:
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
grad = p.grad.data
|
|
40
|
+
if grad.is_sparse:
|
|
41
|
+
raise RuntimeError("hi optimizer does not support sparse gradients")
|
|
42
|
+
|
|
43
|
+
state = self.state[p]
|
|
44
|
+
|
|
45
|
+
# State initialization
|
|
46
|
+
if 'accumulator' not in state:
|
|
47
|
+
state['accumulator'] = torch.full_like(p.data, acc_init)
|
|
48
|
+
|
|
49
|
+
accumulator = state['accumulator']
|
|
50
|
+
accumulator.add_(grad.pow(2)) # A_t = A_{t-1} + g_t^2
|
|
51
|
+
|
|
52
|
+
# Decoupled weight decay (AdamW style)
|
|
53
|
+
if weight_decay != 0:
|
|
54
|
+
p.data.mul_(1 - lr * weight_decay)
|
|
55
|
+
|
|
56
|
+
# Effective learning rate
|
|
57
|
+
effective_lr = lr / (torch.log(accumulator + 1) + epsilon)
|
|
58
|
+
|
|
59
|
+
# Parameter update
|
|
60
|
+
p.data.addcmul_(grad, -effective_lr)
|
|
61
|
+
|
|
62
|
+
return loss
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: zengrad-pytorch
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: ZenGrad Optimizer - Pytorch
|
|
5
|
+
Home-page: https://github.com/XenReZ/ZenGrad-PyTorch
|
|
6
|
+
Author: Rishi Chaitanya
|
|
7
|
+
Author-email: rishichaitanya888@gmail.com
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.6
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: torch>=1.6.0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
To install ZenGrad, run the following command:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install zengrad-pytorch
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Implementation
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import torch
|
|
32
|
+
from zengrad_pytorch import ZenGrad # Custom optimizer
|
|
33
|
+
|
|
34
|
+
# Define the model
|
|
35
|
+
|
|
36
|
+
# Instantiate the model
|
|
37
|
+
model = SimpleModel()
|
|
38
|
+
|
|
39
|
+
# Define loss function
|
|
40
|
+
criterion = nn.CrossEntropyLoss()
|
|
41
|
+
|
|
42
|
+
# Instantiate optimizer
|
|
43
|
+
optimizer = ZenGrad(model.parameters(), lr=0.01, weight_decay=1e-4, epsilon=1e-8) # <---- In This Way
|
|
44
|
+
|
|
45
|
+
# Model summary (optional)
|
|
46
|
+
print(model)
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
ZenGrad_pytorch is released under the [Apache License 2.0](https://github.com/XenReZ/ZenGrad-PyTorch/blob/main/LICENSE).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
zengrad_pytorch/__init__.py
|
|
4
|
+
zengrad_pytorch/zengrad_pytorch.py
|
|
5
|
+
zengrad_pytorch.egg-info/PKG-INFO
|
|
6
|
+
zengrad_pytorch.egg-info/SOURCES.txt
|
|
7
|
+
zengrad_pytorch.egg-info/dependency_links.txt
|
|
8
|
+
zengrad_pytorch.egg-info/requires.txt
|
|
9
|
+
zengrad_pytorch.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
torch>=1.6.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
zengrad_pytorch
|