trainloop 0.6.0__tar.gz → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: trainloop
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Minimal PyTorch training loop with hooks and checkpointing.
5
5
  Author: Karim Knaebel
6
6
  Author-email: Karim Knaebel <contact@knaebel.dev>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "trainloop"
3
- version = "0.6.0"
3
+ version = "0.7.0"
4
4
  description = "Minimal PyTorch training loop with hooks and checkpointing."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -597,7 +597,8 @@ class WandbHook(BaseHook):
597
597
  project: W&B project name.
598
598
  config: Optional config dict or JSON file path to log.
599
599
  tags: Optional tag list.
600
- image_format: File format for images or a callable to derive it per key.
600
+ image_format: File format for images or a callable taking the flattened
601
+ image key and returning the format.
601
602
  **wandb_kwargs: Extra arguments forwarded to ``wandb.init``.
602
603
  """
603
604
 
@@ -606,7 +607,7 @@ class WandbHook(BaseHook):
606
607
  project: str,
607
608
  config: dict[str, Any] | str | None = None,
608
609
  tags: Sequence[str] | None = None,
609
- image_format: str | None | Callable[[str], str | None] = "png",
610
+ image_format: str | None | Callable[[tuple[str, ...]], str | None] = "png",
610
611
  **wandb_kwargs,
611
612
  ):
612
613
  self.project = project
@@ -655,7 +656,7 @@ class WandbHook(BaseHook):
655
656
  if _dist_rank() == 0:
656
657
  wandb_data = {}
657
658
  for k, img in flatten_nested_dict({"vis": records}).items():
658
- file_type = self.image_format(k[-1])
659
+ file_type = self.image_format(k)
659
660
  wandb_data.setdefault("/".join(k[:-1]), []).append(
660
661
  wandb.Image(
661
662
  self._ensure_jpeg_compatible(img)
@@ -705,12 +706,12 @@ class ImageFileLoggerHook(BaseHook):
705
706
  """Persist logged images to ``workspace/visualizations`` on rank 0.
706
707
 
707
708
  Args:
708
- image_format: File extension or callable taking the leaf key.
709
+ image_format: File extension or callable taking the flattened image key.
709
710
  """
710
711
 
711
712
  def __init__(
712
713
  self,
713
- image_format: str | Callable[[str], str] = "png",
714
+ image_format: str | Callable[[tuple[str, ...]], str] = "png",
714
715
  ):
715
716
  if callable(image_format):
716
717
  self.image_format = image_format
@@ -721,7 +722,7 @@ class ImageFileLoggerHook(BaseHook):
721
722
  if _dist_rank() == 0:
722
723
  for k, img in flatten_nested_dict(records).items():
723
724
  p = trainer.workspace / "visualizations" / str(trainer.step) / Path(*k)
724
- p = Path(str(p) + "." + self.image_format(k[-1]))
725
+ p = Path(str(p) + "." + self.image_format(k))
725
726
  if not dry_run:
726
727
  p.parent.mkdir(parents=True, exist_ok=True)
727
728
  img.save(p)
File without changes