Metadata-Version: 2.5
Name: xpm-torch
Version: 0.3.0
Summary: Experimaestro module for Pytorch-based experiments
License: GPL-3
Keywords: PyTorch,experimaestro,experiments
Requires-Python: <3.15,>=3.10
Requires-Dist: experimaestro>=2.5.2
Requires-Dist: huggingface-hub>0.17
Requires-Dist: lightning>=2.4
Requires-Dist: safetensors>=0.4
Requires-Dist: setuptools<82.0
Requires-Dist: tensorboard>=2.19.0
Requires-Dist: torchdata>=0.10
Requires-Dist: xpm-mlboard[tensorboard]>=0.2.0
Description-Content-Type: text/markdown

# xpm-torch

[![PyPI version](https://badge.fury.io/py/xpm-torch.svg)](https://badge.fury.io/py/xpm-torch)
[![RTD](https://app.readthedocs.org/projects/xpm-torch/badge/?version=stable)](https://xpm-torch.readthedocs.io/en/stable/)

PyTorch training framework built on [experimaestro](https://experimaestro-python.readthedocs.io/) and [Lightning Fabric](https://lightning.ai/docs/fabric/).

## Documentation

The full documentation is at [xpm-torch.readthedocs.io](https://xpm-torch.readthedocs.io/en/stable/):

- [Overview](https://xpm-torch.readthedocs.io/en/stable/overview.html) — what's in the package and how it fits together
- [Module system](https://xpm-torch.readthedocs.io/en/stable/module.html) — `Module`, `ModuleLoader` and safetensors serialization
- [Training](https://xpm-torch.readthedocs.io/en/stable/training.html) — `Learner`, trainers, checkpointing and validation
- [Optimization](https://xpm-torch.readthedocs.io/en/stable/optimization.html) — optimizers, schedulers and gradient hooks
- [HuggingFace Hub](https://xpm-torch.readthedocs.io/en/stable/huggingface.html) — export actions, pushing and loading models

## Features

- **Module system**: `Module` base class combining experimaestro `Config` with `torch.nn.Module`, with safetensors serialization
- **Training**: `Learner` task with checkpointing, validation listeners, and TensorBoard logging
- **HuggingFace Hub**: Upload/download models via `ExperimaestroHFHub` (from experimaestro)
- **Distributed training**: Lightning Fabric integration for multi-GPU/node training

## Installation

```bash
pip install xpm-torch
```

## Quick Start

```python
from xpm_torch.module import Module
from experimaestro import Param
import torch
import torch.nn as nn


class MyModel(Module):
    input_dim: Param[int]
    hidden_dim: Param[int]

    def __initialize__(self):
        self.fc1 = nn.Linear(self.input_dim, self.hidden_dim)

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


# Create config, then instance
cfg = MyModel.C(input_dim=50, hidden_dim=100)
model = cfg.instance()
model.initialize()

# Save/load with safetensors
from pathlib import Path

model.save_model(Path("checkpoint/model"))
model.load_model(Path("checkpoint/model"))
```

## License

GPL-3.0
