tensorneko 0.3.5__tar.gz → 0.3.6__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.
Files changed (98) hide show
  1. {tensorneko-0.3.5/src/tensorneko.egg-info → tensorneko-0.3.6}/PKG-INFO +2 -2
  2. {tensorneko-0.3.5 → tensorneko-0.3.6}/README.md +1 -1
  3. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/arch/binary_classifier.py +13 -8
  4. tensorneko-0.3.6/src/tensorneko/callback/gpu_stats_logger.py +68 -0
  5. tensorneko-0.3.6/src/tensorneko/callback/system_stats_logger.py +44 -0
  6. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/fid.py +2 -2
  7. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/neko_trainer.py +7 -3
  8. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/__init__.py +2 -1
  9. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/configuration.py +5 -3
  10. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/misc.py +2 -1
  11. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/type.py +0 -1
  12. tensorneko-0.3.6/src/tensorneko/version.txt +1 -0
  13. {tensorneko-0.3.5 → tensorneko-0.3.6/src/tensorneko.egg-info}/PKG-INFO +2 -2
  14. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko.egg-info/requires.txt +1 -1
  15. tensorneko-0.3.5/src/tensorneko/callback/gpu_stats_logger.py +0 -31
  16. tensorneko-0.3.5/src/tensorneko/callback/system_stats_logger.py +0 -22
  17. tensorneko-0.3.5/src/tensorneko/version.txt +0 -1
  18. {tensorneko-0.3.5 → tensorneko-0.3.6}/LICENSE +0 -0
  19. {tensorneko-0.3.5 → tensorneko-0.3.6}/setup.cfg +0 -0
  20. {tensorneko-0.3.5 → tensorneko-0.3.6}/setup.py +0 -0
  21. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/__init__.py +0 -0
  22. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/arch/__init__.py +0 -0
  23. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/arch/auto_encoder.py +0 -0
  24. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/arch/gan.py +0 -0
  25. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/arch/vqvae.py +0 -0
  26. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/arch/wgan.py +0 -0
  27. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/backend/__init__.py +0 -0
  28. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/__init__.py +0 -0
  29. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/display_metrics_callback.py +0 -0
  30. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/earlystop_lr.py +0 -0
  31. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/epoch_num_logger.py +0 -0
  32. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/epoch_time_logger.py +0 -0
  33. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/lr_logger.py +0 -0
  34. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/callback/nil_callback.py +0 -0
  35. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/dataset/__init__.py +0 -0
  36. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/dataset/list_dataset.py +0 -0
  37. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/dataset/nested_dataset.py +0 -0
  38. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/dataset/round_robin_dataset.py +0 -0
  39. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/dataset/sampler/__init__.py +0 -0
  40. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/dataset/sampler/sequential_iter_sampler.py +0 -0
  41. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/debug/__init__.py +0 -0
  42. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/__init__.py +0 -0
  43. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/enum.py +0 -0
  44. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/iou.py +0 -0
  45. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/psnr.py +0 -0
  46. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/secs.py +0 -0
  47. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/evaluation/ssim.py +0 -0
  48. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/io/__init__.py +0 -0
  49. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/io/mesh/__init__.py +0 -0
  50. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/io/mesh/mesh_reader.py +0 -0
  51. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/io/mesh/mesh_writer.py +0 -0
  52. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/io/reader.py +0 -0
  53. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/io/writer.py +0 -0
  54. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/__init__.py +0 -0
  55. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/aggregation.py +0 -0
  56. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/attention.py +0 -0
  57. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/concatenate.py +0 -0
  58. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/conv.py +0 -0
  59. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/linear.py +0 -0
  60. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/log.py +0 -0
  61. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/masked_conv2d.py +0 -0
  62. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/noise.py +0 -0
  63. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/patching.py +0 -0
  64. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/positional_embedding.py +0 -0
  65. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/reshape.py +0 -0
  66. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/stack.py +0 -0
  67. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/layer/vector_quantizer.py +0 -0
  68. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/__init__.py +0 -0
  69. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/dense.py +0 -0
  70. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/gated_conv.py +0 -0
  71. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/inception.py +0 -0
  72. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/mlp.py +0 -0
  73. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/residual.py +0 -0
  74. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/module/transformer.py +0 -0
  75. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/neko_model.py +0 -0
  76. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/neko_module.py +0 -0
  77. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/notebook/__init__.py +0 -0
  78. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/optim/__init__.py +0 -0
  79. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/optim/lr_scheduler/__init__.py +0 -0
  80. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/preprocess/__init__.py +0 -0
  81. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/preprocess/crop.py +0 -0
  82. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/preprocess/enum.py +0 -0
  83. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/preprocess/face_detector/__init__.py +0 -0
  84. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/preprocess/pad.py +0 -0
  85. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/preprocess/resize.py +0 -0
  86. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/dispatched_misc.py +0 -0
  87. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/reproducibility.py +0 -0
  88. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/util/string_getter.py +0 -0
  89. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/visualization/__init__.py +0 -0
  90. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/visualization/image_browser/__init__.py +0 -0
  91. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/visualization/log_graph.py +0 -0
  92. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/visualization/matplotlib.py +0 -0
  93. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko/visualization/watcher/__init__.py +0 -0
  94. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko.egg-info/SOURCES.txt +0 -0
  95. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko.egg-info/dependency_links.txt +0 -0
  96. {tensorneko-0.3.5 → tensorneko-0.3.6}/src/tensorneko.egg-info/top_level.txt +0 -0
  97. {tensorneko-0.3.5 → tensorneko-0.3.6}/test/test_library_info.py +0 -0
  98. {tensorneko-0.3.5 → tensorneko-0.3.6}/test/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tensorneko
