kostyl-toolkit 0.1.13__py3-none-any.whl → 0.1.15__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.
@@ -100,5 +100,5 @@ class TrainingSettings(KostylBaseModel):
100
100
 
101
101
  trainer: LightningTrainerParameters
102
102
  early_stopping: EarlyStoppingConfig | None = None
103
- checkpoint: CheckpointConfig
103
+ checkpoint: CheckpointConfig = CheckpointConfig()
104
104
  data: DataConfig
@@ -78,49 +78,41 @@ class ClearMLRegistryUploaderCallback(Callback):
78
78
  )
79
79
  return output_model
80
80
 
81
- @override
82
- def on_validation_epoch_end(
83
- self, trainer: Trainer, pl_module: KostylLightningModule
84
- ) -> None:
85
- if (not trainer.is_global_zero) or (
86
- self.uploading_frequency != "after-every-eval"
87
- ):
88
- return
81
+ def _upload_best_checkpoint(self, pl_module: KostylLightningModule) -> None:
89
82
  if self._output_model is None:
90
83
  self._output_model = self._create_output_model(pl_module)
91
84
 
92
- if self.ckpt_callback.best_model_path != self._last_best_model_path:
85
+ if self.ckpt_callback.best_model_path == self._last_best_model_path:
86
+ if self.verbose and (self._last_best_model_path != ""):
87
+ logger.info("Best model unchanged since last upload")
88
+ elif self.verbose:
89
+ logger.info("No best model found yet to upload")
90
+ else:
93
91
  if self.verbose:
94
- logger.info(f"Best model path: {self.ckpt_callback.best_model_path}")
92
+ logger.info(
93
+ f"Uploading best model from {self.ckpt_callback.best_model_path}"
94
+ )
95
95
  self._output_model.update_weights(
96
96
  self.ckpt_callback.best_model_path,
97
97
  auto_delete_file=False,
98
- async_enable=True,
98
+ async_enable=False,
99
99
  )
100
- self._last_best_model_path = self.ckpt_callback.best_model_path
101
- elif self.verbose:
102
- logger.info("Best model path: unchanged since last upload, skipping...")
100
+ return
101
+
102
+ @override
103
+ def on_validation_epoch_end(
104
+ self, trainer: Trainer, pl_module: KostylLightningModule
105
+ ) -> None:
106
+ if (not trainer.is_global_zero) or (
107
+ self.uploading_frequency != "after-every-eval"
108
+ ):
109
+ return
110
+ self._upload_best_checkpoint(pl_module)
103
111
  return
104
112
 
105
113
  @override
106
114
  def on_train_end(self, trainer: Trainer, pl_module: KostylLightningModule) -> None:
107
115
  if not trainer.is_global_zero:
108
116
  return
109
- if self._output_model is None:
110
- self._output_model = self._create_output_model(pl_module)
111
-
112
- if self.ckpt_callback.best_model_path != self._last_best_model_path:
113
- if self.verbose:
114
- logger.info(
115
- f"Best model path at the end of training: {self.ckpt_callback.best_model_path}"
116
- )
117
- self._output_model.update_weights(
118
- self.ckpt_callback.best_model_path,
119
- auto_delete_file=False,
120
- async_enable=False,
121
- )
122
- elif self.verbose:
123
- logger.info(
124
- "Best model path at the end of training: unchanged since last upload, skipping..."
125
- )
117
+ self._upload_best_checkpoint(pl_module)
126
118
  return
@@ -26,8 +26,6 @@ logger = setup_logger(fmt="only_message")
26
26
  class KostylLightningModule(L.LightningModule):
27
27
  """Custom PyTorch Lightning Module with logging, checkpointing, and distributed training utilities."""
28
28
 
29
- model: PreTrainedModel | nn.Module | None
30
-
31
29
  def get_process_group(self) -> ProcessGroup | None:
