# ModelBatch
**Train many independent PyTorch models simultaneously on a single GPU using vectorized operations.**
[](https://www.python.org/downloads/)
[](https://pytorch.org/)
## ⚠️ Current Status
**ModelBatch is still in active development. Core functionality is tested and working, but the API may be subject to change.**
## 🚀 Quick Start
### Installation
From PyPI:
```bash
# recommended
uv add modelbatch
# alternative
pip install modelbatch
```
From source:
```bash
uv sync --dev
uv pip install -e ".[dev]"
```
### Basic Example
```python
import torch
from modelbatch import ModelBatch
# Create multiple models
num_models = 4 # choose the number of models to batch
models = [SimpleNet() for _ in range(num_models)]
# Wrap with ModelBatch - that's it!
mb = ModelBatch(models, lr_list=[0.001] * num_models, optimizer_cls=torch.optim.Adam)
# Train normally (but many times faster!), batched across models
for batch in dataloader:
mb.zero_grad()
outputs = mb(batch)
loss = mb.compute_loss(outputs, targets)
loss.backward()
mb.step()
```
See [here](examples) for more examples.
## 📚 Documentation
See [docs](https://rock-z.github.io/ModelBatch/).
## 🛠️ Development
### Environment Setup
```bash
uv sync --dev
```
### Commands
```bash
# Tests (currently showing failures)
uv run -m pytest
# Linting
uv run ruff check --fix . && uv run ruff format .
# Documentation
uv run mkdocs serve
```
## 📄 License
This project is licensed under the [MIT License](LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "modelbatch",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "pytorch, machine learning, vectorization, gpu, training",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/4a/57/a0c368dfc14c9c0ca0d61782957a6c9dab661eadf4a67b06ca22ac01029e/modelbatch-0.1.0.tar.gz",
"platform": null,
"description": "# ModelBatch\n\n**Train many independent PyTorch models simultaneously on a single GPU using vectorized operations.**\n\n[](https://www.python.org/downloads/)\n[](https://pytorch.org/)\n\n## \u26a0\ufe0f Current Status\n\n**ModelBatch is still in active development. Core functionality is tested and working, but the API may be subject to change.**\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\nFrom PyPI:\n\n```bash\n# recommended\nuv add modelbatch\n\n# alternative\npip install modelbatch\n```\n\nFrom source:\n\n```bash\nuv sync --dev\nuv pip install -e \".[dev]\"\n```\n\n### Basic Example\n\n```python\nimport torch\nfrom modelbatch import ModelBatch\n\n# Create multiple models\nnum_models = 4 # choose the number of models to batch\nmodels = [SimpleNet() for _ in range(num_models)]\n\n# Wrap with ModelBatch - that's it!\nmb = ModelBatch(models, lr_list=[0.001] * num_models, optimizer_cls=torch.optim.Adam)\n\n# Train normally (but many times faster!), batched across models\nfor batch in dataloader:\n mb.zero_grad()\n outputs = mb(batch)\n loss = mb.compute_loss(outputs, targets) \n loss.backward()\n mb.step()\n```\n\nSee [here](examples) for more examples.\n\n## \ud83d\udcda Documentation\n\nSee [docs](https://rock-z.github.io/ModelBatch/).\n\n## \ud83d\udee0\ufe0f Development\n\n### Environment Setup\n\n```bash\nuv sync --dev\n```\n\n### Commands\n\n```bash\n# Tests (currently showing failures)\nuv run -m pytest\n\n# Linting \nuv run ruff check --fix . && uv run ruff format .\n\n# Documentation\nuv run mkdocs serve\n```\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the [MIT License](LICENSE).\n",
"bugtrack_url": null,
"license": null,
"summary": "Train many independent PyTorch models simultaneously on a single GPU using vectorized operations",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [
"pytorch",
" machine learning",
" vectorization",
" gpu",
" training"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "afbbe54d8e7cf5fbb1d396c0085044869e4619cd0ab26403a42ed172b1681f9c",
"md5": "f79e12c97b2904cf7b40d6f599d74a6a",
"sha256": "b17edaef56a878e2e78d512f0a2886c5fad5be0b0bc5a07e2ec7a162cfec5633"
},
"downloads": -1,
"filename": "modelbatch-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f79e12c97b2904cf7b40d6f599d74a6a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 28951,
"upload_time": "2025-08-22T01:22:05",
"upload_time_iso_8601": "2025-08-22T01:22:05.113377Z",
"url": "https://files.pythonhosted.org/packages/af/bb/e54d8e7cf5fbb1d396c0085044869e4619cd0ab26403a42ed172b1681f9c/modelbatch-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4a57a0c368dfc14c9c0ca0d61782957a6c9dab661eadf4a67b06ca22ac01029e",
"md5": "da6a8f5e5c88b4a4f0928cb7fa2b0560",
"sha256": "1671de7f667c62d35c87e88717e79c8d358f55309a9819f4b728ba20268a8f7c"
},
"downloads": -1,
"filename": "modelbatch-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "da6a8f5e5c88b4a4f0928cb7fa2b0560",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 45194,
"upload_time": "2025-08-22T01:22:06",
"upload_time_iso_8601": "2025-08-22T01:22:06.502545Z",
"url": "https://files.pythonhosted.org/packages/4a/57/a0c368dfc14c9c0ca0d61782957a6c9dab661eadf4a67b06ca22ac01029e/modelbatch-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-22 01:22:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "modelbatch"
}