kostyl-toolkit 0.1.3__tar.gz → 0.1.6__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.
Files changed (36) hide show
  1. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/PKG-INFO +1 -1
  2. kostyl_toolkit-0.1.3/kostyl/ml_core/configs/config_base.py → kostyl_toolkit-0.1.6/kostyl/ml_core/clearml/config_mixin.py +6 -69
  3. kostyl_toolkit-0.1.6/kostyl/ml_core/clearml/dataset_utils.py +61 -0
  4. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/configs/__init__.py +1 -1
  5. kostyl_toolkit-0.1.6/kostyl/ml_core/configs/base.py +54 -0
  6. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/configs/hyperparams.py +2 -3
  7. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/configs/training_params.py +3 -3
  8. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/extenstions/pretrained_model.py +3 -3
  9. kostyl_toolkit-0.1.6/kostyl/utils/fs.py +19 -0
  10. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/pyproject.toml +1 -1
  11. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/README.md +0 -0
  12. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/__init__.py +0 -0
  13. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/__init__.py +0 -0
  14. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/clearml/__init__.py +0 -0
  15. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/clearml/logging_utils.py +0 -0
  16. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/clearml/pulling_utils.py +0 -0
  17. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/dist_utils.py +0 -0
  18. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/__init__.py +0 -0
  19. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/callbacks/__init__.py +0 -0
  20. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/callbacks/checkpoint.py +0 -0
  21. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/callbacks/early_stopping.py +0 -0
  22. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/callbacks/registry_uploading.py +0 -0
  23. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/extenstions/__init__.py +0 -0
  24. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/extenstions/custom_module.py +0 -0
  25. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/loggers/__init__.py +0 -0
  26. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/loggers/tb_logger.py +0 -0
  27. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/lightning/steps_estimation.py +0 -0
  28. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/metrics_formatting.py +0 -0
  29. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/params_groups.py +0 -0
  30. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/schedulers/__init__.py +0 -0
  31. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/schedulers/base.py +0 -0
  32. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/schedulers/composite.py +0 -0
  33. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/ml_core/schedulers/cosine.py +0 -0
  34. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/utils/__init__.py +0 -0
  35. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/utils/dict_manipulations.py +0 -0
  36. {kostyl_toolkit-0.1.3 → kostyl_toolkit-0.1.6}/kostyl/utils/logging.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: kostyl-toolkit
3
- Version: 0.1.3
3
+ Version: 0.1.6
4
4
  Summary: Kickass Orchestration System for Training, Yielding & Logging
5
5
  Requires-Dist: case-converter>=1.2.0
6
6
  Requires-Dist: loguru>=0.7.3
@@ -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.utils import convert_to_flat_dict
11
- from kostyl.utils import flattened_dict_to_nested
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
- def load_config(path: Path | str) -> dict:
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 ClearMLBaseModel(PydanticBaseModel, ClearMLConfigMixin):
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,61 @@
1
+ from concurrent.futures import ThreadPoolExecutor
2
+ from concurrent.futures import as_completed
3
+ from pathlib import Path
4
+
5
+ from clearml import Dataset as ClearMLDataset
6
+
7
+
8
+ def collect_clearml_datasets(
9
+ datasets_mapping: dict[str, str],
10
+ ) -> dict[str, ClearMLDataset]:
11
+ """
12
+ Collect ClearML datasets by dataset ID.
13
+
14
+ Args:
15
+ datasets_mapping: Mapping where keys are human-readable names and values
16
+ are ClearML dataset IDs.
17
+
18
+ Returns:
19
+ A mapping of dataset names to fetched `ClearMLDataset` instances.
20
+
21
+ """
22
+ datasets_list = {}
23
+ for name, dataset_id in datasets_mapping.items():
24
+ clearml_dataset = ClearMLDataset.get(dataset_id, alias=name)
25
+ datasets_list[name] = clearml_dataset
26
+ return datasets_list
27
+
28
+
29
+ def download_clearml_datasets(datasets_mapping: dict[str, ClearMLDataset]) -> None:
30
+ """
31
+ Download all ClearML datasets in parallel.
32
+
33
+ Args:
34
+ datasets_mapping: Mapping of dataset names to initialized
35
+ `ClearMLDataset` instances whose contents must be downloaded
36
+ locally.
37
+
38
+ """
39
+ with ThreadPoolExecutor() as executor:
40
+ futures = [
41
+ executor.submit(ds.get_local_copy) for ds in datasets_mapping.values()
42
+ ]
43
+ for future in as_completed(futures):
44
+ future.result()
45
+ return
46
+
47
+
48
+ def get_datasets_paths(datasets_mapping: dict[str, ClearMLDataset]) -> dict[str, Path]:
49
+ """
50
+ Return local filesystem paths for ClearML datasets.
51
+
52
+ Args:
53
+ datasets_mapping: Mapping of dataset names to initialized
54
+ `ClearMLDataset` instances.
55
+
56
+ Returns:
57
+ Mapping of dataset names to local `Path` objects pointing to the
58
+ downloaded dataset copies.
59
+
60
+ """
61
+ return {name: Path(ds.get_local_copy()) for name, ds in datasets_mapping.items()}
@@ -1,4 +1,4 @@
1
- from .config_base import ConfigLoadingMixin
1
+ from .base import ConfigLoadingMixin
2
2
  from .hyperparams import HyperparamsConfig