3
- Version: 0.3.5
3
+ Version: 0.3.6
4
4
  Summary: Tensor Neural Engine Kompanion. An util library based on PyTorch and PyTorch Lightning.
5
5
  Home-page: https://github.com/ControlNet/tensorneko
6
6
  Author: ControlNet
@@ -38,7 +38,7 @@ License-File: LICENSE
38
38
  <div align="center">
39
39
  <a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
40
40
  <a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
41
- <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*/2.1.*-792EE5?style=flat-square&logo=lightning"></a>
41
+ <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*%20|%202.1.*-792EE5?style=flat-square&logo=lightning"></a>
42
42
  </div>
43
43
 
44
44
  <div align="center">
@@ -12,7 +12,7 @@
12
12
  <div align="center">
13
13
  <a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
14
14
  <a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
15
- <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*/2.1.*-792EE5?style=flat-square&logo=lightning"></a>
15
+ <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*%20|%202.1.*-792EE5?style=flat-square&logo=lightning"></a>
16
16
  </div>
17
17
 
18
18
  <div align="center">
@@ -1,18 +1,17 @@
1
- from abc import ABC
2
- from typing import Optional, Union, Sequence, Dict
1
+ from typing import Optional, Union, Sequence, Dict, Any
3
2
 
4
3
  from torch import Tensor
5
- from torch.nn import BCEWithLogitsLoss
4
+ from torch.nn import BCEWithLogitsLoss, Module
6
5
  from torch.optim import Adam
7
6
  from torchmetrics import Accuracy, F1Score, AUROC
8
7
 
9
8
  from ..neko_model import NekoModel
10
9
 
11
10
 
12
- class BinaryClassifier(NekoModel, ABC):
11
+ class BinaryClassifier(NekoModel):
13
12
 
14
- def __init__(self, model=None, learning_rate: float = 1e-4, distributed: bool = False):
15
- super().__init__()
13
+ def __init__(self, name, model: Module, learning_rate: float = 1e-4, distributed: bool = False):
14
+ super().__init__(name)
16
15
  self.save_hyperparameters()
17
16
  self.model = model
18
17
  self.learning_rate = learning_rate
@@ -23,8 +22,10 @@ class BinaryClassifier(NekoModel, ABC):
23
22
  self.auc_fn = AUROC(task="binary")
24
23
 
25
24
  @classmethod
26
- def from_module(cls, model, learning_rate: float = 1e-4, distributed=False):
27
- return cls(model, learning_rate, distributed)
25
+ def from_module(cls, model: Module, learning_rate: float = 1e-4, name: str = "binary_classifier",
26
+ distributed: bool = False
27
+ ):
28
+ return cls(name, model, learning_rate, distributed)
28
29
 
29
30
  def forward(self, x):
30
31
  return self.model(x)
@@ -49,6 +50,10 @@ class BinaryClassifier(NekoModel, ABC):
49
50
  ) -> Dict[str, Tensor]:
50
51
  return self.step(batch)
51
52
 
53
+ def predict_step(self, batch: Tensor, batch_idx: int, dataloader_idx: Optional[int] = None) -> Any:
54
+ x, y = batch
55
+ return self(x)
56
+
52
57
  def configure_optimizers(self):
53
58
  optimizer = Adam(self.parameters(), lr=self.learning_rate)
54
59
  return [optimizer]