32
30
  """
33
31
  Retrieves the data parallel process group for distributed training.
@@ -54,16 +52,15 @@ class KostylLightningModule(L.LightningModule):
54
52
  dp_pg = dist.group.WORLD
55
53
  return dp_pg
56
54
 
57
- def get_model(self) -> PreTrainedModel | nn.Module:
55
+ @property
56
+ def model_instance(self) -> PreTrainedModel | nn.Module:
58
57
  """Returns the underlying model."""
59
- if self.model is None:
60
- raise ValueError("Model is not configured.")
61
- return self.model
58
+ raise NotImplementedError
62
59
 
63
60
  @property
64
61
  def model_config(self) -> PretrainedConfig | None:
65
62
  """Returns the model configuration if available."""
66
- model = self.get_model()
63
+ model = self.model_instance
67
64
  if hasattr(model, "config"):
68
65
  return model.config # type: ignore
69
66
  return None
@@ -75,7 +72,7 @@ class KostylLightningModule(L.LightningModule):
75
72
 
76
73
  @override
77
74
  def on_save_checkpoint(self, checkpoint: dict[str, Any]) -> None:
78
- model = self.get_model()
75
+ model = self.model_instance
79
76
  if hasattr(model, "config"):
80
77
  cfg = model.config
81
78
  if hasattr(cfg, "to_dict"):
@@ -94,9 +91,6 @@ class KostylLightningModule(L.LightningModule):
94
91
 
95
92
  @override
96
93
  def on_before_optimizer_step(self, optimizer) -> None:
97
- if self.model is None:
98
- raise ValueError("Model must be configured before optimizer step.")
99
-
100
94
  grad_clip_val = self.grad_clip_val
101
95
  if grad_clip_val is None:
102
96
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: kostyl-toolkit
3
- Version: 0.1.13
3
+ Version: 0.1.15
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
@@ -7,15 +7,15 @@ kostyl/ml/clearml/pulling_utils.py,sha256=-9EIMUu3daWLj99s_G5rJ_omykz1nPLqxBzBJ8
7
7
  kostyl/ml/configs/__init__.py,sha256=IetcivbqYGutowLqxdKp7QR4tkXKBr4m8t4Zkk9jHZU,911
8
8
  kostyl/ml/configs/base_model.py,sha256=Eofn14J9RsjpVx_J4rp6C19pDDCANU4hr3JtX-d0FpQ,4820
9
9
  kostyl/ml/configs/hyperparams.py,sha256=CaVNEvpW4LvlHhLsbe2FockIGI1mJufCqjH298nYgKE,2971
10
- kostyl/ml/configs/training_settings.py,sha256=CZBwVVmkpCUtXCnfC1RFGQGUemht5xbOI43rgg7cNeg,2535
10
+ kostyl/ml/configs/training_settings.py,sha256=0cyKF6EuTv6KgXC1g0Oy9zbwnMkDP4uXTJJO1TRQ0aY,2556
11
11
  kostyl/ml/dist_utils.py,sha256=G8atjzkRbXZZiZh9rdEYBmeXqX26rJdDDovft2n6xiU,3201
12
12
  kostyl/ml/lightning/__init__.py,sha256=-F3JAyq8KU1d-nACWryGu8d1CbvWbQ1rXFdeRwfE2X8,175
13
13
  kostyl/ml/lightning/callbacks/__init__.py,sha256=Vd-rozY4T9Prr3IMqbliXxj6sC6y9XsovHQqRwzc2HI,297
14
14
  kostyl/ml/lightning/callbacks/checkpoint.py,sha256=FooGeeUz6TtoXQglpcK16NWAmSX3fbu6wntRtK3a_Io,1936
15
15
  kostyl/ml/lightning/callbacks/early_stopping.py,sha256=D5nyjktCJ9XYAf28-kgXG8jORvXLl1N3nbDQnvValPM,615
16
- kostyl/ml/lightning/callbacks/registry_uploading.py,sha256=um-fHQUp-TSD_76rVZoNV2IMi05RFjKajGvMV7SAb6s,4691
16
+ kostyl/ml/lightning/callbacks/registry_uploading.py,sha256=AAohqTGigWMGLHt-yITAznIVsaDVXR_jisLDzFNzlu8,4275
17
17
  kostyl/ml/lightning/extenstions/__init__.py,sha256=OY6QGv1agYgqqKf1xJBrxgp_i8FunVfPzYezfaRrGXU,182
18
- kostyl/ml/lightning/extenstions/custom_module.py,sha256=N4kPObp4jqrCJscPKzJib3AkvcQQ3AHal7A1Cm3ZobA,6201
18
+ kostyl/ml/lightning/extenstions/custom_module.py,sha256=nB5jW7cqRD1tyh-q5LD2EtiFQwFkLXpnS9Yu6c5xMRg,5987
19
19
  kostyl/ml/lightning/extenstions/pretrained_model.py,sha256=ZOKtrVl095cwvI43wAz-Xdzu4l0v0lHH2mfh4WXwxKQ,5059
20
20
  kostyl/ml/lightning/loggers/__init__.py,sha256=e51dszaoJbuzwBkbdugmuDsPldoSO4yaRgmZUg1Bdy0,71
21
21
  kostyl/ml/lightning/loggers/tb_logger.py,sha256=I0WQV3SVVIds9kHhAYnN3SXodX64jfTk7_5gH-j3uzA,932
@@ -30,6 +30,6 @@ kostyl/utils/__init__.py,sha256=hkpmB6c5pr4Ti5BshOROebb7cvjDZfNCw83qZ_FFKMM,240
30
30
  kostyl/utils/dict_manipulations.py,sha256=e3vBicID74nYP8lHkVTQc4-IQwoJimrbFELy5uSF6Gk,1073
31
31
  kostyl/utils/fs.py,sha256=gAQNIU4R_2DhwjgzOS8BOMe0gZymtY1eZwmdgOdDgqo,510
32
32
  kostyl/utils/logging.py,sha256=3MvfDPArZhwakHu5nMlp_LpOsWg0E0SP26y41clsBtA,5232
33
- kostyl_toolkit-0.1.13.dist-info/WHEEL,sha256=3id4o64OvRm9dUknh3mMJNcfoTRK08ua5cU6DFyVy-4,79
34
- kostyl_toolkit-0.1.13.dist-info/METADATA,sha256=BX_FpC83Q61Mr4jBEjRj-xC5UGtZcQJJn3EoF-Dnx24,4269
35
- kostyl_toolkit-0.1.13.dist-info/RECORD,,
33
+ kostyl_toolkit-0.1.15.dist-info/WHEEL,sha256=3id4o64OvRm9dUknh3mMJNcfoTRK08ua5cU6DFyVy-4,79
34
+ kostyl_toolkit-0.1.15.dist-info/METADATA,sha256=ieM22BLWafdzv4x7f7zaCz_Yhbe1Qce22w0L2i3mK-c,4269
35
+ kostyl_toolkit-0.1.15.dist-info/RECORD,,