{"id":17645441,"url":"https://github.com/thesoenke/pytorch-trainer","last_synced_at":"2026-05-03T19:31:03.043Z","repository":{"id":97236026,"uuid":"215616393","full_name":"theSoenke/pytorch-trainer","owner":"theSoenke","description":"Lightweight PyTorch trainer","archived":false,"fork":false,"pushed_at":"2019-11-25T22:23:14.000Z","size":49,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T07:15:03.664Z","etag":null,"topics":["pytorch","trainer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theSoenke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-16T18:24:59.000Z","updated_at":"2023-10-22T10:35:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"0084afb5-0a80-47a0-84c3-6bb0d91989f0","html_url":"https://github.com/theSoenke/pytorch-trainer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/theSoenke/pytorch-trainer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoenke%2Fpytorch-trainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoenke%2Fpytorch-trainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoenke%2Fpytorch-trainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoenke%2Fpytorch-trainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theSoenke","download_url":"https://codeload.github.com/theSoenke/pytorch-trainer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoenke%2Fpytorch-trainer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32582443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytorch","trainer"],"created_at":"2024-10-23T10:56:20.604Z","updated_at":"2026-05-03T19:31:03.014Z","avatar_url":"https://github.com/theSoenke.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyTorch Trainer\n\nLightweight wrapper around PyTorch. Removes boilerplate code to focus on the important parts.\n\n## Example\n```python\nimport os\n\nimport torch\nimport torchvision.transforms as transforms\nfrom module import Module\nfrom torch.nn import functional as F\nfrom torch.utils.data import DataLoader\nfrom torchvision.datasets import MNIST\n\nfrom pytorch_trainer import EarlyStopping, ModelCheckpoint, Module, Trainer\n\nclass MNISTModel(Module):\n    def __init__(self):\n        super().__init__()\n        self.l1 = torch.nn.Linear(28 * 28, 10)\n\n    def forward(self, x):\n        return torch.relu(self.l1(x.view(x.size(0), -1)))\n\n    def training_step(self, batch, batch_num):\n        x, y = batch\n        y_hat = self.forward(x)\n        loss = F.cross_entropy(y_hat, y)\n        return {'loss': loss}\n\n    def validation_step(self, batch, batch_num):\n        x, y = batch\n        output = self.forward(x)\n        return {'val_loss': F.cross_entropy(output, y)}\n\n    def validation_end(self, outputs):\n        avg_loss = torch.stack([x['val_loss'] for x in outputs]).mean()\n        return {'val_loss': avg_loss}\n\n    def configure_optimizers(self):\n        return torch.optim.Adam(self.parameters(), lr=0.02)\n\n    def train_dataloader(self):\n        return DataLoader(MNIST(os.getcwd(), train=True, download=True, transform=transforms.ToTensor()), batch_size=32)\n\n    def val_dataloader(self):\n        return DataLoader(MNIST(os.getcwd(), train=False, download=True, transform=transforms.ToTensor()), batch_size=32)\n\n\ncheckpoint_callback = ModelCheckpoint(\n    directory='./checkpoints',\n    monitor='val_loss',\n    save_best_only=True,\n    mode='min'\n)\nearly_stop_callback = EarlyStopping(\n    monitor='val_loss',\n    min_delta=0.00,\n    patience=5,\n    mode='min'\n)\n\nmodel = MNISTModel()\ntrainer = Trainer(\n    checkpoint_callback=checkpoint_callback,\n    early_stop_callback=early_stop_callback,\n)\ntrainer.fit(model)\n```\n\nInspired by [PyTorch Lightning](https://github.com/williamFalcon/pytorch-lightning)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesoenke%2Fpytorch-trainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesoenke%2Fpytorch-trainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesoenke%2Fpytorch-trainer/lists"}