HomOpt 0.1.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.
@@ -0,0 +1,62 @@
1
+ import torch
2
+ from torch.optim import Optimizer
3
+
4
+ class HomM(Optimizer):
5
+ def __init__(self, params, lr=0.1, a=-0.5, k1=-1.0, k2=-1.0, eps=0.2):
6
+ """
7
+ Finite-Time Momentum Optimizer
8
+
9
+ Args:
10
+ params (iterable): model parameters
11
+ lr (float): learning rate
12
+ a (float): exponent on the norm (usually negative)
13
+ k1, k2 (float): gradient scaling coefficients
14
+ eps (float): velocity coupling factor
15
+ """
16
+ defaults = dict(lr=lr, a=a, k1=k1, k2=k2, eps=eps)
17
+ super().__init__(params, defaults)
18
+
19
+ @torch.no_grad()
20
+ def step(self, closure=None):
21
+ """
22
+ Perform a single optimization step.
23
+ """
24
+ loss = closure() if closure is not None else None
25
+ epsilon_min = 1e-5 # to avoid instability when norm is close to zero
26
+
27
+ for group in self.param_groups:
28
+ lr = group['lr']
29
+ a = group['a']
30
+ k1 = group['k1']
31
+ k2 = group['k2']
32
+ eps = group['eps']
33
+
34
+ for p in group['params']:
35
+ if p.grad is None:
36
+ continue
37
+
38
+ grad = p.grad.data # gradient tensor
39
+
40
+ # Get state dict for this parameter
41
+ state = self.state[p]
42
+
43
+ # Initialize velocity buffer if not present
44
+ if 'v' not in state:
45
+ state['v'] = torch.zeros_like(p.data)
46
+
47
+ v = state['v']
48
+
49
+ # Compute Euclidean norm: || [grad, v] ||
50
+ norm_grad = torch.norm(grad)
51
+ norm_v = torch.norm(v)
52
+ norm_z = torch.sqrt(norm_grad ** 2 + norm_v ** 2)
53
+ norm_z = torch.clamp(norm_z, min=epsilon_min)
54
+
55
+ # Compute time-varying gain
56
+ alpha = lr * norm_z.pow(a)
57
+
58
+ # Explicit update (in-place)
59
+ v.add_(alpha * (eps * grad + k2 * v)) # Update v
60
+ p.data.add_(alpha * (k1 * grad + eps * v)) # Update p
61
+
62
+ return loss
@@ -0,0 +1,3 @@
1
+ from .HomM import HomM
2
+
3
+ __all__ = ['HomM']
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: HomOpt
3
+ Version: 0.1.0
4
+ Summary: A collection of homogeneous optimizers for PyTorch
5
+ Home-page: https://github.com/Yu-Zhou-1/HomOpt
6
+ Author: Yu Zhou
7
+ Author-email: yu_zhou@yeah.net
8
+ License: MIT
9
+ Keywords: pytorch optimizer deep-learning
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
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
+ License-File: LICENSE
18
+ Requires-Dist: torch>=1.6.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: keywords
25
+ Dynamic: license
26
+ Dynamic: license-file
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ HomOpt/HomM.py
5
+ HomOpt/__init__.py
6
+ HomOpt.egg-info/PKG-INFO
7
+ HomOpt.egg-info/SOURCES.txt
8
+ HomOpt.egg-info/dependency_links.txt
9
+ HomOpt.egg-info/requires.txt
10
+ HomOpt.egg-info/top_level.txt
11
+ homopt.egg-info/PKG-INFO
12
+ homopt.egg-info/SOURCES.txt
13
+ homopt.egg-info/dependency_links.txt
14
+ homopt.egg-info/requires.txt
15
+ homopt.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ torch>=1.6.0
@@ -0,0 +1 @@
1
+ HomOpt
homopt-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yu Zhou
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.
homopt-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: HomOpt
3
+ Version: 0.1.0
4
+ Summary: A collection of homogeneous optimizers for PyTorch
5
+ Home-page: https://github.com/Yu-Zhou-1/HomOpt
6
+ Author: Yu Zhou
7
+ Author-email: yu_zhou@yeah.net
8
+ License: MIT
9
+ Keywords: pytorch optimizer deep-learning
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
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
+ License-File: LICENSE
18
+ Requires-Dist: torch>=1.6.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: keywords
25
+ Dynamic: license
26
+ Dynamic: license-file
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
homopt-0.1.0/README.md ADDED
File without changes
homopt-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
homopt-0.1.0/setup.py ADDED
@@ -0,0 +1,33 @@
1
+ from setuptools import setup, find_packages
2
+ import pathlib
3
+
4
+ # 读取 README.md 内容作为长描述
5
+ here = pathlib.Path(__file__).parent
6
+ long_description = (here / "README.md").read_text(encoding="utf-8")
7
+
8
+ setup(
9
+ name="HomOpt",
10
+ version="0.1.0",
11
+ packages=find_packages(),
12
+ install_requires=[
13
+ "torch>=1.6.0", # 指定最低版本要求
14
+ ],
15
+ python_requires=">=3.6", # 指定Python版本要求
16
+ author="Yu Zhou",
17
+ author_email="yu_zhou@yeah.net",
18
+ description="A collection of homogeneous optimizers for PyTorch",
19
+ long_description=long_description,
20
+ long_description_content_type="text/markdown",
21
+ url="https://github.com/Yu-Zhou-1/HomOpt",
22
+ classifiers=[
23
+ "Programming Language :: Python :: 3",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Operating System :: OS Independent",
26
+ "Intended Audience :: Science/Research",
27
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
28
+ ],
29
+ license="MIT",
30
+ keywords="pytorch optimizer deep-learning",
31
+ # 确保包含非Python文件(如果有)
32
+ include_package_data=True,
33
+ )