@@ -0,0 +1,68 @@
1
+ from typing import Any
2
+
3
+ from lightning.pytorch import Callback, Trainer, LightningModule
4
+ from lightning.pytorch.utilities.types import STEP_OUTPUT
5
+
6
+
7
+ class GpuStatsLogger(Callback):
8
+ """Log GPU stats for each training epoch"""
9
+
10
+ def __init__(self, delay: float = 0.5, on_epoch: bool = True, on_step: bool = False):
11
+ try:
12
+ from gpumonitor.monitor import GPUStatMonitor
13
+ except ImportError:
14
+ raise ImportError("gpumonitor is required to use GPUStatsLogger")
15
+
16
+ self.monitor_epoch = GPUStatMonitor(delay=delay) if on_epoch else None
17
+ self.monitor_step = GPUStatMonitor(delay=delay) if on_step else None
18
+ self.on_epoch = on_epoch
19
+ self.on_step = on_step
20
+ assert self.on_epoch or self.on_step, "on_epoch and on_step cannot be both False"
21
+
22
+ def on_train_epoch_start(self, trainer: Trainer, pl_module: LightningModule) -> None:
23
+ if not self.on_epoch:
24
+ return
25
+ self.monitor_epoch.reset()
26
+
27
+ def on_train_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None:
28
+ if not self.on_epoch:
29
+ return
30
+ for gpu in self.monitor_epoch.average_stats.gpus:
31
+ logged_info = {
32
+ f"gpu{gpu.index}_memory_used_epoch": gpu.memory_used / 1024,
33
+ f"gpu{gpu.index}_memory_total_epoch": gpu.memory_total / 1024,
34
+ f"gpu{gpu.index}_memory_util_epoch": gpu.memory_used / gpu.memory_total,
35
+ f"gpu{gpu.index}_temperature_epoch": float(gpu.temperature),
36
+ f"gpu{gpu.index}_utilization_epoch": gpu.utilization / 100,
37
+ f"gpu{gpu.index}_power_draw_epoch": float(gpu.power_draw),
38
+ f"gpu{gpu.index}_power_percentage_epoch": gpu.power_draw / gpu.power_limit,
39
+ f"gpu{gpu.index}_fan_speed_epoch": float(gpu.fan_speed) if gpu.fan_speed is not None else 0.,
40
+ }
41
+ pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
42
+ pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
43
+
44
+ def on_train_batch_start(
45
+ self, trainer: Trainer, pl_module: LightningModule, batch: Any, batch_idx: int
46
+ ) -> None:
47
+ if not self.on_step:
48
+ return
49
+ self.monitor_step.reset()
50
+
51
+ def on_train_batch_end(
52
+ self, trainer: Trainer, pl_module: LightningModule, outputs: STEP_OUTPUT, batch: Any, batch_idx: int
53
+ ) -> None:
54
+ if not self.on_step:
55
+ return
56
+ for gpu in self.monitor_step.average_stats.gpus:
57
+ logged_info = {
58
+ f"gpu{gpu.index}_memory_used_step": gpu.memory_used / 1024,
59
+ f"gpu{gpu.index}_memory_total_step": gpu.memory_total / 1024,
60
+ f"gpu{gpu.index}_memory_util_step": gpu.memory_used / gpu.memory_total,
61
+ f"gpu{gpu.index}_temperature_step": float(gpu.temperature),
62
+ f"gpu{gpu.index}_utilization_step": gpu.utilization / 100,
63
+ f"gpu{gpu.index}_power_draw_step": float(gpu.power_draw),
64
+ f"gpu{gpu.index}_power_percentage_step": gpu.power_draw / gpu.power_limit,
65
+ f"gpu{gpu.index}_fan_speed_step": float(gpu.fan_speed) if gpu.fan_speed is not None else 0.,
66
+ }
67
+ pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
68
+ pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
@@ -0,0 +1,44 @@
1
+ from typing import Any
2
+
3
+ from lightning.pytorch import Callback, Trainer, LightningModule
4
+ from lightning.pytorch.utilities.types import STEP_OUTPUT
5
+
6
+
7
+ class SystemStatsLogger(Callback):
8
+ """Log system stats for each training epoch"""
9
+
10
+ def __init__(self, on_epoch: bool = True, on_step: bool = False):
11
+ try:
12
+ import psutil
13
+ except ImportError:
14
+ raise ImportError("psutil is required to use SystemStatsLogger")
15
+ self.psutil = psutil
16
+ self.on_epoch = on_epoch
17
+ self.on_step = on_step
18
+ assert self.on_epoch or self.on_step, "on_epoch and on_step cannot be both False"
19
+
20
+ def on_train_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None:
21
+ if not self.on_epoch:
22
+ return
23
+ cpu_usage = self.psutil.cpu_percent()
24
+ memory_usage = self.psutil.virtual_memory().percent
25
+ logged_info = {
26
+ "cpu_usage_epoch": cpu_usage,
27
+ "memory_usage_epoch": memory_usage
28
+ }
29
+ pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
30
+ pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
31
+
32
+ def on_train_batch_end(
33
+ self, trainer: Trainer, pl_module: LightningModule, outputs: STEP_OUTPUT, batch: Any, batch_idx: int
34
+ ) -> None:
35
+ if not self.on_step:
36
+ return
37
+ cpu_usage = self.psutil.cpu_percent()
38
+ memory_usage = self.psutil.virtual_memory().percent
39
+ logged_info = {
40
+ "cpu_usage_step": cpu_usage,
41
+ "memory_usage_step": memory_usage
42
+ }
43
+ pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
44
+ pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
@@ -90,8 +90,8 @@ class FID:
90
90
 
