Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
â—‹DOI references
-
â—‹Academic publication links
-
â—‹Committers with academic emails
-
â—‹Institutional organization owner
-
â—‹JOSS paper metadata
-
â—‹Scientific vocabulary similarity
Low similarity (13.6%) to scientific vocabulary
Keywords
Repository
[🔥], PyTorch template with TOML
Basic Info
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
There are many components involved in training a PyTorch model, including model architectures, loss functions, hyperparameters, optimizers, dataloaders, and all of their arguments.
A standard training loop requires boilerplate code to connect all of these components, including training and validation steps, saving and loading checkpoints, and tracking metrics.
To simplify this process, a [🔥] template can be used to specify the aforementioned components using a TOML file, while implementing the remaining ones as a minimal class in a single PyTorch file.
Usage
- Define the configuration in a TOML file (e.g.
configs/example.toml) - Train, Validate and Test the model with
python main.py configs/example.toml
How it works
A TOML file is read by the Trainer class (the unique class that implements all
the boilerplate code for training) and dynamically loads classes and their
arguments using the init function:
python
def init(module: object, class_args: dict):
class_name = class_args.pop("class")
return getattr(module, class_name)(**class_args)
Suppose the following TOML configuration for the optimizer:
TOML
[optimizer]
class = "Adam"
lr = 1e-3
weight_decay=0
From the [optimizer] section, [🔥] uses the class to create a new instance
of a torch.optim.Adam optimizer and passes all other values as arguments to the
new object (here lr and weight_decay). Optimizer also has parameters as a
positional argument but this is already provided by the code in the Learner
class.
You can also initialize from TOML your custom classes
TOML
[model]
class = "LeNet5"
num_classes = 10
This configuration section will initialize LeNet5 class defined in models/models.py
as the model architecture.
You can easily understand how a TOML file is loaded by Trainer and Tester by
comparing configs/example.toml and __init__() methods in main.py.
Q&A
Is [🔥] stable? No, I'm tweaking this template based on my experience and needs, so expect breaking changes. Nevertheless, this is a template so you might have to heavily modify it to fit your needs.
Why the name [🔥]? It's a combination of the PyTorch flame and the square brackets defining sections in a TOML file.
Why TOML? I think it's simpler than YAML and better than JSON for configuration. Moreover, the Python ecosystem starts to embrace it: tomllib in the standard library and pyproject.toml for Python project configuration.
Similar projects
- victoresque/pytorch-template: PyTorch deep learning projects made easy.
- moemen95/Pytorch-Project-Template: A scalable template for PyTorch projects, with examples in Image Segmentation, Object classification, GANs and Reinforcement Learning.
Owner
- Login: S1M0N38
- Kind: user
- Repositories: 9
- Profile: https://github.com/S1M0N38
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Bertolotto" given-names: "Simone" orcid: "https://orcid.org/0009-0007-1960-1665" title: "PyTorch Template with TOML" version: 0.1.0 date-released: 2023-05-31 url: "https://github.com/S1M0N38/pytorch-template"
GitHub Events
Total
Last Year
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0