kostyl-toolkit 0.1.2__py3-none-any.whl → 0.1.4__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.
- kostyl/ml_core/{configs/config_base.py → clearml/config_mixin.py} +6 -69
- kostyl/ml_core/configs/__init__.py +1 -1
- kostyl/ml_core/configs/base.py +54 -0
- kostyl/ml_core/configs/hyperparams.py +1 -1
- kostyl/ml_core/configs/training_params.py +3 -3
- kostyl/utils/fs.py +19 -0
- {kostyl_toolkit-0.1.2.dist-info → kostyl_toolkit-0.1.4.dist-info}/METADATA +8 -5
- {kostyl_toolkit-0.1.2.dist-info → kostyl_toolkit-0.1.4.dist-info}/RECORD +9 -7
- {kostyl_toolkit-0.1.2.dist-info → kostyl_toolkit-0.1.4.dist-info}/WHEEL +0 -0
|
@@ -2,80 +2,17 @@ from pathlib import Path
|
|
|
2
2
|
from typing import TypeVar
|
|
3
3
|
|
|
4
4
|
import clearml
|
|
5
|
-
import yaml
|
|
6
5
|
from caseconverter import pascalcase
|
|
7
6
|
from caseconverter import snakecase
|
|
8
7
|
from pydantic import BaseModel as PydanticBaseModel
|
|
9
8
|
|
|
10
|
-
from kostyl.
|
|
11
|
-
from kostyl.utils import
|
|
9
|
+
from kostyl.ml_core.configs.base import ConfigLoadingMixin
|
|
10
|
+
from kostyl.utils.dict_manipulations import convert_to_flat_dict
|
|
11
|
+
from kostyl.utils.dict_manipulations import flattened_dict_to_nested
|
|
12
|
+
from kostyl.utils.fs import load_config
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
"""Load a configuration from file."""
|
|
16
|
-
if isinstance(path, str):
|
|
17
|
-
path = Path(path)
|
|
18
|
-
|
|
19
|
-
if not path.is_file():
|
|
20
|
-
raise ValueError(f"Config file {path} does not exist or is not a file.")
|
|
21
|
-
|
|
22
|
-
match path.suffix:
|
|
23
|
-
case ".yaml" | ".yml":
|
|
24
|
-
config = yaml.safe_load(path.open("r"))
|
|
25
|
-
case _:
|
|
26
|
-
raise ValueError(f"Unsupported config file format: {path.suffix}")
|
|
27
|
-
return config
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
TConfig = TypeVar("TConfig", bound=PydanticBaseModel)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class ConfigLoadingMixin:
|
|
34
|
-
"""Pydantic mixin class providing basic configuration loading functionality."""
|
|
35
|
-
|
|
36
|
-
@classmethod
|
|
37
|
-
def from_file(
|
|
38
|
-
cls: type[TConfig], # pyright: ignore
|
|
39
|
-
path: str | Path,
|
|
40
|
-
) -> TConfig:
|
|
41
|
-
"""
|
|
42
|
-
Create an instance of the class from a configuration file.
|
|
43
|
-
|
|
44
|
-
Args:
|
|
45
|
-
cls_: The class type to instantiate.
|
|
46
|
-
path (str | Path): Path to the configuration file.
|
|
47
|
-
|
|
48
|
-
Returns:
|
|
49
|
-
An instance of the class created from the configuration file.
|
|
50
|
-
|
|
51
|
-
"""
|
|
52
|
-
config = load_config(path)
|
|
53
|
-
instance = cls.model_validate(config)
|
|
54
|
-
return instance
|
|
55
|
-
|
|
56
|
-
@classmethod
|
|
57
|
-
def from_dict(
|
|
58
|
-
cls: type[TConfig], # pyright: ignore
|
|
59
|
-
state_dict: dict,
|
|
60
|
-
) -> TConfig:
|
|
61
|
-
"""
|
|
62
|
-
Creates an instance from a dictionary.
|
|
63
|
-
|
|
64
|
-
Args:
|
|
65
|
-
cls_: The class type to instantiate.
|
|
66
|
-
state_dict (dict): A dictionary representing the state of the
|
|
67
|
-
class that must be validated and used for initialization.
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
An initialized instance of the class based on the
|
|
71
|
-
provided state dictionary.
|
|
72
|
-
|
|
73
|
-
"""
|
|
74
|
-
instance = cls.model_validate(state_dict)
|
|
75
|
-
return instance
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
TModel = TypeVar("TModel", bound="ClearMLBaseModel")
|
|
15
|
+
TModel = TypeVar("TModel", bound="_ClearMLBaseModel")
|
|
79
16
|
|
|
80
17
|
|
|
81
18
|
class ClearMLConfigMixin(ConfigLoadingMixin):
|
|
@@ -155,7 +92,7 @@ class ClearMLConfigMixin(ConfigLoadingMixin):
|
|
|
155
92
|
return model
|
|
156
93
|
|
|
157
94
|
|
|
158
|
-
class
|
|
95
|
+
class _ClearMLBaseModel(PydanticBaseModel, ClearMLConfigMixin):
|
|
159
96
|
"""A Pydantic model class with ClearML configuration loading and syncing functionality."""
|
|
160
97
|
|
|
161
98
|
pass
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import TypeVar
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel as PydanticBaseModel
|
|
5
|
+
|
|
6
|
+
from kostyl.utils.fs import load_config
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
TConfig = TypeVar("TConfig", bound=PydanticBaseModel)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ConfigLoadingMixin:
|
|
13
|
+
"""Pydantic mixin class providing basic configuration loading functionality."""
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def from_file(
|
|
17
|
+
cls: type[TConfig], # pyright: ignore
|
|
18
|
+
path: str | Path,
|
|
19
|
+
) -> TConfig:
|
|
20
|
+
"""
|
|
21
|
+
Create an instance of the class from a configuration file.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
cls_: The class type to instantiate.
|
|
25
|
+
path (str | Path): Path to the configuration file.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
An instance of the class created from the configuration file.
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
config = load_config(path)
|
|
32
|
+
instance = cls.model_validate(config)
|
|
33
|
+
return instance
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def from_dict(
|
|
37
|
+
cls: type[TConfig], # pyright: ignore
|
|
38
|
+
state_dict: dict,
|
|
39
|
+
) -> TConfig:
|
|
40
|
+
"""
|
|
41
|
+
Creates an instance from a dictionary.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
cls_: The class type to instantiate.
|
|
45
|
+
state_dict (dict): A dictionary representing the state of the
|
|
46
|
+
class that must be validated and used for initialization.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
An initialized instance of the class based on the
|
|
50
|
+
provided state dictionary.
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
instance = cls.model_validate(state_dict)
|
|
54
|
+
return instance
|
|
@@ -3,10 +3,10 @@ from typing import Literal
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
from pydantic import Field
|
|
5
5
|
|
|
6
|
+
from kostyl.ml_core.clearml.config_mixin import ClearMLConfigMixin
|
|
6
7
|
from kostyl.utils.logging import setup_logger
|
|
7
8
|
|
|
8
|
-
from .
|
|
9
|
-
from .config_base import ConfigLoadingMixin
|
|
9
|
+
from .base import ConfigLoadingMixin
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
logger = setup_logger(fmt="only_message")
|
|
@@ -101,8 +101,8 @@ class TrainingParams(BaseModel, ConfigLoadingMixin):
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
class ClearMLTrainingParameters(
|
|
104
|
+
ClearMLConfigMixin,
|
|
104
105
|
TrainingParams,
|
|
105
|
-
ClearMLBaseModel,
|
|
106
106
|
):
|
|
107
107
|
"""Training parameters configuration with ClearML features support (config syncing, model identifiers tracking and etc)."""
|
|
108
108
|
|
kostyl/utils/fs.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import yaml
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def load_config(path: Path | str) -> dict:
|
|
7
|
+
"""Load a configuration from file."""
|
|
8
|
+
if isinstance(path, str):
|
|
9
|
+
path = Path(path)
|
|
10
|
+
|
|
11
|
+
if not path.is_file():
|
|
12
|
+
raise ValueError(f"Config file {path} does not exist or is not a file.")
|
|
13
|
+
|
|
14
|
+
match path.suffix:
|
|
15
|
+
case ".yaml" | ".yml":
|
|
16
|
+
config = yaml.safe_load(path.open("r"))
|
|
17
|
+
case _:
|
|
18
|
+
raise ValueError(f"Unsupported config file format: {path.suffix}")
|
|
19
|
+
return config
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: kostyl-toolkit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Kickass Orchestration System for Training, Yielding & Logging
|
|
5
5
|
Requires-Dist: case-converter>=1.2.0
|
|
6
|
-
Requires-Dist: clearml[s3]>=2.0.2
|
|
7
|
-
Requires-Dist: lightning>=2.5.6
|
|
8
6
|
Requires-Dist: loguru>=0.7.3
|
|
9
|
-
Requires-Dist:
|
|
10
|
-
Requires-Dist:
|
|
7
|
+
Requires-Dist: case-converter>=1.2.0 ; extra == 'ml-core'
|
|
8
|
+
Requires-Dist: clearml[s3]>=2.0.2 ; extra == 'ml-core'
|
|
9
|
+
Requires-Dist: lightning>=2.5.6 ; extra == 'ml-core'
|
|
10
|
+
Requires-Dist: pydantic>=2.12.4 ; extra == 'ml-core'
|
|
11
|
+
Requires-Dist: torch>=2.9.1 ; extra == 'ml-core'
|
|
12
|
+
Requires-Dist: transformers>=4.57.1 ; extra == 'ml-core'
|
|
11
13
|
Requires-Python: >=3.12
|
|
14
|
+
Provides-Extra: ml-core
|
|
12
15
|
Description-Content-Type: text/markdown
|
|
13
16
|
|
|
14
17
|
# Kostyl Toolkit
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
kostyl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
kostyl/ml_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
kostyl/ml_core/clearml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
kostyl/ml_core/clearml/config_mixin.py,sha256=a3YO8kocbiJMSRKcnEIYZlHe_-jvozIh0t_CFcBd1MU,3610
|
|
4
5
|
kostyl/ml_core/clearml/logging_utils.py,sha256=GBjIIZbH_itd5sj7XpvxjkyZwxxGOpEcQ3BiWaJTyq8,1210
|
|
5
6
|
kostyl/ml_core/clearml/pulling_utils.py,sha256=Yf70ux8dS0_ENdvfbNQkXOrDxwd4ed2GnRCmOR2ppEk,3252
|
|
6
|
-
kostyl/ml_core/configs/__init__.py,sha256=
|
|
7
|
-
kostyl/ml_core/configs/
|
|
8
|
-
kostyl/ml_core/configs/hyperparams.py,sha256=
|
|
9
|
-
kostyl/ml_core/configs/training_params.py,sha256=
|
|
7
|
+
kostyl/ml_core/configs/__init__.py,sha256=AcLsl_aGnUuhEtNxfZWYbrKMfJrCAf47laPNeOKPfT4,889
|
|
8
|
+
kostyl/ml_core/configs/base.py,sha256=4trY_fO_VnguNrwT0BgSSoxmnG8BS_z9mEsgX6DmaNU,1467
|
|
9
|
+
kostyl/ml_core/configs/hyperparams.py,sha256=36sJKOy5PzEFYuEOtmLfjvLUqKYoJqidIs3D2AkxbYA,2967
|
|
10
|
+
kostyl/ml_core/configs/training_params.py,sha256=vYZUcOPNQNGLoMD9_-RCO9t72D8z7AwUU5JumkncYBk,2618
|
|
10
11
|
kostyl/ml_core/dist_utils.py,sha256=G8atjzkRbXZZiZh9rdEYBmeXqX26rJdDDovft2n6xiU,3201
|
|
11
12
|
kostyl/ml_core/lightning/__init__.py,sha256=-F3JAyq8KU1d-nACWryGu8d1CbvWbQ1rXFdeRwfE2X8,175
|
|
12
13
|
kostyl/ml_core/lightning/callbacks/__init__.py,sha256=Vd-rozY4T9Prr3IMqbliXxj6sC6y9XsovHQqRwzc2HI,297
|
|
@@ -27,7 +28,8 @@ kostyl/ml_core/schedulers/composite.py,sha256=ee4xlMDMMtjKPkbTF2ue9GTr9DuGCGjZWf
|
|
|
27
28
|
kostyl/ml_core/schedulers/cosine.py,sha256=jufULVHn_L_ZZEc3ZTG3QCY_pc0jlAMH5Aw496T31jo,8203
|
|
28
29
|
kostyl/utils/__init__.py,sha256=hkpmB6c5pr4Ti5BshOROebb7cvjDZfNCw83qZ_FFKMM,240
|
|
29
30
|
kostyl/utils/dict_manipulations.py,sha256=e3vBicID74nYP8lHkVTQc4-IQwoJimrbFELy5uSF6Gk,1073
|
|
31
|
+
kostyl/utils/fs.py,sha256=gAQNIU4R_2DhwjgzOS8BOMe0gZymtY1eZwmdgOdDgqo,510
|
|
30
32
|
kostyl/utils/logging.py,sha256=3MvfDPArZhwakHu5nMlp_LpOsWg0E0SP26y41clsBtA,5232
|
|
31
|
-
kostyl_toolkit-0.1.
|
|
32
|
-
kostyl_toolkit-0.1.
|
|
33
|
-
kostyl_toolkit-0.1.
|
|
33
|
+
kostyl_toolkit-0.1.4.dist-info/WHEEL,sha256=YUH1mBqsx8Dh2cQG2rlcuRYUhJddG9iClegy4IgnHik,79
|
|
34
|
+
kostyl_toolkit-0.1.4.dist-info/METADATA,sha256=z6AS38rjYUVQ8fLML3yHP8LBlpTTBg8OOqYDQFjqBg8,4268
|
|
35
|
+
kostyl_toolkit-0.1.4.dist-info/RECORD,,
|
|
File without changes
|