{"id":15600938,"url":"https://github.com/lucidrains/pytorch-custom-utils","last_synced_at":"2025-10-12T03:33:49.804Z","repository":{"id":212304931,"uuid":"730816835","full_name":"lucidrains/pytorch-custom-utils","owner":"lucidrains","description":"Just some miscellaneous utility functions / decorators / modules related to Pytorch and Accelerate to help speed up implementation of new AI research","archived":false,"fork":false,"pushed_at":"2024-07-26T23:28:33.000Z","size":24,"stargazers_count":124,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-09-24T11:23:59.015Z","etag":null,"topics":["accelerate","pytorch"],"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/lucidrains.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":"2023-12-12T18:29:29.000Z","updated_at":"2025-07-15T09:35:00.000Z","dependencies_parsed_at":"2023-12-13T15:44:22.097Z","dependency_job_id":"a94ce78d-9d1a-4fcc-bbfd-e20e8ccfc9f7","html_url":"https://github.com/lucidrains/pytorch-custom-utils","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":0.07692307692307687,"last_synced_commit":"a452e954eb47b907249e6c13afb22ad670224e85"},"previous_names":["lucidrains/pytorch-custom-utils"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/lucidrains/pytorch-custom-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fpytorch-custom-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fpytorch-custom-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fpytorch-custom-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fpytorch-custom-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/pytorch-custom-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fpytorch-custom-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010149,"owners_count":26084692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["accelerate","pytorch"],"created_at":"2024-10-03T02:09:46.936Z","updated_at":"2025-10-12T03:33:49.788Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Pytorch Custom Utils (wip)\n\nJust some miscellaneous utility functions / decorators / modules related to Pytorch and \u003ca href=\"https://huggingface.co/docs/accelerate/index\"\u003eAccelerate\u003c/a\u003e to help speed up implementation of new AI research\n\n## Install\n\n```bash\n$ pip install pytorch-custom-utils\n```\n\n### Quick save and load\n\nClass decorator for adding a quick `save` and `load` method to the module instance. Can also initialize the entire network with a class method, `init_and_load`.\n\nex.\n\n```python\nimport torch\nfrom torch import nn\n\nfrom pytorch_custom_utils import save_load\n\n# decorate the entire class with `save_load` class decorator\n\n@save_load()\nclass MLP(nn.Module):\n    def __init__(self, dim):\n        super().__init__()\n        self.net = nn.Sequential(nn.Linear(dim, dim), nn.SiLU(), nn.Linear(dim, dim))\n\n    def forward(self, x):\n        return self.net(x)\n\n# instantiated mlp\n\nmlp = MLP(dim = 512)\n\n# now you have a save and load method\n\nmlp.save('./mlp.pt')\nmlp.load('./mlp.pt')\n\n# you can also directly initialize from the checkpoint, without having to save the corresponding hyperparameters (in this case, dim = 512)\n\nmlp = MLP.init_and_load('./mlp.pt')\n```\n\n### Keep track of device on module\n\nex.\n\n```python\nimport torch\nfrom torch import nn\n\nfrom pytorch_custom_utils import module_device\n\n# decorate the class with `module_device` class decorator\n\n@module_device()\nclass MLP(nn.Module):\n    def __init__(self, dim):\n        super().__init__()\n        self.net = nn.Linear(dim, dim)\n\n    def forward(self, x):\n        return self.net(x)\n\n# instantiated mlp\n\nmlp = MLP(dim = 512)\nmlp.to(torch.device('mps'))\n\n# now you have a convenient .device\n\nmlp.device # mps:0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fpytorch-custom-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Fpytorch-custom-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fpytorch-custom-utils/lists"}