kostyl-toolkit 0.1.10__tar.gz → 0.1.11__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.10 → kostyl_toolkit-0.1.11}/PKG-INFO +1 -1
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/config_mixin.py +1 -1
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/pulling_utils.py +6 -3
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/hyperparams.py +1 -1
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/training_settings.py +1 -1
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/callbacks/checkpoint.py +2 -2
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/callbacks/early_stopping.py +1 -1
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/callbacks/registry_uploading.py +3 -3
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/extenstions/custom_module.py +12 -13
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/extenstions/pretrained_model.py +12 -2
- kostyl_toolkit-0.1.11/kostyl/ml/lightning/loggers/__init__.py +4 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/loggers/tb_logger.py +1 -1
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/pyproject.toml +1 -1
- kostyl_toolkit-0.1.10/kostyl/ml_core/lightning/loggers/__init__.py +0 -0
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/README.md +0 -0
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/kostyl/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/dataset_utils.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/logging_utils.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/base_model.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/dist_utils.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/callbacks/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/extenstions/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/steps_estimation.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/metrics_formatting.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/params_groups.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/__init__.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/base.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/composite.py +0 -0
- {kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/cosine.py +0 -0
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/kostyl/utils/__init__.py +0 -0
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/kostyl/utils/dict_manipulations.py +0 -0
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/kostyl/utils/fs.py +0 -0
- {kostyl_toolkit-0.1.10 → kostyl_toolkit-0.1.11}/kostyl/utils/logging.py +0 -0
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/config_mixin.py
RENAMED
|
@@ -5,7 +5,7 @@ import clearml
|
|
|
5
5
|
from caseconverter import pascalcase
|
|
6
6
|
from caseconverter import snakecase
|
|
7
7
|
|
|
8
|
-
from kostyl.
|
|
8
|
+
from kostyl.ml.configs.base_model import KostylBaseModel
|
|
9
9
|
from kostyl.utils.dict_manipulations import convert_to_flat_dict
|
|
10
10
|
from kostyl.utils.dict_manipulations import flattened_dict_to_nested
|
|
11
11
|
from kostyl.utils.fs import load_config
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/pulling_utils.py
RENAMED
|
@@ -3,12 +3,13 @@ from typing import cast
|
|
|
3
3
|
|
|
4
4
|
from clearml import InputModel
|
|
5
5
|
from clearml import Task
|
|
6
|
+
from transformers import Any
|
|
6
7
|
from transformers import AutoModel
|
|
7
8
|
from transformers import AutoTokenizer
|
|
8
9
|
from transformers import PreTrainedModel
|
|
9
10
|
from transformers import PreTrainedTokenizerBase
|
|
10
11
|
|
|
11
|
-
from kostyl.
|
|
12
|
+
from kostyl.ml.lightning.extenstions.pretrained_model import (
|
|
12
13
|
LightningCheckpointLoaderMixin,
|
|
13
14
|
)
|
|
14
15
|
|
|
@@ -48,6 +49,7 @@ def get_model_from_clearml[
|
|
|
48
49
|
model: type[TModel],
|
|
49
50
|
task: Task | None = None,
|
|
50
51
|
ignore_remote_overrides: bool = True,
|
|
52
|
+
**kwargs: Any,
|
|
51
53
|
) -> TModel:
|
|
52
54
|
"""
|
|
53
55
|
Retrieve a pretrained model from ClearML and instantiate it using the appropriate loader.
|
|
@@ -59,6 +61,7 @@ def get_model_from_clearml[
|
|
|
59
61
|
will be connected to this task, with remote overrides optionally ignored.
|
|
60
62
|
ignore_remote_overrides: When connecting the input model to the provided task, determines whether
|
|
61
63
|
remote configuration overrides should be ignored.
|
|
64
|
+
**kwargs: Additional keyword arguments to pass to the model loading method.
|
|
62
65
|
|
|
63
66
|
Returns:
|
|
64
67
|
An instantiated model loaded either from a ClearML package directory or a Lightning checkpoint.
|
|
@@ -72,13 +75,13 @@ def get_model_from_clearml[
|
|
|
72
75
|
local_path = Path(input_model.get_local_copy(raise_on_error=True))
|
|
73
76
|
|
|
74
77
|
if local_path.is_dir() and input_model._is_package():
|
|
75
|
-
model_instance = model.from_pretrained(local_path)
|
|
78
|
+
model_instance = model.from_pretrained(local_path, **kwargs)
|
|
76
79
|
elif local_path.suffix == ".ckpt":
|
|
77
80
|
if not issubclass(model, LightningCheckpointLoaderMixin):
|
|
78
81
|
raise ValueError(
|
|
79
82
|
f"Model class {model.__name__} is not compatible with Lightning checkpoints."
|
|
80
83
|
)
|
|
81
|
-
model_instance = model.from_lighting_checkpoint(local_path)
|
|
84
|
+
model_instance = model.from_lighting_checkpoint(local_path, **kwargs)
|
|
82
85
|
else:
|
|
83
86
|
raise ValueError(
|
|
84
87
|
f"Unsupported model format for path: {local_path}. "
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/hyperparams.py
RENAMED
|
@@ -2,7 +2,7 @@ from pydantic import BaseModel
|
|
|
2
2
|
from pydantic import Field
|
|
3
3
|
from pydantic import model_validator
|
|
4
4
|
|
|
5
|
-
from kostyl.
|
|
5
|
+
from kostyl.ml.clearml.config_mixin import ClearMLConfigMixin
|
|
6
6
|
from kostyl.utils.logging import setup_logger
|
|
7
7
|
|
|
8
8
|
|
|
@@ -3,7 +3,7 @@ from typing import Literal
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
from pydantic import Field
|
|
5
5
|
|
|
6
|
-
from kostyl.
|
|
6
|
+
from kostyl.ml.clearml.config_mixin import ClearMLConfigMixin
|
|
7
7
|
from kostyl.utils.logging import setup_logger
|
|
8
8
|
|
|
9
9
|
from .base_model import KostylBaseModel
|
|
@@ -3,8 +3,8 @@ from shutil import rmtree
|
|
|
3
3
|
|
|
4
4
|
from lightning.pytorch.callbacks import ModelCheckpoint
|
|
5
5
|
|
|
6
|
-
from kostyl.
|
|
7
|
-
from kostyl.
|
|
6
|
+
from kostyl.ml.configs import CheckpointConfig
|
|
7
|
+
from kostyl.ml.dist_utils import is_main_process
|
|
8
8
|
from kostyl.utils import setup_logger
|
|
9
9
|
|
|
10
10
|
|
|
@@ -7,9 +7,9 @@ from lightning import Trainer
|
|
|
7
7
|
from lightning.pytorch.callbacks import Callback
|
|
8
8
|
from lightning.pytorch.callbacks import ModelCheckpoint
|
|
9
9
|
|
|
10
|
-
from kostyl.
|
|
11
|
-
from kostyl.
|
|
12
|
-
from kostyl.
|
|
10
|
+
from kostyl.ml.clearml.logging_utils import find_version_in_tags
|
|
11
|
+
from kostyl.ml.clearml.logging_utils import increment_version
|
|
12
|
+
from kostyl.ml.lightning import KostylLightningModule
|
|
13
13
|
from kostyl.utils.logging import setup_logger
|
|
14
14
|
|
|
15
15
|
|
|
@@ -15,9 +15,8 @@ from torchmetrics import MetricCollection
|
|
|
15
15
|
from transformers import PretrainedConfig
|
|
16
16
|
from transformers import PreTrainedModel
|
|
17
17
|
|
|
18
|
-
from kostyl.
|
|
19
|
-
from kostyl.
|
|
20
|
-
from kostyl.ml_core.schedulers.base import BaseScheduler
|
|
18
|
+
from kostyl.ml.metrics_formatting import apply_suffix
|
|
19
|
+
from kostyl.ml.schedulers.base import BaseScheduler
|
|
21
20
|
from kostyl.utils import setup_logger
|
|
22
21
|
|
|
23
22
|
|
|
@@ -28,7 +27,6 @@ class KostylLightningModule(L.LightningModule):
|
|
|
28
27
|
"""Custom PyTorch Lightning Module with logging, checkpointing, and distributed training utilities."""
|
|
29
28
|
|
|
30
29
|
model: PreTrainedModel | nn.Module | None
|
|
31
|
-
hyperparams: HyperparamsConfig
|
|
32
30
|
|
|
33
31
|
def get_process_group(self) -> ProcessGroup | None:
|
|
34
32
|
"""
|
|
@@ -70,6 +68,11 @@ class KostylLightningModule(L.LightningModule):
|
|
|
70
68
|
return model.config # type: ignore
|
|
71
69
|
return None
|
|
72
70
|
|
|
71
|
+
@property
|
|
72
|
+
def grad_clip_val(self) -> float | None:
|
|
73
|
+
"""Returns the gradient clipping value from hyperparameters if set."""
|
|
74
|
+
raise NotImplementedError
|
|
75
|
+
|
|
73
76
|
@override
|
|
74
77
|
def on_save_checkpoint(self, checkpoint: dict[str, Any]) -> None:
|
|
75
78
|
model = self.get_model()
|
|
@@ -93,20 +96,16 @@ class KostylLightningModule(L.LightningModule):
|
|
|
93
96
|
def on_before_optimizer_step(self, optimizer) -> None:
|
|
94
97
|
if self.model is None:
|
|
95
98
|
raise ValueError("Model must be configured before optimizer step.")
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if self.hyperparams.grad_clip_val is None:
|
|
99
|
+
|
|
100
|
+
grad_clip_val = self.grad_clip_val
|
|
101
|
+
if grad_clip_val is None:
|
|
100
102
|
return
|
|
101
103
|
|
|
102
104
|
if not isinstance(self.trainer.strategy, FSDPStrategy):
|
|
103
|
-
norm = torch.nn.utils.clip_grad_norm_(
|
|
104
|
-
self.parameters(), self.hyperparams.grad_clip_val
|
|
105
|
-
)
|
|
105
|
+
norm = torch.nn.utils.clip_grad_norm_(self.parameters(), grad_clip_val)
|
|
106
106
|
else:
|
|
107
107
|
module: FSDP = self.trainer.strategy.model # type: ignore
|
|
108
|
-
norm = module.clip_grad_norm_(
|
|
109
|
-
|
|
108
|
+
norm = module.clip_grad_norm_(grad_clip_val)
|
|
110
109
|
self.log(
|
|
111
110
|
"grad_norm",
|
|
112
111
|
norm,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
+
from typing import Any
|
|
2
3
|
from typing import cast
|
|
3
4
|
|
|
4
5
|
import torch
|
|
@@ -28,6 +29,7 @@ class LightningCheckpointLoaderMixin(PreTrainedModel):
|
|
|
28
29
|
config_key: str = "config",
|
|
29
30
|
weights_prefix: str = "model.",
|
|
30
31
|
should_log_incompatible_keys: bool = True,
|
|
32
|
+
**kwargs: Any,
|
|
31
33
|
) -> TModelInstance:
|
|
32
34
|
"""
|
|
33
35
|
Load a model from a Lightning checkpoint file.
|
|
@@ -48,6 +50,7 @@ class LightningCheckpointLoaderMixin(PreTrainedModel):
|
|
|
48
50
|
weights_prefix (str, optional): Prefix to strip from state dict keys. Defaults to "model.".
|
|
49
51
|
If not empty and doesn't end with ".", a "." is appended.
|
|
50
52
|
should_log_incompatible_keys (bool, optional): Whether to log incompatible keys. Defaults to True.
|
|
53
|
+
**kwargs: Additional keyword arguments to pass to the model loading method.
|
|
51
54
|
|
|
52
55
|
Returns:
|
|
53
56
|
TModelInstance: The loaded model instance.
|
|
@@ -75,10 +78,17 @@ class LightningCheckpointLoaderMixin(PreTrainedModel):
|
|
|
75
78
|
)
|
|
76
79
|
|
|
77
80
|
config_cls = cast(PretrainedConfig, type(cls.config_class))
|
|
78
|
-
|
|
81
|
+
config_dict = checkpoint_dict[config_key]
|
|
82
|
+
config_dict.update(kwargs)
|
|
83
|
+
config = config_cls.from_dict(config_dict)
|
|
84
|
+
|
|
85
|
+
kwargs_for_model = {}
|
|
86
|
+
for key in kwargs:
|
|
87
|
+
if not hasattr(config, key):
|
|
88
|
+
kwargs_for_model[key] = kwargs[key]
|
|
79
89
|
|
|
80
90
|
with torch.device("meta"):
|
|
81
|
-
model = cls(config)
|
|
91
|
+
model = cls(config, **kwargs_for_model)
|
|
82
92
|
|
|
83
93
|
if "peft_config" in checkpoint_dict:
|
|
84
94
|
if PeftConfig is None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/__init__.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/dataset_utils.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/clearml/logging_utils.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/__init__.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/configs/base_model.py
RENAMED
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/lightning/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/metrics_formatting.py
RENAMED
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/composite.py
RENAMED
|
File without changes
|
{kostyl_toolkit-0.1.10/kostyl/ml_core → kostyl_toolkit-0.1.11/kostyl/ml}/schedulers/cosine.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|