pytorch-template

[🔥], PyTorch template with TOML

https://github.com/s1m0n38/pytorch-template

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

pytorch template toml
Last synced: 6 months ago · JSON representation ·

Repository

[🔥], PyTorch template with TOML

Basic Info
  • Host: GitHub
  • Owner: S1M0N38
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 60.5 KB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
pytorch template toml
Created almost 3 years ago · Last pushed almost 2 years ago
Metadata Files
Readme License Citation

README.md

[🔥]

PyTorch template with TOML

Status Python License Discord

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

  1. Define the configuration in a TOML file (e.g. configs/example.toml)
  2. 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

Owner

  • Login: S1M0N38
  • Kind: user

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

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 45
  • Total Committers: 1
  • Avg Commits per committer: 45.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
S1M0N38 b****e@g****m 45

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
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels