LMFuser 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.
@@ -0,0 +1,70 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.11"
28
+
29
+ - name: Build release distributions
30
+ run: |
31
+ # NOTE: put your own distribution build steps here.
32
+ python -m pip install build
33
+ python -m build
34
+
35
+ - name: Upload distributions
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: release-dists
39
+ path: dist/
40
+
41
+ pypi-publish:
42
+ runs-on: ubuntu-latest
43
+ needs:
44
+ - release-build
45
+ permissions:
46
+ # IMPORTANT: this permission is mandatory for trusted publishing
47
+ id-token: write
48
+
49
+ # Dedicated environments with protections for publishing are strongly recommended.
50
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51
+ environment:
52
+ name: pypi
53
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54
+ # url: https://pypi.org/p/YOURPROJECT
55
+ #
56
+ # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57
+ # ALTERNATIVE: exactly, uncomment the following line instead:
58
+ # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
59
+
60
+ steps:
61
+ - name: Retrieve release distributions
62
+ uses: actions/download-artifact@v4
63
+ with:
64
+ name: release-dists
65
+ path: dist/
66
+
67
+ - name: Publish release distributions to PyPI
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ packages-dir: dist/
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
@@ -0,0 +1,7 @@
1
+ {
2
+ "python.analysis.typeCheckingMode": "standard",
3
+ "editor.rulers": [
4
+ 80,
5
+ 120
6
+ ]
7
+ }
lmfuser-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yintao Tai
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.
lmfuser-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: LMFuser
3
+ Version: 0.0.1
4
+ Summary: The LMFuser training framework.
5
+ Project-URL: Homepage, https://github.com/TYTTYTTYT/LMFuser
6
+ Project-URL: Documentation, https://github.com/TYTTYTTYT/LMFuser
7
+ Project-URL: Repository, https://github.com/TYTTYTTYT/LMFuser
8
+ Project-URL: Bug Tracker, https://github.com/TYTTYTTYT/LMFuser
9
+ Project-URL: Changelog, https://github.com/TYTTYTTYT/LMFuser
10
+ Author-email: Yintao Tai <tai.yintao@gmail.com>
11
+ Maintainer-email: Yintao Tai <tai.yintao@gmail.com>
12
+ License-File: LICENSE
13
+ Keywords: machine learning,pytorch
14
+ Classifier: Intended Audience :: Information Technology
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Utilities
18
+ Requires-Python: >=3.11
19
+ Requires-Dist: hyperargs>=0.1.3
20
+ Requires-Dist: lmfuser-data
21
+ Requires-Dist: numpy
22
+ Requires-Dist: pandas
23
+ Requires-Dist: pyarrow
24
+ Requires-Dist: torch
25
+ Requires-Dist: tqdm
26
+ Requires-Dist: wandb
27
+ Description-Content-Type: text/markdown
28
+
29
+ # LMFuser
30
+ A robust, multi-task PyTorch framework for training versatile Language Models at scale.
@@ -0,0 +1,2 @@
1
+ # LMFuser
2
+ A robust, multi-task PyTorch framework for training versatile Language Models at scale.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["hatchling >= 1.26"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "LMFuser"
7
+ version = "0.0.1"
8
+ requires-python = ">= 3.11"
9
+ description = "The LMFuser training framework."
10
+ readme = "README.md"
11
+ keywords = ["machine learning", "pytorch"]
12
+ classifiers = [
13
+ "Topic :: Utilities",
14
+ "Programming Language :: Python :: 3 :: Only",
15
+ "Intended Audience :: Science/Research",
16
+ "Intended Audience :: Information Technology"
17
+ ]
18
+ dependencies = [
19
+ "numpy",
20
+ "pandas",
21
+ "pyarrow",
22
+ "torch",
23
+ "LMFuser-data",
24
+ "tqdm",
25
+ "wandb",
26
+ "HyperArgs>=0.1.3",
27
+ ]
28
+ authors = [
29
+ {name = "Yintao Tai", email = "tai.yintao@gmail.com"},
30
+ ]
31
+ maintainers = [
32
+ {name = "Yintao Tai", email = "tai.yintao@gmail.com"},
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/TYTTYTTYT/LMFuser"
37
+ Documentation = "https://github.com/TYTTYTTYT/LMFuser"
38
+ Repository = "https://github.com/TYTTYTTYT/LMFuser"
39
+ "Bug Tracker" = "https://github.com/TYTTYTTYT/LMFuser"
40
+ Changelog = "https://github.com/TYTTYTTYT/LMFuser"
41
+
42
+ [tool.hatch.build.targets.wheel]
43
+ packages = ["src/lmfuser"]
File without changes
@@ -0,0 +1,33 @@
1
+ from os import PathLike
2
+
3
+ from torch import nn
4
+ from lmfuser_data.interfaces import SubclassTracer
5
+ from hyperargs import Conf, StrArg, OptionArg
6
+
7
+
8
+ class ModelLoader(SubclassTracer):
9
+ def __init__(self, model_path: str | PathLike):
10
+ self.model_path = model_path
11
+
12
+ def load_model(self) -> nn.Module:
13
+ raise NotImplementedError(f'Not implemented load_model for {self.__class__.__name__}')
14
+
15
+ @classmethod
16
+ def save_model(cls, model: nn.Module, directory: str | PathLike) -> None:
17
+ raise NotImplementedError(f'Not implemented save_model for {model.__class__.__name__}')
18
+
19
+ def find_model_loader_names() -> list[str]:
20
+ return list(ModelLoader.all_subclass_names()) + ['ModelLoader']
21
+
22
+
23
+ class ModelLoaderConf(Conf):
24
+ model_path = StrArg('please set model path here!')
25
+ model_type = OptionArg(default='ModelLoader', option_fn=find_model_loader_names)
26
+
27
+ def get_model_loader(self) -> ModelLoader:
28
+ name = self.model_type.value()
29
+ path = self.model_path.value()
30
+ assert name is not None and path is not None
31
+ if name == 'ModelLoader':
32
+ return ModelLoader(path)
33
+ return ModelLoader.all_subclass_map()[name](path)
@@ -0,0 +1,162 @@
1
+ from typing import Iterable
2
+
3
+ import torch
4
+ from torch.nn.parameter import Parameter as Parameter
5
+ from torch.optim import (
6
+ Optimizer,
7
+ Adam,
8
+ AdamW,
9
+ SGD,
10
+ Adadelta,
11
+ Adagrad
12
+ )
13
+ from hyperargs import Conf, OptionArg, FloatArg, BoolArg, add_dependency, monitor_on
14
+
15
+
16
+ class OptimizerConfigBase(Conf):
17
+
18
+ def init_optimzier(
19
+ self,
20
+ params: Iterable[Parameter],
21
+ ) -> Optimizer:
22
+ raise NotImplementedError(
23
+ 'Please Implement this method in child classes!'
24
+ )
25
+
26
+
27
+ class AdamWConfig(OptimizerConfigBase):
28
+
29
+ lr = FloatArg(5e-5, min_value=0.0)
30
+ beta1 = FloatArg(0.9, min_value=0.0, max_value=1.0)
31
+ beta2 = FloatArg(0.999, min_value=0.0, max_value=1.0)
32
+ eps = FloatArg(1e-8, min_value=0.0, max_value=1.0)
33
+ weight_decay = FloatArg(0.01, min_value=0.0, max_value=1.0)
34
+ amsgrad = BoolArg(False)
35
+
36
+ def init_optimzier(
37
+ self,
38
+ params: Iterable[Parameter],
39
+ ) -> Optimizer:
40
+ return AdamW(
41
+ params=params,
42
+ lr=self.lr.value(), # type: ignore
43
+ betas=(self.beta1.value(), self.beta2.value()), # type: ignore
44
+ eps=self.eps.value(), # type: ignore
45
+ weight_decay=self.weight_decay.value(), # type: ignore
46
+ amsgrad=self.amsgrad.value() # type: ignore
47
+ )
48
+
49
+
50
+ class AdamConfig(OptimizerConfigBase):
51
+
52
+ lr = FloatArg(5e-5, min_value=0.0)
53
+ beta1 = FloatArg(0.9, min_value=0.0, max_value=1.0)
54
+ beta2 = FloatArg(0.999, min_value=0.0, max_value=1.0)
55
+ eps = FloatArg(1e-8, min_value=0.0, max_value=1.0)
56
+ weight_decay = FloatArg(0.01, min_value=0.0, max_value=1.0)
57
+ amsgrad = BoolArg(False)
58
+
59
+ def init_optimzier(
60
+ self,
61
+ params: Iterable[Parameter]
62
+ ) -> Optimizer:
63
+ return Adam(
64
+ params=params,
65
+ lr=self.lr.value(), # type: ignore
66
+ betas=(self.beta1.value(), self.beta2.value()), # type: ignore
67
+ eps=self.eps.value(), # type: ignore
68
+ weight_decay=self.weight_decay.value(), # type: ignore
69
+ amsgrad=self.amsgrad.value() # type: ignore
70
+ )
71
+
72
+
73
+ class SGDConfig(OptimizerConfigBase):
74
+
75
+ lr = FloatArg(5e-5, min_value=0.0)
76
+ momentum = FloatArg(0.90, min_value=0.0, max_value=1.0)
77
+ dampening = FloatArg(0.0, min_value=0.0, max_value=1.0)
78
+ weight_decay = FloatArg(0.0, min_value=0.0, max_value=1.0)
79
+ nesterov = BoolArg(False)
80
+
81
+ def init_optimzier(
82
+ self,
83
+ params: Iterable[Parameter],
84
+ ) -> Optimizer:
85
+ return SGD(
86
+ params=params,
87
+ lr=self.lr.value(), # type: ignore
88
+ momentum=self.momentum.value(), # type: ignore
89
+ weight_decay=self.weight_decay.value(), # type: ignore
90
+ nesterov=self.nesterov.value() # type: ignore
91
+ )
92
+
93
+
94
+ class AdadeltaConfig(OptimizerConfigBase):
95
+
96
+ lr = FloatArg(1.0, min_value=0.0)
97
+ rho = FloatArg(0.9, min_value=0.0, max_value=1.0)
98
+ eps = FloatArg(1e-6, min_value=0.0, max_value=1.0)
99
+ weight_decay = FloatArg(0.0, min_value=0.0, max_value=1.0)
100
+
101
+ def init_optimzier(
102
+ self,
103
+ params: Iterable[Parameter]
104
+ ) -> Optimizer:
105
+ return Adadelta(
106
+ params=params,
107
+ lr=self.lr.value(), # type: ignore
108
+ rho=self.rho.value(), # type: ignore
109
+ eps=self.eps.value(), # type: ignore
110
+ weight_decay=self.weight_decay.value() # type: ignore
111
+ )
112
+
113
+
114
+ class AdagradConfig(OptimizerConfigBase):
115
+
116
+ lr = FloatArg(0.01, min_value=0.0)
117
+ lr_decay = FloatArg(0.0, min_value=0.0, max_value=1.0)
118
+ weight_decay = FloatArg(0.0, min_value=0.0, max_value=1.0)
119
+ initial_accumulator_value = FloatArg(0.0, min_value=0.0, max_value=1.0)
120
+ eps = FloatArg(1e-10, min_value=0.0, max_value=1.0)
121
+
122
+ def init_optimzier(
123
+ self,
124
+ params: Iterable[Parameter]
125
+ ) -> Optimizer:
126
+ return Adagrad(
127
+ params=params,
128
+ lr=self.lr.value(), # type: ignore
129
+ lr_decay=self.lr_decay.value(), # type: ignore
130
+ weight_decay=self.weight_decay.value(), # type: ignore
131
+ initial_accumulator_value=self.initial_accumulator_value.value(), # type: ignore
132
+ eps=self.eps.value() # type: ignore
133
+ )
134
+
135
+
136
+ @add_dependency('optimizer_type', 'optimizer')
137
+ class OptimizerConfig(Conf):
138
+ optimizer_type = OptionArg('AdamW', options=['AdamW', 'Adam', 'SGD', 'Adadelta', 'Adagrad'])
139
+ optimizer: OptimizerConfigBase = AdamWConfig()
140
+
141
+ @monitor_on('optimizer_type')
142
+ def set_optimizer(self) -> None:
143
+ if self.optimizer_type.value() == 'AdamW' and not isinstance(self.optimizer, AdamWConfig):
144
+ self.optimizer = AdamWConfig()
145
+ elif self.optimizer_type.value() == 'Adam' and not isinstance(self.optimizer, AdamConfig):
146
+ self.optimizer = AdamConfig()
147
+ elif self.optimizer_type.value() == 'SGD' and not isinstance(self.optimizer, SGDConfig):
148
+ self.optimizer = SGDConfig()
149
+ elif self.optimizer_type.value() == 'Adadelta' and not isinstance(self.optimizer, AdadeltaConfig):
150
+ self.optimizer = AdadeltaConfig()
151
+ elif self.optimizer_type.value() == 'Adagrad' and not isinstance(self.optimizer, AdagradConfig):
152
+ self.optimizer = AdagradConfig()
153
+
154
+ def init_optimzier(
155
+ self,
156
+ params: Iterable[Parameter]
157
+ ) -> Optimizer:
158
+ return self.optimizer.init_optimzier(params)
159
+
160
+ if __name__ == '__main__':
161
+ conf = OptimizerConfig.parse_command_line()
162
+ print(conf)
@@ -0,0 +1 @@
1
+ from .ddp_runner import DDPRunner, DDPRunnerConfig