tensorneko 0.3.8__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.
Files changed (99) hide show
  1. {tensorneko-0.3.8/src/tensorneko.egg-info → tensorneko-0.3.9}/PKG-INFO +1 -1
  2. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/__init__.py +8 -3
  3. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/backend/__init__.py +3 -1
  4. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/fid.py +2 -1
  5. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/io/reader.py +2 -0
  6. tensorneko-0.3.9/src/tensorneko/io/weight/__init__.py +2 -0
  7. tensorneko-0.3.9/src/tensorneko/io/weight/weight_reader.py +81 -0
  8. tensorneko-0.3.9/src/tensorneko/io/weight/weight_writer.py +48 -0
  9. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/io/writer.py +2 -0
  10. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/noise.py +1 -1
  11. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/type.py +1 -1
  12. tensorneko-0.3.9/src/tensorneko/version.txt +1 -0
  13. {tensorneko-0.3.8 → tensorneko-0.3.9/src/tensorneko.egg-info}/PKG-INFO +1 -1
  14. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko.egg-info/SOURCES.txt +3 -0
  15. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko.egg-info/requires.txt +1 -1
  16. tensorneko-0.3.8/src/tensorneko/version.txt +0 -1
  17. {tensorneko-0.3.8 → tensorneko-0.3.9}/LICENSE +0 -0
  18. {tensorneko-0.3.8 → tensorneko-0.3.9}/README.md +0 -0
  19. {tensorneko-0.3.8 → tensorneko-0.3.9}/setup.cfg +0 -0
  20. {tensorneko-0.3.8 → tensorneko-0.3.9}/setup.py +0 -0
  21. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/arch/__init__.py +0 -0
  22. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/arch/auto_encoder.py +0 -0
  23. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/arch/binary_classifier.py +0 -0
  24. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/arch/gan.py +0 -0
  25. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/arch/vqvae.py +0 -0
  26. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/arch/wgan.py +0 -0
  27. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/__init__.py +0 -0
  28. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/display_metrics_callback.py +0 -0
  29. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/earlystop_lr.py +0 -0
  30. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/epoch_num_logger.py +0 -0
  31. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/epoch_time_logger.py +0 -0
  32. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/gpu_stats_logger.py +0 -0
  33. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/lr_logger.py +0 -0
  34. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/nil_callback.py +0 -0
  35. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/callback/system_stats_logger.py +0 -0
  36. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/dataset/__init__.py +0 -0
  37. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/dataset/list_dataset.py +0 -0
  38. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/dataset/nested_dataset.py +0 -0
  39. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/dataset/round_robin_dataset.py +0 -0
  40. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/dataset/sampler/__init__.py +0 -0
  41. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/dataset/sampler/sequential_iter_sampler.py +0 -0
  42. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/debug/__init__.py +0 -0
  43. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/__init__.py +0 -0
  44. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/enum.py +0 -0
  45. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/iou.py +0 -0
  46. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/psnr.py +0 -0
  47. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/secs.py +0 -0
  48. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/evaluation/ssim.py +0 -0
  49. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/io/__init__.py +0 -0
  50. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/io/mesh/__init__.py +0 -0
  51. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/io/mesh/mesh_reader.py +0 -0
  52. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/io/mesh/mesh_writer.py +0 -0
  53. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/__init__.py +0 -0
  54. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/aggregation.py +0 -0
  55. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/attention.py +0 -0
  56. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/concatenate.py +0 -0
  57. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/conv.py +0 -0
  58. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/linear.py +0 -0
  59. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/log.py +0 -0
  60. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/masked_conv2d.py +0 -0
  61. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/patching.py +0 -0
  62. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/positional_embedding.py +0 -0
  63. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/reshape.py +0 -0
  64. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/stack.py +0 -0
  65. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/layer/vector_quantizer.py +0 -0
  66. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/__init__.py +0 -0
  67. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/dense.py +0 -0
  68. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/gated_conv.py +0 -0
  69. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/inception.py +0 -0
  70. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/mlp.py +0 -0
  71. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/residual.py +0 -0
  72. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/module/transformer.py +0 -0
  73. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/neko_model.py +0 -0
  74. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/neko_module.py +0 -0
  75. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/neko_trainer.py +0 -0
  76. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/notebook/__init__.py +0 -0
  77. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/optim/__init__.py +0 -0
  78. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/optim/lr_scheduler/__init__.py +0 -0
  79. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/preprocess/__init__.py +0 -0
  80. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/preprocess/crop.py +0 -0
  81. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/preprocess/enum.py +0 -0
  82. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/preprocess/face_detector/__init__.py +0 -0
  83. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/preprocess/pad.py +0 -0
  84. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/preprocess/resize.py +0 -0
  85. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/__init__.py +0 -0
  86. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/configuration.py +0 -0
  87. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/dispatched_misc.py +0 -0
  88. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/misc.py +0 -0
  89. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/reproducibility.py +0 -0
  90. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/util/string_getter.py +0 -0
  91. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/visualization/__init__.py +0 -0
  92. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/visualization/image_browser/__init__.py +0 -0
  93. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/visualization/log_graph.py +0 -0
  94. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/visualization/matplotlib.py +0 -0
  95. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko/visualization/watcher/__init__.py +0 -0
  96. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko.egg-info/dependency_links.txt +0 -0
  97. {tensorneko-0.3.8 → tensorneko-0.3.9}/src/tensorneko.egg-info/top_level.txt +0 -0
  98. {tensorneko-0.3.8 → tensorneko-0.3.9}/test/test_library_info.py +0 -0
  99. {tensorneko-0.3.8 → tensorneko-0.3.9}/test/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tensorneko
3
- Version: 0.3.8
3
+ Version: 0.3.9
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
@@ -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
- __version__ = io.read.text(os.path.join(util.get_tensorneko_path(), "version.txt"))
44
+
@@ -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
  ]
@@ -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._tqdm import import_tqdm_auto
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,2 @@
1
+ from .weight_reader import WeightReader
2
+ from .weight_writer import WeightWriter
@@ -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: Union[Device, str] = "cuda"):
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)
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tensorneko
3
- Version: 0.3.8
3
+ Version: 0.3.9
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
@@ -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
@@ -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.8
11
+ tensorneko_util==0.3.9
12
12
 
13
13
  [:platform_system == "Windows"]
14
14
  pysoundfile>=0.9.0
@@ -1 +0,0 @@
1
- 0.3.8
File without changes
File without changes
File without changes
File without changes