91
91
  if progress_bar:
92
92
  tqdm = import_tqdm_auto().tqdm
93
- pred = tqdm(total=len(pred), desc="Forward predicted features")
94
- true = tqdm(total=len(true), desc="Forward ground truth features")
93
+ pred = tqdm(pred, total=len(pred), desc="Forward predicted features")
94
+ true = tqdm(true, total=len(true), desc="Forward ground truth features")
95
95
 
96
96
  for batch in pred:
97
97
  self.fid.update(batch.to(self.device), real=False)
@@ -3,16 +3,20 @@ from datetime import timedelta
3
3
  from time import time
4
4
  from typing import Optional, Union, List, Dict
5
5
 
6
+ from lightning.fabric.plugins.precision.precision import _PRECISION_INPUT
7
+ from lightning.fabric.utilities.types import _PATH
6
8
  from lightning.pytorch import Trainer, Callback
7
9
  from lightning.pytorch.accelerators import Accelerator
8
10
  from lightning.pytorch.callbacks import ModelCheckpoint, Checkpoint
9
11
  from lightning.pytorch.loggers import Logger, TensorBoardLogger
10
- from lightning.pytorch.plugins import PLUGIN_INPUT
11
12
  from lightning.pytorch.profilers import Profiler
12
13
  from lightning.pytorch.strategies import Strategy
13
14
  from lightning.pytorch.trainer.connectors.accelerator_connector import _LITERAL_WARN
14
- from lightning.fabric.plugins.precision.precision import _PRECISION_INPUT
15
- from lightning.fabric.utilities.types import _PATH
15
+
16
+ try:
17
+ from lightning.pytorch.plugins import PLUGIN_INPUT
18
+ except ImportError:
19
+ from lightning.pytorch.plugins import _PLUGIN_INPUT as PLUGIN_INPUT
16
20
 
17
21
  from .callback import NilCallback, LrLogger, EpochNumLogger, EpochTimeLogger, GpuStatsLogger, SystemStatsLogger
18
22
 
@@ -9,7 +9,7 @@ from . import type
9
9
  from .configuration import Configuration
10
10
  from .misc import reduce_dict_by, summarize_dict_by, with_printed_shape, is_bad_num, count_parameters, compose, \
11
11
  generate_inf_seq, listdir, with_printed, ifelse, dict_add, as_list, identity, list_to_dict, circular_pad, \
12
- load_py, try_until_success
12
+ load_py, try_until_success, sample_indexes
13
13
  from .misc import get_tensorneko_path
14
14
  from .dispatched_misc import sparse2binary, binary2sparse
15
15
  from .reproducibility import Seed
@@ -71,6 +71,7 @@ __all__ = [
71
71
  "circular_pad",
72
72
  "load_py",
73
73
  "try_until_success",
74
+ "sample_indexes",
74
75
  "download_file",
75
76
  "WindowMerger",
76
77
  ]
@@ -1,10 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
- from typing import Any
4
+ from typing import Generic
5
5
 
6
+ from tensorneko_util.util.type import T
6
7
 
7
- class Configuration(ABC):
8
+
9
+ class Configuration(ABC, Generic[T]):
8
10
  """
9
11
  Configuration base abstract class.
10
12
 
@@ -55,7 +57,7 @@ class Configuration(ABC):
55
57
  return iter((*self.args, *self.kwargs.values()))
56
58
 
57
59
  @abstractmethod
58
- def build(self) -> Any:
60
+ def build(self) -> T:
59
61
  """
