{"id":13439210,"url":"https://github.com/KinglittleQ/torch-batch-svd","last_synced_at":"2025-03-20T07:32:38.818Z","repository":{"id":37271550,"uuid":"171496660","full_name":"KinglittleQ/torch-batch-svd","owner":"KinglittleQ","description":"A 100x faster SVD for PyTorch⚡️","archived":false,"fork":false,"pushed_at":"2022-10-10T05:27:38.000Z","size":50,"stargazers_count":425,"open_issues_count":10,"forks_count":35,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-01T03:28:47.641Z","etag":null,"topics":["cusolver","pytorch","svd"],"latest_commit_sha":null,"homepage":"","language":"C++","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/KinglittleQ.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}},"created_at":"2019-02-19T15:17:40.000Z","updated_at":"2024-07-30T07:03:43.000Z","dependencies_parsed_at":"2022-08-08T20:00:43.123Z","dependency_job_id":null,"html_url":"https://github.com/KinglittleQ/torch-batch-svd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinglittleQ%2Ftorch-batch-svd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinglittleQ%2Ftorch-batch-svd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinglittleQ%2Ftorch-batch-svd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinglittleQ%2Ftorch-batch-svd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KinglittleQ","download_url":"https://codeload.github.com/KinglittleQ/torch-batch-svd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221739670,"owners_count":16872768,"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","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":["cusolver","pytorch","svd"],"created_at":"2024-07-31T03:01:12.001Z","updated_at":"2024-10-27T22:30:29.461Z","avatar_url":"https://github.com/KinglittleQ.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# Pytorch Batched SVD\n\n## Introduction\n\nA 100x faster SVD for PyTorch including forward and backward function.\n\nPerformance:\n\n| matrix size      | torch_batch_svd.svd  | torch.svd  |\n| ---------------  |:--------------------:| :---------:|\n| `(10000, 9, 9)`  | **0.043** s          | 19.352 s   |\n| `(20000, 9, 9)`  | **0.073** s          | 34.578 s   |\n\n\n``` python\nimport torch\nfrom torch_batch_svd import svd\n\nA = torch.rand(1000000, 3, 3).cuda()\nu, s, v = svd(A)\nu, s, v = torch.svd(A)  # probably you should take a coffee break here\n```\n\nThe catch here is that it only works for matrices whose row and column are smaller than `32`.\nOther than that, `torch_batch_svd.svd` can be a drop-in for the native one.\n\nThe forward function is modified from [ShigekiKarita/pytorch-cusolver](https://github.com/ShigekiKarita/pytorch-cusolver) and I fixed several bugs of it. The backward function is borrowed from the PyTorch official [svd backward function](https://github.com/pytorch/pytorch/blob/b0545aa85f7302be5b9baf8320398981365f003d/tools/autograd/templates/Functions.cpp#L1476). I converted it to a batched version.\n\n**NOTE**: `batch_svd` supports all `torch.half`, `torch.float` and `torch.double` tensors now.\n\n**NOTE**: SVD for `torch.half` is performed by casting to `torch.float`\nas there is no CuSolver implementation for `c10::half`.\n\n**NOTE**: Sometimes, tests will fail for `torch.double` tensor due to numerical imprecision.\n\n## Get Started\n\n### Requirements\n\n- Pytorch \u003e= 1.0\n\n- CUDA 9.0/10.2 (should work with 10.0/10.1 too)\n\n- Tested in Pytorch 1.4 \u0026 1.5, with CUDA 10.2\n\n### Install\n\n``` shell\nexport CUDA_HOME=/your/cuda/home/directory/\npython setup.py install\n```\n\n### Test\n\n```shell\ncd tests\npython test.py\n```\n\n## Differences between `torch.svd()`\n\n- The sign of column vectors at U and V may be different from `torch.svd()`.\n\n- Much more faster than `torch.svd()` using loop.\n\n## Example\n\nSee `test.py` and [introduction](#1-introduction).\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=KinglittleQ/torch-batch-svd\u0026type=Date)](https://star-history.com/#KinglittleQ/torch-batch-svd\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKinglittleQ%2Ftorch-batch-svd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKinglittleQ%2Ftorch-batch-svd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKinglittleQ%2Ftorch-batch-svd/lists"}