{"id":13716896,"url":"https://github.com/sniklaus/pytorch-extension","last_synced_at":"2025-12-25T21:56:53.722Z","repository":{"id":85025920,"uuid":"95942770","full_name":"sniklaus/pytorch-extension","owner":"sniklaus","description":"an example of a CUDA extension for PyTorch using CuPy which computes the Hadamard product of two tensors","archived":false,"fork":false,"pushed_at":"2024-03-01T17:01:28.000Z","size":42,"stargazers_count":117,"open_issues_count":0,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-31T16:52:22.515Z","etag":null,"topics":["cuda","cupy","deep-learning","python","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sniklaus.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":"2017-07-01T04:49:16.000Z","updated_at":"2024-08-12T19:31:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"ac990436-3fe3-4d75-ae46-48057afa8d6c","html_url":"https://github.com/sniklaus/pytorch-extension","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/sniklaus%2Fpytorch-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sniklaus%2Fpytorch-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sniklaus%2Fpytorch-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sniklaus%2Fpytorch-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sniklaus","download_url":"https://codeload.github.com/sniklaus/pytorch-extension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252826878,"owners_count":21810197,"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":["cuda","cupy","deep-learning","python","pytorch"],"created_at":"2024-08-03T00:01:15.503Z","updated_at":"2025-12-25T21:56:53.666Z","avatar_url":"https://github.com/sniklaus.png","language":"Python","funding_links":[],"categories":["Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"readme":"# pytorch-extension\nThis is an example of a CUDA extension/function/layer for PyTorch which uses CuPy to compute the Hadamard product of two tensors.\n\nFor a more advanced extension that uses CuPy as well, please see: https://github.com/sniklaus/softmax-splatting\n\u003cbr /\u003e\nAnd yet another extension that uses CuPy can be found here: https://github.com/sniklaus/revisiting-sepconv\n\n## setup\nMake sure to install CuPy, which can be done using `pip install cupy` or alternatively using one of the provided [binary packages](https://docs.cupy.dev/en/stable/install.html#installing-cupy) as outlined in the CuPy repository.\n\n## usage\nThere is no separate build process necessary, simply run `python run.py` to test it. A minimal example of how the sample extension can be used is also shown below.\n\n```python\nimport torch\n\nimport hadamard # the custom layer\n\nclass Network(torch.nn.Module):\n\tdef __init__(self):\n\t\tsuper().__init__()\n\t# end\n\n\tdef forward(self, tenOne, tenTwo):\n\t\treturn hadamard.hadamard_func.apply(tenOne, tenTwo)\n\t# end\n# end\n\nnetNetwork = Network().cuda()\n\ntenOne = torch.rand(size=[64, 3, 128, 128], dtype=torch.float32, device=torch.device('cuda')).requires_grad_()\ntenTwo = torch.rand(size=[64, 3, 128, 128], dtype=torch.float32, device=torch.device('cuda')).requires_grad_()\n\ntenOut = netNetwork(tenOne, tenTwo)\ntenExpected = torch.mul(tenOne, tenTwo)\n\nprint(torch.sum(tenOut.data - tenExpected.data), '\u003c-- should be 0.0')\n```\n\n## license\nPlease refer to the appropriate file within this repository.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsniklaus%2Fpytorch-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsniklaus%2Fpytorch-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsniklaus%2Fpytorch-extension/lists"}