{"id":16475571,"url":"https://github.com/f-dangel/einconv","last_synced_at":"2025-09-04T23:32:14.086Z","repository":{"id":178430909,"uuid":"577671881","full_name":"f-dangel/einconv","owner":"f-dangel","description":"Convolutions and more as einsum for PyTorch","archived":false,"fork":false,"pushed_at":"2024-06-06T15:49:55.000Z","size":256,"stargazers_count":16,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-10T00:20:04.176Z","etag":null,"topics":["convolution","einsum","einsum-notation","fisher","ggn","im2col","jvp","kfac","ntk","pytorch","tensornetwork","transpose-convolution","vjp"],"latest_commit_sha":null,"homepage":"https://einconv.readthedocs.io/en/latest/","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/f-dangel.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-12-13T09:08:34.000Z","updated_at":"2025-04-09T04:20:47.000Z","dependencies_parsed_at":"2024-06-05T16:34:59.794Z","dependency_job_id":null,"html_url":"https://github.com/f-dangel/einconv","commit_stats":null,"previous_names":["f-dangel/einconv"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/f-dangel/einconv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-dangel%2Feinconv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-dangel%2Feinconv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-dangel%2Feinconv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-dangel%2Feinconv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f-dangel","download_url":"https://codeload.github.com/f-dangel/einconv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-dangel%2Feinconv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273688223,"owners_count":25150285,"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-09-04T02:00:08.968Z","response_time":61,"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":["convolution","einsum","einsum-notation","fisher","ggn","im2col","jvp","kfac","ntk","pytorch","tensornetwork","transpose-convolution","vjp"],"created_at":"2024-10-11T12:39:09.553Z","updated_at":"2025-09-04T23:32:09.065Z","avatar_url":"https://github.com/f-dangel.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg alt=\"Einconv:\" src=\"./docs/logo_transparent.png\" height=\"90\"\u003e Convolutions Through the Lens of Tensor Networks\n\nThis package offers `einsum`-based implementations of convolutions and related\noperations in PyTorch.\n\nIts name is inspired by [this](https://github.com/pfnet-research/einconv) Github\nrepository which represented the starting point for our work.\n\n## Installation\nInstall from PyPI via `pip`\n\n```sh\npip install einconv\n```\n\n## Examples\n\n- [Basic\n  example](https://einconv.readthedocs.io/en/latest/tutorials/basic_conv2d/)\n\n- For more tutorials, check out the\n  [docs](https://einconv.readthedocs.io/en/latest/)\n\n## Features \u0026 Usage\n\nIn general, `einconv`'s goals are:\n\n- Full hyper-parameter support (stride, padding, dilation, groups, etc.)\n- Support for any dimension (e.g. 5d-convolution)\n- Optimizations via symbolic simplification\n\n### Modules\n\n`einconv` provides `einsum`-based implementations of the following PyTorch modules:\n\n| `torch` module    | `einconv` module   |\n|-------------------|--------------------|\n| `nn.Conv{1,2,3}d` | `modules.ConvNd`   |\n| `nn.Unfold`       | `modules.UnfoldNd` |\n\nThey work in exactly the same way as their PyTorch equivalents.\n\n### Functionals\n\n`einconv` provides `einsum`-based implementations of the following PyTorch functionals:\n\n| `torch` functional           | `einconv` functional   |\n|------------------------------|------------------------|\n| `nn.functional.conv{1,2,3}d` | `functionals.convNd`   |\n| `nn.functional.unfold`       | `functionals.unfoldNd` |\n\nThey work in exactly the same way as their PyTorch equivalents.\n\n### Einsum Expressions\n`einconv` can generate `einsum` expressions (equation, operands, and output\nshape) for the following operations:\n\n- Forward pass of `N`-dimensional convolution\n- Backward pass (input and weight VJPs) of `N`-dimensional convolution\n- Input unfolding (`im2col/unfold`) for inputs of `N`-dimensional convolution\n- Input-based Kronecker factors of Fisher approximations for convolutions (KFC\n  and KFAC-reduce)\n\nThese can then be evaluated with `einsum`. For instance, the `einsum` expression\nfor the forward pass of an `N`-dimensional convolution is\n\n```py\nfrom torch import einsum\nfrom einconv.expressions import convNd_forward\n\nequation, operands, shape = convNd_forward.einsum_expression(...)\nresult = einsum(equation, *operands).reshape(shape)\n```\n\nAll expressions follow this pattern.\n\n### Symbolic Simplification\n\nSome operations (e.g. dense convolutions) can be optimized via symbolic\nsimplifications. This is turned on by default as it generally improves\nperformance. You can also generate a non-optimized expression and simplify it:\n\n```py\nfrom einconv import simplify\n\nequation, operands, shape = convNd_forward.einsum_expression(..., simplify=False)\nequation, operands = simplify(equation, operands)\nresult = einsum(equation, *operands).reshape(shape)\n```\n\nSometimes it might be better to inspect the non-simplified expression to see how\nindices relate to operands.\n\n## Citation\n\nIf you find the `einconv` package useful for your research, consider mentioning\nthe accompanying article\n\n```bib\n\n@article{dangel2023convolutions,\n  title =        {Convolutions Through the Lens of Tensor Networks},\n  author =       {Dangel, Felix},\n  year =         2023,\n}\n\n```\n## Limitations\n\n- Currently, none of the underlying operations (computation of index pattern\n  tensors, generation of einsum equations and shapes, simplification) is cached.\n  This consumes additional time, although it should usually take much less time\n  than evaluating an expression via `einsum`.\n\n- At the moment, the code to perform expression simplifications is coupled with\n  PyTorch. I am planning to address this in the future by switching the\n  implementation to a symbolic approach which will also allow efficient caching.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-dangel%2Feinconv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff-dangel%2Feinconv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-dangel%2Feinconv/lists"}