Skip to content

sagnik1511/Torch-Tutor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Torch-Tutor


GOALS of the Project

1. Reduces implementation time upto 50%.
2. Presents Eye-catching Training Job Monitor.
3. Stores training data efficiently.
4. Integrated with W&B.

Visit at PyPI

Primary Release

Installation

  1. Primary Requirements :

    a) Python >= 3.9

    b) Torch >= 1.11.0 + cu113

    Visit Custom Installation PyTorch to install the latest version(Date : 07-09-2022)

  2. Install the torch_tutor package.

Package Installation

a) From PyPi :

pip install torch_tutor

b) From Repository :

Install the reporsitory :

git clone https://github.com/sagnik1511/Torch-Tutor.git

Go to the directory.

cd Torch_Tutor

Install from the local repository.

pip install -v -e .

Usage

from torch_tutor.core.trainer import Trainer
from torch_tutor.core.callbacks import CallBack

callback = CallBack(tracker="accuracy",
                    stop_epoch=5,
                    save_weights=True,
                    on="training",
                    save_directory="../weight_directory")

trainer = Trainer(train_dataset="<add your train_dataset_here>",
                  model="<add your model here>",
                  device="cpu")

optimizer_hyperparameter_dict = {"lr" : 0.0001}

trainer.compile(optimizer="<add your optimizer here>",
                loss_fn="<add your los function here>",
                metrics=["accuracy", "precision",...],
                optimizer_hparams=optimizer_hyperparameter_dict)

trainer.train(batch_size=32,
              num_epochs=50,
              training_steps=100,
              validation_set="<add your validation dataset here>",
              validation_steps=50,
              logging_index=10,
              shuffle=True,
              drop_last_batches=True,
              callback=callback,
              connect_wandb=True,
              exp_name="New Experiment")

Check in Google Colab

Feature Description

CallBack

from torch_tutor.core.callbacks import CallBack

tracker [type: list] : On which metric the model will be tested. Currently, supporting "accuracy", "precision", "recall", "f1_score" and "mean_squared_error".

stop_epoch [type: int] : Number of epochs of continuous degradation after training stops.

save_weights [type: bool] : Flag to save best model.

on [type: str] : On which dataset the best results will be tracked. Takes either "training" or "validation".

save_directory [type: Path] : On which directory the best model will be saved.


Trainer

from torch_tutor.core.trainer import Trainer

train_dataset [type: torch.utils.data.Dataset] : The dataset used for training.

model [type: torch.nn.Module] : The model used for training.

device [type: str] : The device used for training . Currently supporting cpu and cuda.

compile


optimizer : The optimizer which will be used for training, e.g. Adam, Adagrad

loss_fn : The loss function that is used for backpropagation, e.g. CrossEntropyLoss, MSELoss

metrics [type: str] : On which metric the model will be tested. Currently, supporting "accuracy", "precision", "recall", "f1_score" and "mean_squared_error".

optimizer_hparams [type: dict] : The parameters that are used inside Optimizer e.e learning_rate,weight_decay.

train


batch_size [type: int] : Batch size of the training and validation set.

num_epochs [type: int] : Number of epoch on which the model will be trained.

training_steps [type: int] : Number of batches per epoch on which model will be trained.

validation_set [type: None or torch.utils.data.Dataset] : On which the model will be validated.

validation_steps [type : int] : Number of batches per epoch on which model will be validated.

logging_index [type: int] : Number of indexes after which results will be shown.

shuffle [type: bool] : Flag to shuffle data indexes.

drop_last_batches [type: bool] : Flag on which the last small batches will be cut.

callback [type: torch_tutor.core.callback.callBack] : CallBack function.

connect_wandb [type: bool] : Flag to connect W&B loggers.

exp_name [type: str] : Name of the experiment.


Module Functionalities Achieved

  • Training through CPU / GPU / TPU.
  • Basic Loggings & Reports.
  • W&B Integration.
  • MLFlow Integration.
  • Distributed Training.
  • Multi-Model Training.
  • Effective Web-platform UI.

If you get any errors while running the code, please make a PR.

Thanks for Visiting!!!

If you like the project, do ⭐

Also follow me on GitHub , Kaggle , LinkedIn