unfoldNd
N-dimensional unfold (im2col) and fold (col2im) in PyTorch
Decision gist · record as of 2026-08-14
Yes, if you work with 3D, 4D, or 5D convolutions and need the im2col perspective for optimization or custom AD. The package is production-stable, actively maintained, has no known vulnerabilities, and offers measurable speed improvements over workarounds. Install only if you actually need higher-dimensional unfold; it's a specialized tool, not a general PyTorch enhancement.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires PyTorch and NumPy installed; intended for use with higher-dimensional tensor operations in convolution-based workflows.
- Low friction installation with a pure Python wheel.
- The package is actively maintained with a recent release (2024-12-30) and depends only on packaging, torch, and numpy—all standard in PyTorch workflows.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
last release 2024-12-30 (592 days) · last repo commit 2026-07-17 · 109 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 105,303 downloads/mo, #12,707 on PyPI
Alternatives
Verify before relying
pip install unfoldNd
import unfoldNd
import torch
# Unfold a 5D tensor (batch, channels, depth, height, width)
x = torch.randn(2, 3, 4, 5, 6)
unfolded = unfoldNd.unfoldNd(x, kernel_size=3, padding=1)
# Returns unfolded view suitable for convolution-as-matrix-multiplication- Whether fold operations (col2im) have equivalent performance to unfold operations, as the description notes fold is not benchmarked.
- Memory overhead characteristics in production settings beyond the documented benchmark configurations.
- Compatibility with recent PyTorch versions beyond 3.10 support stated in classifiers.
What it is and what it does
unfoldNd generalizes PyTorch's im2col (unfold) and col2im (fold) operations to tensors with more than 4 dimensions. PyTorch's native torch.nn.functional.unfold and torch.nn.Unfold only work on 4D batched image tensors; this package extends that functionality to 3D, 4D, and 5D inputs using a numerical trick based on one-hot kernels and group convolutions.
The package is useful when you need to express convolutions as matrix-matrix multiplications on higher-dimensional data—a perspective that enables certain optimization techniques and automatic differentiation patterns. It trades some additional peak memory usage for speed gains in both forward and backward passes compared to native PyTorch operations. The package also exposes transpose convolution unfolding (unfoldTransposeNd) and fold operations (foldNd), though fold is tested but not benchmarked.
Use it for
- Implementing second-order optimization methods like KFAC that approximate the Fisher matrix using Kronecker factors on volumetric (3D) convolutions.
- Expressing 3D or 5D convolutions as explicit matrix multiplications for custom automatic differentiation or layer implementations.
- Unfolding inputs for transpose convolutions in higher dimensions where PyTorch provides no native support.
- Research on convolution-as-linear-layer perspectives in deep learning frameworks like BackPACK.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you work with 3D, 4D, or 5D convolutions and need the im2col perspective for optimization or custom AD.
The package is production-stable, actively maintained, has no known vulnerabilities, and offers measurable speed improvements over workarounds. Install only if you actually need higher-dimensional unfold; it's a specialized tool, not a general PyTorch enhancement.
Install
unfoldnd on PyPI
Before you install
Low friction installation with a pure Python wheel. The package is actively maintained with a recent release (2024-12-30) and depends only on packaging, torch, and numpy—all standard in PyTorch workflows.
Requires PyTorch and NumPy installed; intended for use with higher-dimensional tensor operations in convolution-based workflows.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
Quickstart
pip install unfoldNd
import unfoldNd
import torch
# Unfold a 5D tensor (batch, channels, depth, height, width)
x = torch.randn(2, 3, 4, 5, 6)
unfolded = unfoldNd.unfoldNd(x, kernel_size=3, padding=1)
# Returns unfolded view suitable for convolution-as-matrix-multiplication
Verify before relying
- Whether fold operations (col2im) have equivalent performance to unfold operations, as the description notes fold is not benchmarked.
- Memory overhead characteristics in production settings beyond the documented benchmark configurations.
- Compatibility with recent PyTorch versions beyond 3.10 support stated in classifiers.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagespackagingtorchnumpy |
| Maintenance | Actively maintained 592 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 105,303 / month, #12,707 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: unfoldNd-0.2.3-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pytorch unfold higher dimensions”
- unfoldNdExtends PyTorch's unfold and fold operations to 3D, 4D, and 5D…
- torchtypingAdds type annotations for PyTorch tensor shape, dtype, layout, and…
- torchsrProvides pretrained neural network models for image super-resolution…
Give your agent the search over MCP, or paste the wish link into any chat.
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to call 100+ LLM providers (OpenAI, Anthropic, Gemini, Bedrock, Azure, and others) using OpenAI-compatible API format, available as both a Python SDK and a self-hosted AI Gateway proxy server.
Install it if you need to work with multiple LLM providers or want to centralize LLM routing in your organization.
Client library and CLI tool for downloading, uploading, and managing models, datasets, and repositories on the Hugging Face Hub platform.
Install it if you work with Hugging Face Hub models or datasets.
LangChain provides a framework for building agents and LLM-powered applications by composing language models, tools, and memory through a unified API that abstracts over multiple model providers.
hf-xet provides chunk-based deduplication and efficient file transfer for the Hugging Face Hub, enabling faster uploads and downloads of large files with local disk caching.
Tokenizers converts raw text into token sequences for NLP models, with support for training custom vocabularies and using pre-built tokenizers (BPE, WordPiece) optimized for speed via Rust.
Transformers provides a unified framework for loading, fine-tuning, and running state-of-the-art pretrained models across text, vision, audio, video, and multimodal tasks using PyTorch, JAX, or TensorFlow.
Install it if you need to run or train any transformer-based model for NLP, vision, audio, or multimodal tasks.
See also resize-right · torch · pytorchcv · causal-conv1d · sparse · nvidia-cusparse · nvidia-cusolver-cu11 · nvidia-cublas · torchinfo · torch-einops-utils