trainloop 0.4.0__tar.gz → 0.5.0__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.
- {trainloop-0.4.0 → trainloop-0.5.0}/PKG-INFO +1 -1
- {trainloop-0.4.0 → trainloop-0.5.0}/pyproject.toml +1 -1
- {trainloop-0.4.0 → trainloop-0.5.0}/src/trainloop/hooks.py +14 -5
- {trainloop-0.4.0 → trainloop-0.5.0}/src/trainloop/trainer.py +3 -1
- {trainloop-0.4.0 → trainloop-0.5.0}/README.md +0 -0
- {trainloop-0.4.0 → trainloop-0.5.0}/src/trainloop/__init__.py +0 -0
- {trainloop-0.4.0 → trainloop-0.5.0}/src/trainloop/py.typed +0 -0
- {trainloop-0.4.0 → trainloop-0.5.0}/src/trainloop/utils.py +0 -0
|
@@ -346,7 +346,8 @@ class CheckpointingHook(BaseHook):
|
|
|
346
346
|
Args:
|
|
347
347
|
interval: Save every ``interval`` steps.
|
|
348
348
|
keep_previous: Keep the last N checkpoints in addition to the latest.
|
|
349
|
-
keep_interval:
|
|
349
|
+
keep_interval: Save and keep checkpoints every ``keep_interval`` steps.
|
|
350
|
+
keep_steps: Save and keep checkpoints at these explicit step numbers.
|
|
350
351
|
path: Directory (relative to workspace unless absolute) for checkpoints.
|
|
351
352
|
load: Path to load at startup or ``\"latest\"`` to auto-resume.
|
|
352
353
|
exit_signals: Signals that trigger a checkpoint then exit.
|
|
@@ -358,7 +359,9 @@ class CheckpointingHook(BaseHook):
|
|
|
358
359
|
self,
|
|
359
360
|
interval: int,
|
|
360
361
|
keep_previous: int = 0, # keep N previous checkpoints
|
|
361
|
-
keep_interval: int = 0, # keep checkpoints of every N-th step
|
|
362
|
+
keep_interval: int = 0, # save and keep checkpoints of every N-th step
|
|
363
|
+
keep_steps: Sequence[int]
|
|
364
|
+
| None = None, # save and keep checkpoints at these steps
|
|
362
365
|
path: Path | str = "checkpoints",
|
|
363
366
|
load: Path | str | Literal["latest"] | None = "latest",
|
|
364
367
|
exit_signals: list[signal.Signals] | signal.Signals = None,
|
|
@@ -370,6 +373,7 @@ class CheckpointingHook(BaseHook):
|
|
|
370
373
|
self.interval = interval
|
|
371
374
|
self.keep_previous = keep_previous
|
|
372
375
|
self.keep_interval = keep_interval
|
|
376
|
+
self.keep_steps = set(keep_steps or [])
|
|
373
377
|
self.path = Path(path)
|
|
374
378
|
self.load_path = Path(load) if load is not None else None
|
|
375
379
|
|
|
@@ -435,18 +439,23 @@ class CheckpointingHook(BaseHook):
|
|
|
435
439
|
save_and_exit = exit_signal != -1
|
|
436
440
|
|
|
437
441
|
# NOTE: Check if last step here (not in on_after_train) to avoid saving twice
|
|
438
|
-
|
|
442
|
+
should_keep = trainer.step in self.keep_steps or (
|
|
443
|
+
self.keep_interval > 0 and trainer.step % self.keep_interval == 0
|
|
444
|
+
)
|
|
445
|
+
should_save = (
|
|
439
446
|
trainer.step % self.interval == 0
|
|
440
447
|
or trainer.step == trainer.max_steps
|
|
448
|
+
or should_keep
|
|
441
449
|
or save_and_exit
|
|
442
|
-
)
|
|
450
|
+
)
|
|
451
|
+
if should_save:
|
|
443
452
|
if save_and_exit:
|
|
444
453
|
trainer.logger.info(
|
|
445
454
|
f"=> Caught signal {exit_signal}. Saving checkpoint before exit ..."
|
|
446
455
|
)
|
|
447
456
|
self._save_checkpoint(
|
|
448
457
|
trainer,
|
|
449
|
-
keep=
|
|
458
|
+
keep=should_keep,
|
|
450
459
|
)
|
|
451
460
|
if save_and_exit:
|
|
452
461
|
_dist_barrier()
|
|
@@ -276,7 +276,9 @@ class BaseTrainer:
|
|
|
276
276
|
< self.max_non_finite_grad_retries
|
|
277
277
|
):
|
|
278
278
|
non_finite_grad_retry_count += 1
|
|
279
|
-
self.step_info["non_finite_grad_retry_count"] =
|
|
279
|
+
self.step_info["non_finite_grad_retry_count"] = (
|
|
280
|
+
non_finite_grad_retry_count
|
|
281
|
+
)
|
|
280
282
|
self.logger.warning(
|
|
281
283
|
f"Gradient is non-finite. Retrying step {self.step} (retry {non_finite_grad_retry_count}"
|
|
282
284
|
+ (
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|