tensorneko 0.3.7__tar.gz → 0.3.9__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.
- {tensorneko-0.3.7/src/tensorneko.egg-info → tensorneko-0.3.9}/PKG-INFO +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/__init__.py +8 -3
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/arch/binary_classifier.py +8 -6
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/arch/gan.py +2 -2
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/arch/vqvae.py +2 -2
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/arch/wgan.py +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/backend/__init__.py +3 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/earlystop_lr.py +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/epoch_num_logger.py +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/epoch_time_logger.py +2 -2
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/gpu_stats_logger.py +16 -16
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/lr_logger.py +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/system_stats_logger.py +4 -4
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/fid.py +2 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/io/reader.py +2 -0
- tensorneko-0.3.9/src/tensorneko/io/weight/__init__.py +2 -0
- tensorneko-0.3.9/src/tensorneko/io/weight/weight_reader.py +81 -0
- tensorneko-0.3.9/src/tensorneko/io/weight/weight_writer.py +48 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/io/writer.py +2 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/noise.py +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/neko_model.py +21 -4
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/type.py +1 -1
- tensorneko-0.3.9/src/tensorneko/version.txt +1 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9/src/tensorneko.egg-info}/PKG-INFO +1 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko.egg-info/SOURCES.txt +3 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko.egg-info/requires.txt +1 -1
- tensorneko-0.3.7/src/tensorneko/version.txt +0 -1
- {tensorneko-0.3.7 → tensorneko-0.3.9}/LICENSE +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/README.md +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/setup.cfg +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/setup.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/arch/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/arch/auto_encoder.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/display_metrics_callback.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/callback/nil_callback.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/list_dataset.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/nested_dataset.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/round_robin_dataset.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/sampler/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/sampler/sequential_iter_sampler.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/debug/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/enum.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/iou.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/psnr.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/secs.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/evaluation/ssim.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/io/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/io/mesh/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/io/mesh/mesh_reader.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/io/mesh/mesh_writer.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/aggregation.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/attention.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/concatenate.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/conv.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/linear.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/log.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/masked_conv2d.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/patching.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/positional_embedding.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/reshape.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/stack.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/layer/vector_quantizer.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/dense.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/gated_conv.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/inception.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/mlp.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/residual.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/module/transformer.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/neko_module.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/neko_trainer.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/notebook/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/optim/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/optim/lr_scheduler/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/preprocess/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/preprocess/crop.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/preprocess/enum.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/preprocess/face_detector/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/preprocess/pad.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/preprocess/resize.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/configuration.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/dispatched_misc.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/misc.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/reproducibility.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/util/string_getter.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/visualization/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/visualization/image_browser/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/visualization/log_graph.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/visualization/matplotlib.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/visualization/watcher/__init__.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko.egg-info/dependency_links.txt +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko.egg-info/top_level.txt +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/test/test_library_info.py +0 -0
- {tensorneko-0.3.7 → tensorneko-0.3.9}/test/test_version.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import os.path
|
|
2
2
|
|
|
3
|
-
from tensorneko_util import io
|
|
4
3
|
from . import backend
|
|
5
4
|
from . import callback
|
|
6
5
|
from . import dataset
|
|
7
6
|
from . import debug
|
|
8
7
|
from . import evaluation
|
|
8
|
+
from . import io
|
|
9
9
|
from . import layer
|
|
10
10
|
from . import module
|
|
11
11
|
from . import notebook
|
|
@@ -13,10 +13,13 @@ from . import optim
|
|
|
13
13
|
from . import preprocess
|
|
14
14
|
from . import util
|
|
15
15
|
from . import visualization
|
|
16
|
+
from .io import read, write
|
|
16
17
|
from .neko_model import NekoModel
|
|
17
18
|
from .neko_module import NekoModule
|
|
18
19
|
from .neko_trainer import NekoTrainer
|
|
19
20
|
|
|
21
|
+
__version__ = io.read.text(os.path.join(util.get_tensorneko_path(), "version.txt"))
|
|
22
|
+
|
|
20
23
|
__all__ = [
|
|
21
24
|
"callback",
|
|
22
25
|
"dataset",
|
|
@@ -33,7 +36,9 @@ __all__ = [
|
|
|
33
36
|
"debug",
|
|
34
37
|
"NekoModel",
|
|
35
38
|
"NekoTrainer",
|
|
36
|
-
"NekoModule"
|
|
39
|
+
"NekoModule",
|
|
40
|
+
"read",
|
|
41
|
+
"write",
|
|
37
42
|
]
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
|
|
@@ -6,16 +6,18 @@ from torch.optim import Adam
|
|
|
6
6
|
from torchmetrics import Accuracy, F1Score, AUROC
|
|
7
7
|
|
|
8
8
|
from ..neko_model import NekoModel
|
|
9
|
+
from ..util import Shape
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class BinaryClassifier(NekoModel):
|
|
12
13
|
|
|
13
|
-
def __init__(self, name, model: Module, learning_rate: float = 1e-4, distributed: bool = False
|
|
14
|
-
|
|
14
|
+
def __init__(self, name, model: Module, learning_rate: float = 1e-4, distributed: bool = False,
|
|
15
|
+
input_shape: Optional[Shape] = None
|
|
16
|
+
):
|
|
17
|
+
super().__init__(name, input_shape=input_shape, distributed=distributed)
|
|
15
18
|
self.save_hyperparameters()
|
|
16
19
|
self.model = model
|
|
17
20
|
self.learning_rate = learning_rate
|
|
18
|
-
self.distributed = distributed
|
|
19
21
|
self.loss_fn = BCEWithLogitsLoss()
|
|
20
22
|
self.acc_fn = Accuracy(task="binary")
|
|
21
23
|
self.f1_fn = F1Score(task="binary")
|
|
@@ -23,9 +25,9 @@ class BinaryClassifier(NekoModel):
|
|
|
23
25
|
|
|
24
26
|
@classmethod
|
|
25
27
|
def from_module(cls, model: Module, learning_rate: float = 1e-4, name: str = "binary_classifier",
|
|
26
|
-
distributed: bool = False
|
|
28
|
+
distributed: bool = False, input_shape: Optional[Shape] = None
|
|
27
29
|
):
|
|
28
|
-
return cls(name, model, learning_rate, distributed)
|
|
30
|
+
return cls(name, model, learning_rate, distributed, input_shape)
|
|
29
31
|
|
|
30
32
|
def forward(self, x):
|
|
31
33
|
return self.model(x)
|
|
@@ -38,7 +40,7 @@ class BinaryClassifier(NekoModel):
|
|
|
38
40
|
acc = self.acc_fn(prob, y)
|
|
39
41
|
f1 = self.f1_fn(prob, y)
|
|
40
42
|
auc = self.auc_fn(prob, y)
|
|
41
|
-
return {"loss": loss, "acc": acc, "f1": f1, "auc": auc}
|
|
43
|
+
return {"loss": loss, "metric/acc": acc, "metric/f1": f1, "metric/auc": auc}
|
|
42
44
|
|
|
43
45
|
def training_step(self, batch: Optional[Union[Tensor, Sequence[Tensor]]] = None, batch_idx: Optional[int] = None,
|
|
44
46
|
optimizer_idx: Optional[int] = None, hiddens: Optional[Tensor] = None
|
|
@@ -140,7 +140,7 @@ class GAN(NekoModel, ABC):
|
|
|
140
140
|
|
|
141
141
|
# calculate discriminator loss
|
|
142
142
|
d_loss = self.d_loss_fn(self.discriminator(d_batch), d_label)
|
|
143
|
-
return {"loss": d_loss, "d_loss": d_loss}
|
|
143
|
+
return {"loss": d_loss, "loss/d_loss": d_loss}
|
|
144
144
|
|
|
145
145
|
def g_step(self, x: Tensor, z: Tensor) -> Dict[str, Tensor]:
|
|
146
146
|
# forward generator
|
|
@@ -150,7 +150,7 @@ class GAN(NekoModel, ABC):
|
|
|
150
150
|
|
|
151
151
|
# calculate generator loss
|
|
152
152
|
g_loss = self.g_loss_fn(self.discriminator(fake_image), target_label)
|
|
153
|
-
return {"loss": g_loss, "g_loss": g_loss}
|
|
153
|
+
return {"loss": g_loss, "loss/g_loss": g_loss}
|
|
154
154
|
|
|
155
155
|
def validation_step(self, batch: Optional[Union[Tensor, Sequence[Tensor]]] = None, batch_idx: Optional[int] = None,
|
|
156
156
|
dataloader_idx: Optional[int] = None
|
|
@@ -72,7 +72,7 @@ class VQVAE(NekoModel, ABC):
|
|
|
72
72
|
x_hat, embedding_loss = self(x)
|
|
73
73
|
rec_loss = self.rec_loss_fn(x_hat, x)
|
|
74
74
|
loss = rec_loss + embedding_loss
|
|
75
|
-
return {"loss": loss, "r_loss": rec_loss, "e_loss": embedding_loss}
|
|
75
|
+
return {"loss": loss, "loss/r_loss": rec_loss, "loss/e_loss": embedding_loss}
|
|
76
76
|
|
|
77
77
|
def validation_step(self, batch: Optional[Union[Tensor, Sequence[Tensor]]] = None, batch_idx: Optional[int] = None,
|
|
78
78
|
dataloader_idx: Optional[int] = None
|
|
@@ -84,7 +84,7 @@ class VQVAE(NekoModel, ABC):
|
|
|
84
84
|
x_hat, embedding_loss = self(x)
|
|
85
85
|
rec_loss = self.rec_loss_fn(x_hat, x)
|
|
86
86
|
loss = rec_loss + embedding_loss
|
|
87
|
-
return {"loss": loss, "r_loss": rec_loss, "e_loss": embedding_loss}
|
|
87
|
+
return {"loss": loss, "loss/r_loss": rec_loss, "loss/e_loss": embedding_loss}
|
|
88
88
|
|
|
89
89
|
def predict_step(self, batch: Tensor, batch_idx: int, dataloader_idx: Optional[int] = None) -> Tensor:
|
|
90
90
|
return self(batch)[0]
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
from tensorneko_util.backend import parallel, run_blocking, VisualLib, AudioLib
|
|
1
|
+
from tensorneko_util.backend import parallel, run_blocking, VisualLib, AudioLib, import_tqdm_auto, import_tqdm
|
|
2
2
|
|
|
3
3
|
__all__ = [
|
|
4
4
|
"parallel",
|
|
5
5
|
"run_blocking",
|
|
6
6
|
"VisualLib",
|
|
7
7
|
"AudioLib",
|
|
8
|
+
"import_tqdm_auto",
|
|
9
|
+
"import_tqdm",
|
|
8
10
|
]
|
|
@@ -5,7 +5,7 @@ class EpochNumLogger(Callback):
|
|
|
5
5
|
"""Log epoch number in each epoch start."""
|
|
6
6
|
|
|
7
7
|
def on_train_epoch_start(self, trainer: Trainer, pl_module: LightningModule) -> None:
|
|
8
|
-
key = "epoch"
|
|
8
|
+
key = "epoch/epoch"
|
|
9
9
|
value = trainer.current_epoch
|
|
10
10
|
pl_module.logger.log_metrics({key: value}, step=trainer.global_step)
|
|
11
11
|
pl_module.log(key, value, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -12,5 +12,5 @@ class EpochTimeLogger(Callback):
|
|
|
12
12
|
|
|
13
13
|
def on_train_epoch_end(self, trainer: Trainer, pl_module: LightningModule) -> None:
|
|
14
14
|
elapsed_time = time() - self.start_time
|
|
15
|
-
pl_module.logger.log_metrics({"epoch_time": elapsed_time}, step=trainer.global_step)
|
|
16
|
-
pl_module.log("epoch_time", elapsed_time, logger=False, sync_dist=pl_module.distributed)
|
|
15
|
+
pl_module.logger.log_metrics({"epoch/epoch_time": elapsed_time}, step=trainer.global_step)
|
|
16
|
+
pl_module.log("epoch/epoch_time", elapsed_time, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -29,14 +29,14 @@ class GpuStatsLogger(Callback):
|
|
|
29
29
|
return
|
|
30
30
|
for gpu in self.monitor_epoch.average_stats.gpus:
|
|
31
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.,
|
|
32
|
+
f"system/gpu{gpu.index}_memory_used_epoch": gpu.memory_used / 1024,
|
|
33
|
+
f"system/gpu{gpu.index}_memory_total_epoch": gpu.memory_total / 1024,
|
|
34
|
+
f"system/gpu{gpu.index}_memory_util_epoch": gpu.memory_used / gpu.memory_total,
|
|
35
|
+
f"system/gpu{gpu.index}_temperature_epoch": float(gpu.temperature),
|
|
36
|
+
f"system/gpu{gpu.index}_utilization_epoch": gpu.utilization / 100,
|
|
37
|
+
f"system/gpu{gpu.index}_power_draw_epoch": float(gpu.power_draw),
|
|
38
|
+
f"system/gpu{gpu.index}_power_percentage_epoch": gpu.power_draw / gpu.power_limit,
|
|
39
|
+
f"system/gpu{gpu.index}_fan_speed_epoch": float(gpu.fan_speed) if gpu.fan_speed is not None else 0.,
|
|
40
40
|
}
|
|
41
41
|
pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
|
|
42
42
|
pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -55,14 +55,14 @@ class GpuStatsLogger(Callback):
|
|
|
55
55
|
return
|
|
56
56
|
for gpu in self.monitor_step.average_stats.gpus:
|
|
57
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.,
|
|
58
|
+
f"system/gpu{gpu.index}_memory_used_step": gpu.memory_used / 1024,
|
|
59
|
+
f"system/gpu{gpu.index}_memory_total_step": gpu.memory_total / 1024,
|
|
60
|
+
f"system/gpu{gpu.index}_memory_util_step": gpu.memory_used / gpu.memory_total,
|
|
61
|
+
f"system/gpu{gpu.index}_temperature_step": float(gpu.temperature),
|
|
62
|
+
f"system/gpu{gpu.index}_utilization_step": gpu.utilization / 100,
|
|
63
|
+
f"system/gpu{gpu.index}_power_draw_step": float(gpu.power_draw),
|
|
64
|
+
f"system/gpu{gpu.index}_power_percentage_step": gpu.power_draw / gpu.power_limit,
|
|
65
|
+
f"system/gpu{gpu.index}_fan_speed_step": float(gpu.fan_speed) if gpu.fan_speed is not None else 0.,
|
|
66
66
|
}
|
|
67
67
|
pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
|
|
68
68
|
pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -7,7 +7,7 @@ class LrLogger(Callback):
|
|
|
7
7
|
def on_train_epoch_start(self, trainer: Trainer, pl_module: LightningModule) -> None:
|
|
8
8
|
for i, optimizer in enumerate(trainer.optimizers):
|
|
9
9
|
for j, params in enumerate(optimizer.param_groups):
|
|
10
|
-
key = f"opt{i}_lr{j}"
|
|
10
|
+
key = f"learning_rate/opt{i}_lr{j}"
|
|
11
11
|
value = params["lr"]
|
|
12
12
|
pl_module.logger.log_metrics({key: value}, step=trainer.global_step)
|
|
13
13
|
pl_module.log(key, value, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -23,8 +23,8 @@ class SystemStatsLogger(Callback):
|
|
|
23
23
|
cpu_usage = self.psutil.cpu_percent()
|
|
24
24
|
memory_usage = self.psutil.virtual_memory().percent
|
|
25
25
|
logged_info = {
|
|
26
|
-
"cpu_usage_epoch": cpu_usage,
|
|
27
|
-
"memory_usage_epoch": memory_usage
|
|
26
|
+
"system/cpu_usage_epoch": cpu_usage,
|
|
27
|
+
"system/memory_usage_epoch": memory_usage
|
|
28
28
|
}
|
|
29
29
|
pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
|
|
30
30
|
pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -37,8 +37,8 @@ class SystemStatsLogger(Callback):
|
|
|
37
37
|
cpu_usage = self.psutil.cpu_percent()
|
|
38
38
|
memory_usage = self.psutil.virtual_memory().percent
|
|
39
39
|
logged_info = {
|
|
40
|
-
"cpu_usage_step": cpu_usage,
|
|
41
|
-
"memory_usage_step": memory_usage
|
|
40
|
+
"system/cpu_usage_step": cpu_usage,
|
|
41
|
+
"system/memory_usage_step": memory_usage
|
|
42
42
|
}
|
|
43
43
|
pl_module.logger.log_metrics(logged_info, step=trainer.global_step)
|
|
44
44
|
pl_module.log_dict(logged_info, logger=False, sync_dist=pl_module.distributed)
|
|
@@ -12,12 +12,13 @@ from torchmetrics.image.fid import FrechetInceptionDistance
|
|
|
12
12
|
from torchvision.transforms.functional import resize
|
|
13
13
|
|
|
14
14
|
from tensorneko_util.backend import VisualLib
|
|
15
|
-
from tensorneko_util.backend.
|
|
15
|
+
from tensorneko_util.backend.tqdm import import_tqdm_auto
|
|
16
16
|
|
|
17
17
|
try:
|
|
18
18
|
from typing import Literal
|
|
19
19
|
TypeOption = Literal["video", "image"]
|
|
20
20
|
except ImportError:
|
|
21
|
+
Literal = None
|
|
21
22
|
TypeOption = str
|
|
22
23
|
|
|
23
24
|
|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
from typing import Type
|
|
3
3
|
|
|
4
4
|
from tensorneko_util.io.reader import Reader as BaseReader
|
|
5
|
+
from .weight import WeightReader
|
|
5
6
|
|
|
6
7
|
try:
|
|
7
8
|
from .mesh import MeshReader
|
|
@@ -15,6 +16,7 @@ class Reader(BaseReader):
|
|
|
15
16
|
|
|
16
17
|
def __init__(self):
|
|
17
18
|
super().__init__()
|
|
19
|
+
self.weight = WeightReader
|
|
18
20
|
self._mesh = None
|
|
19
21
|
|
|
20
22
|
@property
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from typing import OrderedDict
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
|
|
5
|
+
from ...util import Device
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WeightReader:
|
|
9
|
+
"""WeightReader for read model weights (checkpoints, state_dict, etc)."""
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def of_pt(cls, path: str, map_location: Device = "cpu") -> OrderedDict[str, torch.Tensor]:
|
|
13
|
+
"""
|
|
14
|
+
Reads PyTorch model weights from a `.pt` or `.pth` file.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
path (``str``): The path of the `.pt` or `.pth` file.
|
|
18
|
+
map_location (:class:`torch.device` | ``str``): The location to load the model weights. Default: "cpu"
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]: The model weights.
|
|
22
|
+
"""
|
|
23
|
+
return torch.load(path, map_location=map_location)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def of_ckpt(cls, path: str, map_location: Device = "cpu") -> OrderedDict[str, torch.Tensor]:
|
|
27
|
+
"""
|
|
28
|
+
Reads PyTorch model weights from a `.ckpt` file.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
path (``str``): The path of the `.ckpt` file.
|
|
32
|
+
map_location (:class:`torch.device` | ``str``): The location to load the model weights. Default: "cpu"
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]: The model weights.
|
|
36
|
+
"""
|
|
37
|
+
return torch.load(path, map_location=map_location)["state_dict"]
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def of_safetensors(cls, path: str, map_location: str = "cpu") -> OrderedDict[str, torch.Tensor]:
|
|
41
|
+
"""
|
|
42
|
+
Reads model weights from a `.safetensors` file.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
path (``str``): The path of the `.safetensors` file.
|
|
46
|
+
map_location (``str``): The location to load the model weights. Default: "cpu"
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]: The model weights.
|
|
50
|
+
"""
|
|
51
|
+
import safetensors
|
|
52
|
+
from collections import OrderedDict
|
|
53
|
+
tensors = OrderedDict()
|
|
54
|
+
with safetensors.safe_open(path, framework="pt", device=map_location) as f:
|
|
55
|
+
for key in f.keys():
|
|
56
|
+
tensors[key] = f.get_tensor(key)
|
|
57
|
+
return tensors
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def of(cls, path: str, map_location: Device = "cpu") -> OrderedDict[str, torch.Tensor]:
|
|
61
|
+
"""
|
|
62
|
+
Reads model weights from a file.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
path (``str``): The path of the file.
|
|
66
|
+
map_location (:class:`torch.device` | ``str``): The location to load the model weights. Default: "cpu"
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]: The model weights.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
if path.endswith(".pt") or path.endswith(".pth"):
|
|
73
|
+
return cls.of_pt(path, map_location)
|
|
74
|
+
elif path.endswith(".ckpt"):
|
|
75
|
+
return cls.of_ckpt(path, map_location)
|
|
76
|
+
elif path.endswith(".safetensors"):
|
|
77
|
+
if isinstance(map_location, torch.device):
|
|
78
|
+
map_location = str(map_location)
|
|
79
|
+
return cls.of_safetensors(path, map_location)
|
|
80
|
+
else:
|
|
81
|
+
raise ValueError("Unknown file type. Supported types: .pt, .pth, .ckpt, .safetensors")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class WeightWriter:
|
|
7
|
+
"""WeightWriter for write model weights (checkpoints, state_dict, etc)."""
|
|
8
|
+
|
|
9
|
+
@classmethod
|
|
10
|
+
def to_pt(cls, path: str, weights: Dict[str, torch.Tensor]) -> None:
|
|
11
|
+
"""
|
|
12
|
+
Writes PyTorch model weights to a `.pt` or `.pth` file.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
path (``str``): The path of the `.pt` or `.pth` file.
|
|
16
|
+
weights (:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]): The model weights.
|
|
17
|
+
"""
|
|
18
|
+
torch.save(weights, path)
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def to_safetensors(cls, path: str, weights: Dict[str, torch.Tensor]) -> None:
|
|
22
|
+
"""
|
|
23
|
+
Writes model weights to a `.safetensors` file.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
path (``str``): The path of the `.safetensors` file.
|
|
27
|
+
weights (:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]): The model weights.
|
|
28
|
+
"""
|
|
29
|
+
import safetensors.torch
|
|
30
|
+
safetensors.torch.save_file(weights, path)
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def to(cls, path: str, weights: Dict[str, torch.Tensor]) -> None:
|
|
34
|
+
"""
|
|
35
|
+
Writes model weights to a file.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
path (``str``): The path of the file.
|
|
39
|
+
weights (:class:`collections.OrderedDict`[``str``, :class:`torch.Tensor`]): The model weights.
|
|
40
|
+
"""
|
|
41
|
+
file_type = path.split(".")[-1]
|
|
42
|
+
|
|
43
|
+
if file_type == "pt":
|
|
44
|
+
cls.to_pt(path, weights)
|
|
45
|
+
elif file_type == "safetensors":
|
|
46
|
+
cls.to_safetensors(path, weights)
|
|
47
|
+
else:
|
|
48
|
+
raise ValueError("Unknown file type. Supported types: .pt, .safetensors")
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import Type
|
|
4
4
|
|
|
5
5
|
from tensorneko_util.io.writer import Writer as BaseWriter
|
|
6
|
+
from .weight import WeightWriter
|
|
6
7
|
|
|
7
8
|
try:
|
|
8
9
|
from .mesh import MeshWriter
|
|
@@ -16,6 +17,7 @@ class Writer(BaseWriter):
|
|
|
16
17
|
|
|
17
18
|
def __init__(self):
|
|
18
19
|
super().__init__()
|
|
20
|
+
self.weight = WeightWriter
|
|
19
21
|
self._mesh = None
|
|
20
22
|
|
|
21
23
|
@property
|
|
@@ -22,7 +22,7 @@ class GaussianNoise(NekoModule):
|
|
|
22
22
|
from https://discuss.pytorch.org/t/writing-a-simple-gaussian-noise-layer-in-pytorch/4694/3
|
|
23
23
|
"""
|
|
24
24
|
|
|
25
|
-
def __init__(self, sigma=0.1, device:
|
|
25
|
+
def __init__(self, sigma=0.1, device: Device = "cuda"):
|
|
26
26
|
super().__init__()
|
|
27
27
|
self.sigma = sigma
|
|
28
28
|
self.noise = torch.tensor(0.).to(device)
|
|
@@ -170,6 +170,7 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
170
170
|
and self.logger is not None \
|
|
171
171
|
and self.trainer.global_step % self.trainer.log_every_n_steps == 0:
|
|
172
172
|
self.log_on_training_step_end(outputs)
|
|
173
|
+
super().on_train_batch_end(outputs, batch, batch_idx)
|
|
173
174
|
|
|
174
175
|
def on_validation_batch_end(
|
|
175
176
|
self, outputs: Optional[STEP_OUTPUT], batch: Any, batch_idx: int, dataloader_idx: int = 0
|
|
@@ -177,18 +178,21 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
177
178
|
"""Append the outputs of validation step to the list"""
|
|
178
179
|
outputs = {k: v.detach() for k, v in outputs.items()}
|
|
179
180
|
self.validation_step_outputs.append(outputs)
|
|
181
|
+
super().on_validation_batch_end(outputs, batch, batch_idx, dataloader_idx)
|
|
180
182
|
|
|
181
183
|
def on_train_epoch_end(self) -> None:
|
|
182
184
|
"""For each training epoch end, log the metrics"""
|
|
183
185
|
if self.trainer.log_on_epoch and self.logger is not None:
|
|
184
186
|
self.log_on_training_epoch_end(self.training_step_outputs)
|
|
185
187
|
self.training_step_outputs.clear()
|
|
188
|
+
super().on_train_epoch_end()
|
|
186
189
|
|
|
187
190
|
def on_validation_epoch_end(self) -> None:
|
|
188
191
|
"""For each validation epoch end, log the metrics"""
|
|
189
192
|
if self.logger is not None:
|
|
190
193
|
self.log_on_validation_epoch_end(self.validation_step_outputs)
|
|
191
194
|
self.validation_step_outputs.clear()
|
|
195
|
+
super().on_validation_epoch_end()
|
|
192
196
|
|
|
193
197
|
def log_on_training_epoch_end(self, outputs: EPOCH_OUTPUT) -> None:
|
|
194
198
|
"""Log the training epoch outputs"""
|
|
@@ -197,7 +201,8 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
197
201
|
getter = summarize_dict_by(key, torch.mean)
|
|
198
202
|
value = getter(outputs)
|
|
199
203
|
history_item[key] = value
|
|
200
|
-
self.logger
|
|
204
|
+
if self.logger is not None:
|
|
205
|
+
self.logger.log_metrics({key: value}, step=self.trainer.global_step)
|
|
201
206
|
self.log(key, value, on_epoch=True, on_step=False, logger=False, sync_dist=self.distributed)
|
|
202
207
|
self.history.append(history_item)
|
|
203
208
|
|
|
@@ -210,7 +215,8 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
210
215
|
getter = summarize_dict_by(key, torch.mean)
|
|
211
216
|
value = getter(outputs)
|
|
212
217
|
self.history[-1]["val_" + key] = value
|
|
213
|
-
self.logger
|
|
218
|
+
if self.logger is not None:
|
|
219
|
+
self.logger.log_metrics({key: value}, step=self.trainer.global_step)
|
|
214
220
|
self.log(key, value, on_epoch=True, on_step=False, logger=False, sync_dist=self.distributed)
|
|
215
221
|
self.log(f"val_{key}", value, on_epoch=True, on_step=False, logger=False, prog_bar=True,
|
|
216
222
|
sync_dist=self.distributed)
|
|
@@ -220,7 +226,8 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
220
226
|
history_item = {}
|
|
221
227
|
for key, value in output.items():
|
|
222
228
|
history_item[key] = value
|
|
223
|
-
self.logger
|
|
229
|
+
if self.logger is not None:
|
|
230
|
+
self.logger.log_metrics({key: value}, step=self.trainer.global_step)
|
|
224
231
|
self.log(key, value, on_epoch=False, on_step=True, logger=False, prog_bar=key == "loss",
|
|
225
232
|
sync_dist=self.distributed)
|
|
226
233
|
self.history.append(history_item)
|
|
@@ -230,6 +237,7 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
230
237
|
) -> None:
|
|
231
238
|
"""For each test step end, log the metrics"""
|
|
232
239
|
self.log_dict(outputs, sync_dist=self.distributed)
|
|
240
|
+
super().on_test_batch_end(outputs, batch, batch_idx, dataloader_idx)
|
|
233
241
|
|
|
234
242
|
def log_image(self, name: str, image: torch.Tensor) -> None:
|
|
235
243
|
"""Log an image to the logger"""
|
|
@@ -238,6 +246,15 @@ class NekoModel(LightningModule, NekoModule):
|
|
|
238
246
|
|
|
239
247
|
self.logger.experiment.add_image(name, torch.clip(image, 0, 1), self.trainer.global_step)
|
|
240
248
|
|
|
249
|
+
def log_histogram(self, name: str, values: torch.Tensor) -> None:
|
|
250
|
+
"""Log a histogram to the logger"""
|
|
251
|
+
if self.logger is None:
|
|
252
|
+
return
|
|
253
|
+
|
|
254
|
+
self.logger.experiment.add_histogram(name, values, self.trainer.global_step)
|
|
255
|
+
|
|
241
256
|
def on_train_start(self) -> None:
|
|
242
257
|
"""Log the model graph to tensorboard when the input shape is set"""
|
|
243
|
-
self.
|
|
258
|
+
if self.can_plot_graph and self.logger is not None:
|
|
259
|
+
self.logger.log_graph(self, self.example_input_array)
|
|
260
|
+
super().on_train_start()
|
|
@@ -11,7 +11,7 @@ ModuleFactory = Union[Callable[[], Module], Callable[[int], Module]]
|
|
|
11
11
|
"""The module builder type of ``() -> torch.nn.Module | (int) -> torch.nn.Module``"""
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
Device = device
|
|
14
|
+
Device = Union[str, device]
|
|
15
15
|
"""Device type of :class:`torch.device`"""
|
|
16
16
|
|
|
17
17
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.3.9
|
|
@@ -47,6 +47,9 @@ src/tensorneko/io/writer.py
|
|
|
47
47
|
src/tensorneko/io/mesh/__init__.py
|
|
48
48
|
src/tensorneko/io/mesh/mesh_reader.py
|
|
49
49
|
src/tensorneko/io/mesh/mesh_writer.py
|
|
50
|
+
src/tensorneko/io/weight/__init__.py
|
|
51
|
+
src/tensorneko/io/weight/weight_reader.py
|
|
52
|
+
src/tensorneko/io/weight/weight_writer.py
|
|
50
53
|
src/tensorneko/layer/__init__.py
|
|
51
54
|
src/tensorneko/layer/aggregation.py
|
|
52
55
|
src/tensorneko/layer/attention.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.7
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/dataset/sampler/sequential_iter_sampler.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tensorneko-0.3.7 → tensorneko-0.3.9}/src/tensorneko/visualization/image_browser/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|