kostyl-toolkit 0.1.4__tar.gz → 0.1.7__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.
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/PKG-INFO +1 -1
- kostyl_toolkit-0.1.7/kostyl/ml_core/clearml/dataset_utils.py +58 -0
- kostyl_toolkit-0.1.7/kostyl/ml_core/configs/__init__.py +30 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/configs/hyperparams.py +2 -3
- kostyl_toolkit-0.1.4/kostyl/ml_core/configs/training_params.py → kostyl_toolkit-0.1.7/kostyl/ml_core/configs/training_settings.py +4 -3
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/extenstions/pretrained_model.py +4 -4
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/pyproject.toml +1 -1
- kostyl_toolkit-0.1.4/kostyl/ml_core/configs/__init__.py +0 -30
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/README.md +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/clearml/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/clearml/config_mixin.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/clearml/logging_utils.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/clearml/pulling_utils.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/configs/base.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/dist_utils.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/checkpoint.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/early_stopping.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/registry_uploading.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/extenstions/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/extenstions/custom_module.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/loggers/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/loggers/tb_logger.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/steps_estimation.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/metrics_formatting.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/params_groups.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/schedulers/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/schedulers/base.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/schedulers/composite.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/schedulers/cosine.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/utils/__init__.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/utils/dict_manipulations.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/utils/fs.py +0 -0
- {kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/utils/logging.py +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from collections.abc import Collection
|
|
2
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
3
|
+
from concurrent.futures import as_completed
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from clearml import Dataset as ClearMLDataset
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def collect_clearml_datasets(
|
|
10
|
+
datasets_mapping: dict[str, str],
|
|
11
|
+
) -> dict[str, ClearMLDataset]:
|
|
12
|
+
"""
|
|
13
|
+
Collect ClearML datasets by dataset ID.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
datasets_mapping: Mapping where keys are human-readable names and values
|
|
17
|
+
are ClearML dataset IDs.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
A mapping of dataset names to fetched `ClearMLDataset` instances.
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
datasets_list = {}
|
|
24
|
+
for name, dataset_id in datasets_mapping.items():
|
|
25
|
+
clearml_dataset = ClearMLDataset.get(dataset_id, alias=name)
|
|
26
|
+
datasets_list[name] = clearml_dataset
|
|
27
|
+
return datasets_list
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def download_clearml_datasets(datasets: Collection[ClearMLDataset]) -> None:
|
|
31
|
+
"""
|
|
32
|
+
Download all ClearML datasets in parallel.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
datasets: Collection of initialized `ClearMLDataset` instances to download.
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
with ThreadPoolExecutor() as executor:
|
|
39
|
+
futures = [executor.submit(ds.get_local_copy) for ds in datasets]
|
|
40
|
+
for future in as_completed(futures):
|
|
41
|
+
future.result()
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_datasets_paths(datasets_mapping: dict[str, ClearMLDataset]) -> dict[str, Path]:
|
|
46
|
+
"""
|
|
47
|
+
Return local filesystem paths for ClearML datasets.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
datasets_mapping: Mapping of dataset names to initialized
|
|
51
|
+
`ClearMLDataset` instances.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
Mapping of dataset names to local `Path` objects pointing to the
|
|
55
|
+
downloaded dataset copies.
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
return {name: Path(ds.get_local_copy()) for name, ds in datasets_mapping.items()}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from .base import ConfigLoadingMixin
|
|
2
|
+
from .hyperparams import HyperparamsConfig
|
|
3
|
+
from .hyperparams import Lr
|
|
4
|
+
from .hyperparams import Optimizer
|
|
5
|
+
from .hyperparams import WeightDecay
|
|
6
|
+
from .training_settings import CheckpointConfig
|
|
7
|
+
from .training_settings import ClearMLTrainingSettings
|
|
8
|
+
from .training_settings import DataConfig
|
|
9
|
+
from .training_settings import DDPStrategyConfig
|
|
10
|
+
from .training_settings import EarlyStoppingConfig
|
|
11
|
+
from .training_settings import FSDP1StrategyConfig
|
|
12
|
+
from .training_settings import SingleDeviceStrategyConfig
|
|
13
|
+
from .training_settings import TrainingSettings
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"CheckpointConfig",
|
|
18
|
+
"ClearMLTrainingSettings",
|
|
19
|
+
"ConfigLoadingMixin",
|
|
20
|
+
"DDPStrategyConfig",
|
|
21
|
+
"DataConfig",
|
|
22
|
+
"EarlyStoppingConfig",
|
|
23
|
+
"FSDP1StrategyConfig",
|
|
24
|
+
"HyperparamsConfig",
|
|
25
|
+
"Lr",
|
|
26
|
+
"Optimizer",
|
|
27
|
+
"SingleDeviceStrategyConfig",
|
|
28
|
+
"TrainingSettings",
|
|
29
|
+
"WeightDecay",
|
|
30
|
+
]
|
|
@@ -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 .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(
|
|
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)
|
|
@@ -49,6 +49,7 @@ class DDPStrategyConfig(BaseModel):
|
|
|
49
49
|
"""Distributed Data Parallel (DDP) strategy configuration."""
|
|
50
50
|
|
|
51
51
|
type: Literal["ddp"]
|
|
52
|
+
find_unused_parameters: bool = False
|
|
52
53
|
|
|
53
54
|
|
|
54
55
|
class LightningTrainerParameters(BaseModel):
|
|
@@ -91,7 +92,7 @@ class DataConfig(BaseModel):
|
|
|
91
92
|
data_columns: list[str]
|
|
92
93
|
|
|
93
94
|
|
|
94
|
-
class
|
|
95
|
+
class TrainingSettings(BaseModel, ConfigLoadingMixin):
|
|
95
96
|
"""Training parameters configuration."""
|
|
96
97
|
|
|
97
98
|
trainer: LightningTrainerParameters
|
|
@@ -100,9 +101,9 @@ class TrainingParams(BaseModel, ConfigLoadingMixin):
|
|
|
100
101
|
data: DataConfig
|
|
101
102
|
|
|
102
103
|
|
|
103
|
-
class
|
|
104
|
+
class ClearMLTrainingSettings(
|
|
104
105
|
ClearMLConfigMixin,
|
|
105
|
-
|
|
106
|
+
TrainingSettings,
|
|
106
107
|
):
|
|
107
108
|
"""Training parameters configuration with ClearML features support (config syncing, model identifiers tracking and etc)."""
|
|
108
109
|
|
|
@@ -9,7 +9,7 @@ from transformers import PreTrainedModel
|
|
|
9
9
|
try:
|
|
10
10
|
from peft import PeftConfig
|
|
11
11
|
except ImportError:
|
|
12
|
-
PeftConfig = None
|
|
12
|
+
PeftConfig = None # ty: ignore
|
|
13
13
|
|
|
14
14
|
from kostyl.utils.logging import log_incompatible_keys
|
|
15
15
|
from kostyl.utils.logging import setup_logger
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
113
|
+
if should_log_incompatible_keys:
|
|
114
114
|
log_incompatible_keys(incompatible_keys=incompatible_keys, logger=logger)
|
|
115
115
|
return model
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
from .base import ConfigLoadingMixin
|
|
2
|
-
from .hyperparams import HyperparamsConfig
|
|
3
|
-
from .hyperparams import Lr
|
|
4
|
-
from .hyperparams import Optimizer
|
|
5
|
-
from .hyperparams import WeightDecay
|
|
6
|
-
from .training_params import CheckpointConfig
|
|
7
|
-
from .training_params import ClearMLTrainingParameters
|
|
8
|
-
from .training_params import DataConfig
|
|
9
|
-
from .training_params import DDPStrategyConfig
|
|
10
|
-
from .training_params import EarlyStoppingConfig
|
|
11
|
-
from .training_params import FSDP1StrategyConfig
|
|
12
|
-
from .training_params import SingleDeviceStrategyConfig
|
|
13
|
-
from .training_params import TrainingParams
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
__all__ = [
|
|
17
|
-
"CheckpointConfig",
|
|
18
|
-
"ClearMLTrainingParameters",
|
|
19
|
-
"ConfigLoadingMixin",
|
|
20
|
-
"DDPStrategyConfig",
|
|
21
|
-
"DataConfig",
|
|
22
|
-
"EarlyStoppingConfig",
|
|
23
|
-
"FSDP1StrategyConfig",
|
|
24
|
-
"HyperparamsConfig",
|
|
25
|
-
"Lr",
|
|
26
|
-
"Optimizer",
|
|
27
|
-
"SingleDeviceStrategyConfig",
|
|
28
|
-
"TrainingParams",
|
|
29
|
-
"WeightDecay",
|
|
30
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/__init__.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/checkpoint.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/callbacks/early_stopping.py
RENAMED
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/extenstions/__init__.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.4 → kostyl_toolkit-0.1.7}/kostyl/ml_core/lightning/extenstions/custom_module.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|