Metadata-Version: 2.1
Name: torchmate
Version: 0.1.0
Summary: Torchmate: A High level PyTorch Training Library
Author: Abdullah Saihan Taki
Author-email: saihan0176@gmail.com
License: MIT
Project-URL: Homepage, https://github.com/SaihanTaki/torchmate
Project-URL: Documentation, https://torchmate.readthedocs.io/en/latest/
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9.0
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: numpy >=1.26.4
Requires-Dist: wandb >=0.16.3
Requires-Dist: matplotlib >=3.8.3
Provides-Extra: all
Requires-Dist: pytest >=8.0.1 ; extra == 'all'
Requires-Dist: pytest-mock >=3.12.0 ; extra == 'all'
Requires-Dist: coverage >=7.4.1 ; extra == 'all'
Requires-Dist: six >=1.16.0 ; extra == 'all'
Requires-Dist: pre-commit >=3.6.2 ; extra == 'all'
Requires-Dist: black >=24.1.1 ; extra == 'all'
Requires-Dist: flake8 >=7.0.0 ; extra == 'all'
Requires-Dist: isort >=5.13.2 ; extra == 'all'
Requires-Dist: Sphinx ==7.2.6 ; extra == 'all'
Requires-Dist: sphinx-copybutton ==0.5.2 ; extra == 'all'
Requires-Dist: sphinx-notfound-page ==1.0.0 ; extra == 'all'
Requires-Dist: sphinx-rtd-theme ==2.0.0 ; extra == 'all'
Requires-Dist: sphinxcontrib-applehelp ==1.0.8 ; extra == 'all'
Requires-Dist: sphinxcontrib-devhelp ==1.0.6 ; extra == 'all'
Requires-Dist: sphinxcontrib-htmlhelp ==2.0.5 ; extra == 'all'
Requires-Dist: sphinxcontrib-jquery ==4.1 ; extra == 'all'
Requires-Dist: sphinxcontrib-jsmath ==1.0.1 ; extra == 'all'
Requires-Dist: sphinxcontrib-qthelp ==1.0.7 ; extra == 'all'
Requires-Dist: sphinxcontrib-serializinghtml ==1.1.10 ; extra == 'all'
Requires-Dist: autodocsumm ==0.2.12 ; extra == 'all'
Requires-Dist: nbsphinx ==0.9.3 ; extra == 'all'
Provides-Extra: dev
Requires-Dist: pytest >=8.0.1 ; extra == 'dev'
Requires-Dist: pytest-mock >=3.12.0 ; extra == 'dev'
Requires-Dist: coverage >=7.4.1 ; extra == 'dev'
Requires-Dist: six >=1.16.0 ; extra == 'dev'
Requires-Dist: pre-commit >=3.6.2 ; extra == 'dev'
Requires-Dist: black >=24.1.1 ; extra == 'dev'
Requires-Dist: flake8 >=7.0.0 ; extra == 'dev'
Requires-Dist: isort >=5.13.2 ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: Sphinx ==7.2.6 ; extra == 'docs'
Requires-Dist: sphinx-copybutton ==0.5.2 ; extra == 'docs'
Requires-Dist: sphinx-notfound-page ==1.0.0 ; extra == 'docs'
Requires-Dist: sphinx-rtd-theme ==2.0.0 ; extra == 'docs'
Requires-Dist: sphinxcontrib-applehelp ==1.0.8 ; extra == 'docs'
Requires-Dist: sphinxcontrib-devhelp ==1.0.6 ; extra == 'docs'
Requires-Dist: sphinxcontrib-htmlhelp ==2.0.5 ; extra == 'docs'
Requires-Dist: sphinxcontrib-jquery ==4.1 ; extra == 'docs'
Requires-Dist: sphinxcontrib-jsmath ==1.0.1 ; extra == 'docs'
Requires-Dist: sphinxcontrib-qthelp ==1.0.7 ; extra == 'docs'
Requires-Dist: sphinxcontrib-serializinghtml ==1.1.10 ; extra == 'docs'
Requires-Dist: autodocsumm ==0.2.12 ; extra == 'docs'
Requires-Dist: nbsphinx ==0.9.3 ; extra == 'docs'
Provides-Extra: style
Requires-Dist: pre-commit >=3.6.2 ; extra == 'style'
Requires-Dist: black >=24.1.1 ; extra == 'style'
Requires-Dist: flake8 >=7.0.0 ; extra == 'style'
Requires-Dist: isort >=5.13.2 ; extra == 'style'
Provides-Extra: tests
Requires-Dist: pytest >=8.0.1 ; extra == 'tests'
Requires-Dist: pytest-mock >=3.12.0 ; extra == 'tests'
Requires-Dist: coverage >=7.4.1 ; extra == 'tests'
Requires-Dist: six >=1.16.0 ; extra == 'tests'


<div align="center">
 