3
3
  from .hyperparams import Lr
4
4
  from .hyperparams import Optimizer
@@ -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
@@ -2,10 +2,9 @@ from pydantic import BaseModel
2
2
  from pydantic import Field
3
3
  from pydantic import model_validator
4
4
 
5
+ from kostyl.ml_core.clearml.config_mixin import ClearMLConfigMixin
5
6
  from kostyl.utils.logging import setup_logger
6
7
 
7
- from .config_base import ClearMLBaseModel
8
-
9
8
 
10
9
  logger = setup_logger(fmt="only_message")
11
10
 
@@ -75,7 +74,7 @@ class WeightDecay(BaseModel):
75
74
  return self
76
75
 
77
76
 
78
- class HyperparamsConfig(ClearMLBaseModel):
77
+ class HyperparamsConfig(BaseModel, ClearMLConfigMixin):
79
78
  """Model training hyperparameters configuration."""
80
79
 
81
80
  grad_clip_val: float | None = Field(default=None, gt=0, validate_default=False)
@@ -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 .config_base import ClearMLBaseModel
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
 
@@ -27,7 +27,7 @@ class LightningCheckpointLoaderMixin(PreTrainedModel):
27
27
  checkpoint_path: str | Path,
28
28
  config_key: str = "config",
29
29
  weights_prefix: str = "model.",
30
- log_incompatible: bool = True,
30
+ should_log_incompatible_keys: bool = True,
31
31
  ) -> TModelInstance:
32
32
  """
33
33
  Load a model from a Lightning checkpoint file.
@@ -47,7 +47,7 @@ class LightningCheckpointLoaderMixin(PreTrainedModel):
47
47
  Defaults to "config".
48
48
  weights_prefix (str, optional): Prefix to strip from state dict keys. Defaults to "model.".
49
49
  If not empty and doesn't end with ".", a "." is appended.
50
- log_incompatible (bool, optional): Whether to log incompatible keys. Defaults to True.
50
+ should_log_incompatible_keys (bool, optional): Whether to log incompatible keys. Defaults to True.
51
51
 
52
52
  Returns:
53
53
  TModelInstance: The loaded model instance.
@@ -110,6 +110,6 @@ class LightningCheckpointLoaderMixin(PreTrainedModel):
110
110
  )
111
111
  incompatible_keys["missing_keys"] = missing_keys
112
112
  incompatible_keys["unexpected_keys"] = unexpected_keys
113
- if log_incompatible:
113
+ if should_log_incompatible_keys:
114
114
  log_incompatible_keys(incompatible_keys=incompatible_keys, logger=logger)
115
115
  return model
@@ -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,6 +1,6 @@
1
1
  [project]
2
2
  name = "kostyl-toolkit"
3
- version = "0.1.3"
3
+ version = "0.1.6"
4
4
  description = "Kickass Orchestration System for Training, Yielding & Logging "
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
File without changes