torchabc 0.2.0__tar.gz → 0.2.2__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.
- {torchabc-0.2.0 → torchabc-0.2.2}/PKG-INFO +9 -9
- {torchabc-0.2.0 → torchabc-0.2.2}/README.md +7 -7
- {torchabc-0.2.0 → torchabc-0.2.2}/pyproject.toml +2 -2
- {torchabc-0.2.0 → torchabc-0.2.2}/torchabc/__init__.py +1 -1
- {torchabc-0.2.0 → torchabc-0.2.2}/torchabc/cli.py +6 -6
- {torchabc-0.2.0 → torchabc-0.2.2}/LICENSE +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: torchabc
|
|
3
|
-
Version: 0.2.
|
|
4
|
-
Summary: A
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: A simple abstract class for training and inference in PyTorch.
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Emanuele Guidotti
|
|
7
7
|
Author-email: emanuele.guidotti@usi.ch
|
|
@@ -18,21 +18,21 @@ Description-Content-Type: text/markdown
|
|
|
18
18
|
|
|
19
19
|
# TorchABC
|
|
20
20
|
|
|
21
|
-
[`TorchABC`](https://github.com/eguidotti/torchabc) is
|
|
21
|
+
[`TorchABC`](https://github.com/eguidotti/torchabc/blob/main/torchabc/__init__.py) is an abstract class for training and inference in PyTorch that helps you keep your code well organized. It is a minimalist version of [pytorch-lightning](https://pypi.org/project/pytorch-lightning/), it depends on [torch](https://pypi.org/project/torch/) only, and it consists of a simple self-contained [file](https://github.com/eguidotti/torchabc/blob/main/torchabc/__init__.py).
|
|
22
22
|
|
|
23
23
|
## Workflow
|
|
24
24
|
|
|
25
25
|

|
|
26
26
|
|
|
27
|
-
`TorchABC` implements the workflow illustrated above. The workflow begins with raw
|
|
27
|
+
The `TorchABC` class implements the workflow illustrated above. The workflow begins with raw `data`, which undergoes a `preprocess` step. This step transforms the raw `data` into `input` samples and their corresponding `target` labels.
|
|
28
28
|
|
|
29
|
-
Next, the individual
|
|
29
|
+
Next, the individual `input` samples are grouped into batches called `inputs` using a `collate` function. Similarly, the `target` labels are batched into `targets`. The `inputs` are then fed into the `network`, which produces `outputs`.
|
|
30
30
|
|
|
31
|
-
The
|
|
31
|
+
The `outputs` are compared to the `targets` using a `loss` function which quantifies the error between the two. The `optimizer` updates the parameters of the `network` to minimize the `loss`. The `scheduler` can dynamically change the learning rate of the `optimizer` during training.
|
|
32
32
|
|
|
33
|
-
Finally, the raw
|
|
33
|
+
Finally, the raw `outputs` from the `network` undergo a `postprocess` step to generate the final `predictions`. This could involve converting probabilities to class labels, applying thresholds, or other task-specific transformations.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
The core logic blocks are abstract. You define their specific behavior with maximum flexibility.
|
|
36
36
|
|
|
37
37
|
## Quick start
|
|
38
38
|
|
|
@@ -82,7 +82,7 @@ class ClassName(TorchABC):
|
|
|
82
82
|
return outputs
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
Fill out the template with the dataloaders, preprocessing and postprocessing steps, the neural network, optimizer, scheduler, loss, and evaluation metrics.
|
|
85
|
+
Fill out the template with the dataloaders, preprocessing and postprocessing steps, the neural network, optimizer, scheduler, loss, and optional evaluation metrics.
|
|
86
86
|
|
|
87
87
|
#### `dataloaders`: the dataloaders for training and evaluation
|
|
88
88
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# TorchABC
|
|
2
2
|
|
|
3
|
-
[`TorchABC`](https://github.com/eguidotti/torchabc) is
|
|
3
|
+
[`TorchABC`](https://github.com/eguidotti/torchabc/blob/main/torchabc/__init__.py) is an abstract class for training and inference in PyTorch that helps you keep your code well organized. It is a minimalist version of [pytorch-lightning](https://pypi.org/project/pytorch-lightning/), it depends on [torch](https://pypi.org/project/torch/) only, and it consists of a simple self-contained [file](https://github.com/eguidotti/torchabc/blob/main/torchabc/__init__.py).
|
|
4
4
|
|
|
5
5
|
## Workflow
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
`TorchABC` implements the workflow illustrated above. The workflow begins with raw
|
|
9
|
+
The `TorchABC` class implements the workflow illustrated above. The workflow begins with raw `data`, which undergoes a `preprocess` step. This step transforms the raw `data` into `input` samples and their corresponding `target` labels.
|
|
10
10
|
|
|
11
|
-
Next, the individual
|
|
11
|
+
Next, the individual `input` samples are grouped into batches called `inputs` using a `collate` function. Similarly, the `target` labels are batched into `targets`. The `inputs` are then fed into the `network`, which produces `outputs`.
|
|
12
12
|
|
|
13
|
-
The
|
|
13
|
+
The `outputs` are compared to the `targets` using a `loss` function which quantifies the error between the two. The `optimizer` updates the parameters of the `network` to minimize the `loss`. The `scheduler` can dynamically change the learning rate of the `optimizer` during training.
|
|
14
14
|
|
|
15
|
-
Finally, the raw
|
|
15
|
+
Finally, the raw `outputs` from the `network` undergo a `postprocess` step to generate the final `predictions`. This could involve converting probabilities to class labels, applying thresholds, or other task-specific transformations.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The core logic blocks are abstract. You define their specific behavior with maximum flexibility.
|
|
18
18
|
|
|
19
19
|
## Quick start
|
|
20
20
|
|
|
@@ -64,7 +64,7 @@ class ClassName(TorchABC):
|
|
|
64
64
|
return outputs
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
Fill out the template with the dataloaders, preprocessing and postprocessing steps, the neural network, optimizer, scheduler, loss, and evaluation metrics.
|
|
67
|
+
Fill out the template with the dataloaders, preprocessing and postprocessing steps, the neural network, optimizer, scheduler, loss, and optional evaluation metrics.
|
|
68
68
|
|
|
69
69
|
#### `dataloaders`: the dataloaders for training and evaluation
|
|
70
70
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "torchabc"
|
|
3
|
-
version = "0.2.
|
|
4
|
-
description = "A
|
|
3
|
+
version = "0.2.2"
|
|
4
|
+
description = "A simple abstract class for training and inference in PyTorch."
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Emanuele Guidotti",email = "emanuele.guidotti@usi.ch"}
|
|
7
7
|
]
|
|
@@ -7,7 +7,7 @@ from typing import Any, Union, Dict, List, Callable
|
|
|
7
7
|
|
|
8
8
|
class TorchABC(abc.ABC):
|
|
9
9
|
"""
|
|
10
|
-
A
|
|
10
|
+
A simple abstract class for training and inference in PyTorch.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
def __init__(self, device: Union[str, torch.device] = None, logger: Callable = print, **hparams):
|
|
@@ -7,7 +7,7 @@ from . import TorchABC
|
|
|
7
7
|
def main():
|
|
8
8
|
parser = argparse.ArgumentParser(description="Generate template.")
|
|
9
9
|
parser.add_argument('--create', type=str, required=True, help='The path to create the template file.')
|
|
10
|
-
parser.add_argument('--
|
|
10
|
+
parser.add_argument('--min', action='store_true', help='Generate a minimalistic template without docstrings.')
|
|
11
11
|
args = parser.parse_args()
|
|
12
12
|
|
|
13
13
|
cached_properties = {}
|
|
@@ -36,9 +36,9 @@ from typing import Any, Dict
|
|
|
36
36
|
|
|
37
37
|
class ClassName(TorchABC):"""
|
|
38
38
|
|
|
39
|
-
if not args.
|
|
39
|
+
if not args.min:
|
|
40
40
|
template += """
|
|
41
|
-
\"\"\"A concrete
|
|
41
|
+
\"\"\"A concrete subclass of the TorchABC abstract class.
|
|
42
42
|
|
|
43
43
|
Use this template to implement your own model by following these steps:
|
|
44
44
|
- replace ClassName with the name of your model,
|
|
@@ -56,7 +56,7 @@ class ClassName(TorchABC):"""
|
|
|
56
56
|
template += f"""
|
|
57
57
|
@cached_property
|
|
58
58
|
def {name}(self):"""
|
|
59
|
-
if not args.
|
|
59
|
+
if not args.min:
|
|
60
60
|
template += f"""
|
|
61
61
|
\"\"\"{doc}\"\"\""""
|
|
62
62
|
template += f"""
|
|
@@ -66,14 +66,14 @@ class ClassName(TorchABC):"""
|
|
|
66
66
|
sig, doc = methods[name]
|
|
67
67
|
template += f"""
|
|
68
68
|
def {name}{sig}:"""
|
|
69
|
-
if not args.
|
|
69
|
+
if not args.min:
|
|
70
70
|
template += f"""
|
|
71
71
|
\"\"\"{doc}\"\"\""""
|
|
72
72
|
template += f"""
|
|
73
73
|
{defaults[name] if name in defaults else 'raise NotImplementedError'}
|
|
74
74
|
"""
|
|
75
75
|
|
|
76
|
-
if not args.
|
|
76
|
+
if not args.min:
|
|
77
77
|
template += f"""
|
|
78
78
|
|
|
79
79
|
if __name__ == "__main__":
|
|
File without changes
|