![logo](https://i.ibb.co/tzsKgkR/Torchmate-logo-v1.png)  
**A High level PyTorch Training and Utility Library**

[![Read the Docs](https://img.shields.io/readthedocs/torchmate?style=flat&logo=readthedocs&logoColor=orange&color=blue)](https://torchmate.readthedocs.io/en/latest/)
[![PyPI](https://img.shields.io/pypi/v/torchmate?style=flat)](https://pypi.org/project/torchmate/)
[![Code style: black](https://img.shields.io/badge/Code%20Style-black-000000.svg)](https://github.com/psf/black)
[![MIT License](https://img.shields.io/badge/License-MIT-<COLOR>.svg?style=flat)](https://github.com/SaihanTaki/torchmate/blob/master/LICENSE.txt)
[![Python Version](https://img.shields.io/pypi/pyversions/torchmate?style=flat)](https://www.python.org/)
 

</div>

### [📚 Project Documentation](https://torchmate.readthedocs.io/en/latest/)

Visit [Torchmate's Read The Docs Project Page](https://torchmate.readthedocs.io/en/latest/) or read following README to know more about Torchmate library


### 💡 Introduction

So, why did I write Torchmate? I was a big fan of TensorFlow and Keras. But during my undergrad thesis I needed to use PyTorch. I was astonished with PyToroch’s flexibility. But I had to write the same boilerplate code which was quite frustrating to me. So, I decided to use a high level library like Catalyst or Lightning. Catalyst was great, but I missed Keras's verbose training output (which is cleaner) for better visualization (I know it's not a very good reason for writing a library). Pytorch Lightning also very good, but it changes a lot how we usually structure our code. Additionally, I was curious about how high-level frameworks like Keras, Catalyst, or Lightning work internally and utilize callbacks for extending functionalities. Building a minimalistic library myself seemed like the best way to understand these concepts. So, that's why I built Torchmate. Torchmate incorporates everything (actually not everything, some functionalities are still under development) I need and the way I prefere as a deep learning practitioner. 


### 🔑 Key Features

- **Encapsulate all training essentials:** Model, data loaders, loss function, optimizer, and learning rate schedulers.
- **Mixed precision training (AMP):** Train faster and potentially achieve better generalization with mixed precision calculations.
- **Gradient Accumulation:** Train on larger batches virtually by accumulating gradients, improving memory efficiency (Implemented through callback).
- **Gradient Clipping:** Prevent exploding gradients and stabilize training (Implemented through callback).
- **Gradient Penalty:** Enhance stability in generative models like GANs.
- **Callback Mechanism:** Monitor progress, save checkpoints, early stopping and extend functionality with custom callbacks.
- **Experiment Tracking:** Integrate dedicated tools like Weights & Biases or TensorBoard through callbacks.
- **Minimal Dependency:** Torchmate only requires four dependencies-  PyTorch (of course), NumPy, Matplotlib, and Weights & Biases (Wandb).
- **Research Paper Modules:** Implementations of various modules from research papers, facilitating reproducibility and experimentation.


### ⚙️ Installation

First make sure that PyTorch is installed on your envioronment. Then install torchmate via pip.

**From PyPI:**
```Bash
$ pip install torchmate
```
**From Source:**
```Bash
$ pip install git+https://github.com/SaihanTaki/torchmate
```

<br>

**N.B.** Torchmate requires the PyTorch (Of course) library to function. But torchmate does not list PyTorch as a dependency to avoid unnecessary overhead during installation. Excluding PyTorch as a dependency allows users to explicitly install the version of PyTorch best suited for their specific needs and environment. For instance, users who don't require GPU acceleration can install the CPU-only version of PyTorch, reducing unnecessary dependencies and installation size.PyTorch Installation Page: https://pytorch.org/get-started/locally/


### ⏳ Quick Example

```python
import torch
import numpy as np
from torchmate.trainer import Trainer
from sklearn.model_selection import train_test_split

# Create a simple neural network model
class SimpleModel(torch.nn.Module):
    def __init__(self):
        super(SimpleModel, self).__init__()
        self.fc1 = torch.nn.Linear(1, 1)

    def forward(self, x):
        return self.fc1(x) 

# Create synthetic data
X = torch.tensor(np.random.rand(1000, 1), dtype=torch.float32)
y = 2 * X + 1 + torch.randn(1000, 1) * 0.1  # Adding some noise

# Split the data into training and validation sets
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)

# Create DataLoader objects for training and validation
train_dataset = torch.utils.data.TensorDataset(X_train, y_train)
train_dataloader = torch.utils.data.DataLoader(train_dataset, batch_size=8, shuffle=True)
val_dataset = torch.utils.data.TensorDataset(X_val, y_val)
val_dataloader = torch.utils.data.DataLoader(val_dataset, batch_size=8, shuffle=False)

model = SimpleModel()
loss_fn = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
device = 'cuda:0' if torch.cuda.is_available() else 'cpu'


# Create a Trainer instance
trainer = Trainer(
    model,
    train_dataloader,
    val_dataloader,
    loss_fn,
    optimizer,
    num_epochs=3,
    device=device
)


# Train the model
history = trainer.fit()

```



### 🛡️ License <a name="license"></a>
Torchmate is distributed under [MIT License](https://github.com/SaihanTaki/torchmate/blob/master/LICENSE.txt)
