{"id":13716973,"url":"https://github.com/szagoruyko/pyinn","last_synced_at":"2025-10-24T00:32:16.456Z","repository":{"id":82253534,"uuid":"90988958","full_name":"szagoruyko/pyinn","owner":"szagoruyko","description":"CuPy fused PyTorch neural networks ops","archived":false,"fork":false,"pushed_at":"2018-02-15T10:59:28.000Z","size":45,"stargazers_count":273,"open_issues_count":16,"forks_count":36,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-24T08:09:04.579Z","etag":null,"topics":["cupy","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/szagoruyko.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-05-11T14:32:40.000Z","updated_at":"2025-03-03T12:38:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"db20f28c-0336-4e22-994e-f7f004b8d921","html_url":"https://github.com/szagoruyko/pyinn","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/szagoruyko%2Fpyinn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fpyinn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fpyinn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fpyinn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szagoruyko","download_url":"https://codeload.github.com/szagoruyko/pyinn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927835,"owners_count":20856198,"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":["cupy","pytorch"],"created_at":"2024-08-03T00:01:16.144Z","updated_at":"2025-10-24T00:32:11.404Z","avatar_url":"https://github.com/szagoruyko.png","language":"Python","funding_links":[],"categories":["Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"readme":"PyINN\n=====\n\nCuPy implementations of fused PyTorch ops.\n\nPyTorch version of [imagine-nn](https://github.com/szagoruyko/imagine-nn)\n\nThe purpose of this package is to contain CUDA ops written in Python\nwith CuPy, which is not a PyTorch dependency.\n\nAn alternative to CuPy would be \u003chttps://github.com/pytorch/extension-ffi\u003e,\nbut it requires a lot of wrapping code like \u003chttps://github.com/sniklaus/pytorch-extension\u003e,\nso doesn't really work with quick prototyping.\n\nAnother advantage of CuPy over C code is that dimensions of each op\nare known at JIT-ing time, and compiled kernels potentially can be faster.\nAlso, the first version of the package was in PyCUDA, but it can't work with\nPyTorch multi-GPU.\n\n~~On Maxwell Titan X pyinn.conv2d_depthwise MobileNets are ~2.6x faster than F.conv2d~~ [benchmark.py](test/benchmark.py)\n\n**No longer the case - with new kernels PyTorch 0.3.0 is now ~20% faster than pyinn.**\n\n## Installation\n\n```\npip install git+https://github.com/szagoruyko/pyinn.git@master\n```\n\n## Example\n\n```python\nimport torch\nfrom torch.autograd import Variable\nimport pyinn as P\nx = Variable(torch.randn(1,4,5,5).cuda())\nw = Variable(torch.randn(4,1,3,3).cuda())\ny = P.conv2d_depthwise(x, w, padding=1)\n```\n\nor with modules interface:\n\n```python\nfrom pyinn.modules import Conv2dDepthwise\nmodule = Conv2dDepthwise(channels=4, kernel_size=3, padding=1).cuda()\ny = module(x)\n```\n\n## Documentation \n\n### conv2d_depthwise\n\nImplements depthwise convolution as in \u003chttps://arxiv.org/abs/1704.04861\u003e\nMobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications\n\nCUDA kernels from https://github.com/BVLC/caffe/pull/5665\n\nCPU side is done by `F.conv2d`.\n\nEquivalent to:\n\n```python\nF.conv2d(input, weight, groups=input.size(1))\n```\n\nInputs and arguments are the same with `F.conv2d`\n\n\n### dgmm\n\nMultiplication with a diagonal matrix.\n\nUsed CUDA dgmm function, sometimes is faster than expand.\n\nIn torch functions does `input.mm(x.diag())`. Both left and right\nmutliplications are supported.\n\nArgs:\n    input: 2D tensor\n    x: 1D tensor\n    \n    \n### cdgmm\n\nComplex multiplication with a diagonal matrix.\n\nDoes `input.mm(x.diag())` where input and x are complex.\n\nArgs:\n    input: 3D tensor with last dimension of size 2\n    x: 2D tensor with last dimension of size 2\n    \n    \n### NCReLU\n\nApplies NCReLU (negative concatenated ReLU) nonlinearity.\n\nDoes `torch.cat([x.clamp(min=0), x.clamp(max=0)], dim=1)` in a single fused op.\n\nUsed in \u003chttps://arxiv.org/abs/1706.00388\u003e\nDiracNets: Training Very Deep Neural Networks Without Skip-Connections\n\nArgs:\n    input: 4D tensor\n\n\n### im2col and col2im\n\nRearrange image blocks into columns.\n\nThe representation is used to perform GEMM-based convolution.\n\nOutput is 5D (or 6D in case of minibatch) tensor.\n\nMinibatch implementation is inefficient, and could be done in a single CUDA kernel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszagoruyko%2Fpyinn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszagoruyko%2Fpyinn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszagoruyko%2Fpyinn/lists"}