kostyl-toolkit 0.1.4__py3-none-any.whl → 0.1.6__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/clearml/dataset_utils.py +61 -0
- kostyl/ml_core/configs/hyperparams.py +2 -3
- kostyl/ml_core/lightning/extenstions/pretrained_model.py +3 -3
- {kostyl_toolkit-0.1.4.dist-info → kostyl_toolkit-0.1.6.dist-info}/METADATA +1 -1
- {kostyl_toolkit-0.1.4.dist-info → kostyl_toolkit-0.1.6.dist-info}/RECORD +6 -5
- {kostyl_toolkit-0.1.4.dist-info → kostyl_toolkit-0.1.6.dist-info}/WHEEL +1 -1
|
@@ -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()}
|
|
@@ -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)
|
|
@@ -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
|
|
@@ -2,11 +2,12 @@ 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
4
|
kostyl/ml_core/clearml/config_mixin.py,sha256=a3YO8kocbiJMSRKcnEIYZlHe_-jvozIh0t_CFcBd1MU,3610
|
|
5
|
+
kostyl/ml_core/clearml/dataset_utils.py,sha256=mkuXqLXjuxR2UUeVwV_NdToILOObOse88ItdfIyyx04,1812
|
|
5
6
|
kostyl/ml_core/clearml/logging_utils.py,sha256=GBjIIZbH_itd5sj7XpvxjkyZwxxGOpEcQ3BiWaJTyq8,1210
|
|
6
7
|
kostyl/ml_core/clearml/pulling_utils.py,sha256=Yf70ux8dS0_ENdvfbNQkXOrDxwd4ed2GnRCmOR2ppEk,3252
|
|
7
8
|
kostyl/ml_core/configs/__init__.py,sha256=AcLsl_aGnUuhEtNxfZWYbrKMfJrCAf47laPNeOKPfT4,889
|
|
8
9
|
kostyl/ml_core/configs/base.py,sha256=4trY_fO_VnguNrwT0BgSSoxmnG8BS_z9mEsgX6DmaNU,1467
|
|
9
|
-
kostyl/ml_core/configs/hyperparams.py,sha256=
|
|
10
|
+
kostyl/ml_core/configs/hyperparams.py,sha256=u-7FIM-cD3nz9Sycuvg7r0Vdiu4pduafiCoAxq8JK0s,3011
|
|
10
11
|
kostyl/ml_core/configs/training_params.py,sha256=vYZUcOPNQNGLoMD9_-RCO9t72D8z7AwUU5JumkncYBk,2618
|
|
11
12
|
kostyl/ml_core/dist_utils.py,sha256=G8atjzkRbXZZiZh9rdEYBmeXqX26rJdDDovft2n6xiU,3201
|
|
12
13
|
kostyl/ml_core/lightning/__init__.py,sha256=-F3JAyq8KU1d-nACWryGu8d1CbvWbQ1rXFdeRwfE2X8,175
|
|
@@ -16,7 +17,7 @@ kostyl/ml_core/lightning/callbacks/early_stopping.py,sha256=nEj3OkMNJkpQzR6pt0Z0
|
|
|
16
17
|
kostyl/ml_core/lightning/callbacks/registry_uploading.py,sha256=1aqT38FVOMQo4JphXcyjyK3ZY6A6HF1JBOsKqYNXar8,4706
|
|
17
18
|
kostyl/ml_core/lightning/extenstions/__init__.py,sha256=OY6QGv1agYgqqKf1xJBrxgp_i8FunVfPzYezfaRrGXU,182
|
|
18
19
|
kostyl/ml_core/lightning/extenstions/custom_module.py,sha256=8Z9iT7kdfLkzBQ8nLaCIxolXytiQqFVRLDSaNACjfK8,6146
|
|
19
|
-
kostyl/ml_core/lightning/extenstions/pretrained_model.py,sha256=
|
|
20
|
+
kostyl/ml_core/lightning/extenstions/pretrained_model.py,sha256=67ihzuO9J5AHpuE4f4qzL8XGJnA6c4LYaDyhXAGYnaw,4671
|
|
20
21
|
kostyl/ml_core/lightning/loggers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
22
|
kostyl/ml_core/lightning/loggers/tb_logger.py,sha256=Zh9n-lLu-bXMld-FIUO3lJfCyDf0IQFhS3JVShDJmvg,937
|
|
22
23
|
kostyl/ml_core/lightning/steps_estimation.py,sha256=fTZ0IrUEZV3H6VYlx4GYn56oco56mMiB7FO9F0Z7qc4,1511
|
|
@@ -30,6 +31,6 @@ kostyl/utils/__init__.py,sha256=hkpmB6c5pr4Ti5BshOROebb7cvjDZfNCw83qZ_FFKMM,240
|
|
|
30
31
|
kostyl/utils/dict_manipulations.py,sha256=e3vBicID74nYP8lHkVTQc4-IQwoJimrbFELy5uSF6Gk,1073
|
|
31
32
|
kostyl/utils/fs.py,sha256=gAQNIU4R_2DhwjgzOS8BOMe0gZymtY1eZwmdgOdDgqo,510
|
|
32
33
|
kostyl/utils/logging.py,sha256=3MvfDPArZhwakHu5nMlp_LpOsWg0E0SP26y41clsBtA,5232
|
|
33
|
-
kostyl_toolkit-0.1.
|
|
34
|
-
kostyl_toolkit-0.1.
|
|
35
|
-
kostyl_toolkit-0.1.
|
|
34
|
+
kostyl_toolkit-0.1.6.dist-info/WHEEL,sha256=AaqHSNJgTyoT6I9ETCXrbV_7cVSjA_q07lkDGeNjGdQ,79
|
|
35
|
+
kostyl_toolkit-0.1.6.dist-info/METADATA,sha256=S3AJNbTWSplf75-tGR-nGqNFubXyxJb4BLVYNvvE5Rk,4268
|
|
36
|
+
kostyl_toolkit-0.1.6.dist-info/RECORD,,
|