zengrad-tensorflow 0.0.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .zengrad_tensorflow import ZenGrad
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import tensorflow as tf
|
|
2
|
+
from keras import layers, models
|
|
3
|
+
from keras.src import initializers, ops
|
|
4
|
+
from keras.src.optimizers import optimizer
|
|
5
|
+
|
|
6
|
+
class ZenGrad(optimizer.Optimizer):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
learning_rate=0.01,
|
|
10
|
+
initial_accumulator_value=0.1,
|
|
11
|
+
weight_decay=1e-4,
|
|
12
|
+
epsilon=1e-8,
|
|
13
|
+
name="ZenGrad",
|
|
14
|
+
**kwargs,
|
|
15
|
+
):
|
|
16
|
+
super().__init__(
|
|
17
|
+
learning_rate=learning_rate,
|
|
18
|
+
name=name,
|
|
19
|
+
**kwargs,
|
|
20
|
+
)
|
|
21
|
+
self.initial_accumulator_value = initial_accumulator_value
|
|
22
|
+
self.weight_decay = weight_decay
|
|
23
|
+
self.epsilon = epsilon
|
|
24
|
+
|
|
25
|
+
def build(self, var_list):
|
|
26
|
+
if self.built:
|
|
27
|
+
return
|
|
28
|
+
super().build(var_list)
|
|
29
|
+
self._accumulators = []
|
|
30
|
+
initializer = initializers.Constant(self.initial_accumulator_value)
|
|
31
|
+
for var in var_list:
|
|
32
|
+
self._accumulators.append(
|
|
33
|
+
self.add_variable(
|
|
34
|
+
name="accumulator",
|
|
35
|
+
shape=var.shape,
|
|
36
|
+
dtype=var.dtype,
|
|
37
|
+
initializer=initializer,
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def update_step(self, gradient, variable, learning_rate):
|
|
42
|
+
lr = ops.cast(learning_rate, variable.dtype)
|
|
43
|
+
gradient = ops.cast(gradient, variable.dtype)
|
|
44
|
+
|
|
45
|
+
accumulator = self._accumulators[self._get_variable_index(variable)]
|
|
46
|
+
|
|
47
|
+
# A_t = A_{t-1} + g_t^2
|
|
48
|
+
self.assign_add(accumulator, ops.square(gradient))
|
|
49
|
+
|
|
50
|
+
# Optional: decoupled weight decay
|
|
51
|
+
if self.weight_decay > 0.0:
|
|
52
|
+
self.assign_sub(variable, variable * lr * self.weight_decay)
|
|
53
|
+
|
|
54
|
+
# Effective learning rate and parameter update
|
|
55
|
+
self.assign_sub(
|
|
56
|
+
variable,
|
|
57
|
+
ops.divide(
|
|
58
|
+
ops.multiply(lr, gradient),
|
|
59
|
+
ops.add(ops.log(ops.add(accumulator, 1.0)), self.epsilon),
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def get_config(self):
|
|
64
|
+
config = super().get_config()
|
|
65
|
+
config.update(
|
|
66
|
+
{
|
|
67
|
+
"initial_accumulator_value": self.initial_accumulator_value,
|
|
68
|
+
"weight_decay": self.weight_decay,
|
|
69
|
+
"epsilon": self.epsilon,
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
return config
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: zengrad-tensorflow
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: ZenGrad Optimizer - TensorFlow
|
|
5
|
+
Home-page: https://github.com/Poorni-Murumuri/ZenGrad
|
|
6
|
+
Author: Murumuri Naga Poorni
|
|
7
|
+
Author-email: poorni.m0405@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: tensorflow>=2.10.0
|
|
18
|
+
Requires-Dist: keras>=2.10.0
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# ZenGrad: Gradient Descent Optimizer
|
|
22
|
+
|
|
23
|
+
ZenGrad is a reliable and efficient gradient descent optimizer designed to improve the stability and performance of deep learning models. It focuses on providing smooth and consistent updates during training, reducing the chances of sudden or unstable changes that can slow down convergence. With its adaptive nature, ZenGrad adjusts to the loss landscape in real time, helping models learn more effectively and reach better performance. Built for seamless integration with TensorFlow, it fits easily into existing machine learning workflows, making it a strong choice for both research and practical applications that demand stable and efficient optimization.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
To install ZenGrad, run the following command:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install zengrad-tensorflow
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Implementation
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from zengrad_tensorflow import ZenGrad # Import the ZenGrad optimizer
|
|
38
|
+
|
|
39
|
+
# Define your preferred model architecture here (e.g., CNN, ResNet, LSTM, Transformer, etc.)
|
|
40
|
+
# Example:
|
|
41
|
+
# model = ...
|
|
42
|
+
|
|
43
|
+
# Compile your model using ZenGrad
|
|
44
|
+
model.compile(
|
|
45
|
+
optimizer=ZenGrad(learning_rate=0.01, weight_decay=1e-4),
|
|
46
|
+
.......
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
ZenGrad is released under the [Apache License 2.0](https://github.com/Poorni-Murumuri/ZenGrad/blob/main/LICENSE).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
zengrad_tensorflow/__init__.py,sha256=c1bxokgiZeubFBOioM4It7zHCy_YJgzbo4-cq_eGs2g,39
|
|
2
|
+
zengrad_tensorflow/zengrad_tensorflow.py,sha256=EYedNL0Unho7K38CNyeFpALPiwIUsUBsjVr9WQstC1Y,2296
|
|
3
|
+
zengrad_tensorflow-0.0.0.dist-info/METADATA,sha256=LpiLA-qdTjtmTejBXP0Phq5bXEZNfEpQqDO_nCfl5GI,2053
|
|
4
|
+
zengrad_tensorflow-0.0.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
5
|
+
zengrad_tensorflow-0.0.0.dist-info/top_level.txt,sha256=wWPj7ArGxzi5IYLqIV2IjCNrxC0R9NNSV6p-bDAI90I,19
|
|
6
|
+
zengrad_tensorflow-0.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
zengrad_tensorflow
|