60
62
  A method to build an object.
61
63
 
@@ -9,7 +9,7 @@ from torch import Tensor
9
9
  from torch.nn import Module
10
10
 
11
11
  from tensorneko_util.util.misc import generate_inf_seq, listdir, with_printed, ifelse, dict_add, as_list, \
12
- identity, list_to_dict, compose, circular_pad, load_py, try_until_success
12
+ identity, list_to_dict, compose, circular_pad, load_py, try_until_success, sample_indexes
13
13
  from .type import T, A
14
14
 
15
15
 
@@ -165,3 +165,4 @@ list_to_dict = list_to_dict
165
165
  circular_pad = circular_pad
166
166
  load_py = load_py
167
167
  try_until_success = try_until_success
168
+ sample_indexes = sample_indexes
@@ -1,4 +1,3 @@
1
- from enum import Enum
2
1
  from typing import Callable, Union, List, Tuple, TypeVar
3
2
 
4
3
  import numpy as np
@@ -0,0 +1 @@
1
+ 0.3.6
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tensorneko
3
- Version: 0.3.5
3
+ Version: 0.3.6
4
4
  Summary: Tensor Neural Engine Kompanion. An util library based on PyTorch and PyTorch Lightning.
5
5
  Home-page: https://github.com/ControlNet/tensorneko
6
6
  Author: ControlNet
@@ -38,7 +38,7 @@ License-File: LICENSE
38
38
  <div align="center">
39
39
  <a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
40
40
  <a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
41
- <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*/2.1.*-792EE5?style=flat-square&logo=lightning"></a>
41
+ <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*%20|%202.1.*-792EE5?style=flat-square&logo=lightning"></a>
42
42
  </div>
43
43
 
44
44
  <div align="center">
@@ -8,7 +8,7 @@ pillow>=8.1
8
8
  av>=8.0.3
9
9
  numpy>=1.20.1
10
10
  einops>=0.3.0
11
- tensorneko_util==0.3.5
11
+ tensorneko_util==0.3.6
12
12
 
13
13
  [:platform_system == "Windows"]
14
14
  pysoundfile>=0.9.0
@@ -1,31 +0,0 @@
1
- from lightning.pytorch import Callback, Trainer, LightningModule
2
-
3
-
4
- class GpuStatsLogger(Callback):
5
- """Log GPU stats for each training epoch"""
6
-
7
- def __init__(self, delay: float = 0.5):
8
- try:
9
- from gpumonitor.monitor import GPUStatMonitor
10
- except ImportError:
11
- raise ImportError("gpumonitor is required to use GPUStatsLogger")
12
-
13
- self.monitor = GPUStatMonitor(delay=delay)
14
-
15
- def on_train_epoch_start(self, trainer: Trainer, pl_module: LightningModule) -> None:
16
- self.monitor.reset()
17
-
18
- def on_train_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None:
19
- for gpu in self.monitor.average_stats.gpus:
20
- logged_info = {
21
- f"gpu{gpu.index}_memory_used": gpu.memory_used / 1024,
22
- f"gpu{gpu.index}_memory_total": gpu.memory_total / 1024,
23
- f"gpu{gpu.index}_memory_util": gpu.memory_used / gpu.memory_total,
24
- f"gpu{gpu.index}_temperature": float(gpu.temperature),
25
- f"gpu{gpu.index}_utilization": gpu.utilization / 100,
26
- f"gpu{gpu.index}_power_draw": float(gpu.power_draw),
27
- f"gpu{gpu.index}_power_percentage": gpu.power_draw / gpu.power_limit,
28
- f"gpu{gpu.index}_fan_speed": float(gpu.fan_speed) if gpu.fan_speed is not None else 0.,
29
- }
30
- pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
31
- pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
@@ -1,22 +0,0 @@
1
- from lightning.pytorch import Callback, Trainer, LightningModule
2
-
3
-
4
- class SystemStatsLogger(Callback):
5
- """Log system stats for each training epoch"""
6
-
7
- def __init__(self):
8
- try:
9
- import psutil
10
- except ImportError:
11
- raise ImportError("psutil is required to use SystemStatsLogger")
12
- self.psutil = psutil
13
-
14
- def on_train_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None:
15
- cpu_usage = self.psutil.cpu_percent()
16
- memory_usage = self.psutil.virtual_memory().percent
17
- logged_info = {
18
- "cpu_usage": cpu_usage,
19
- "memory_usage": memory_usage
20
- }
21
- pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
22
- pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
@@ -1 +0,0 @@
1
- 0.3.5
File without changes
File without changes
File without changes