Skip to main content

xonv: Extended convolutional layers

This repository contains the code for extended convolutional layers. These layers are akin to the convolutional layers in PyTorch, but with the key difference that they have spatially varying kernels.

Since the kernels are spatially varying, the convolutional layers in this repository offer more expressive power than the standard convolutional layers while having $\mathcal{O}(n)$ parameters, where $n$ is the input size. The implementation is based on matrix-vector products, which allows for scalable training and inference on GPUs.

Below is a comparison between the toeplitz-like matrix associated with a regular convolutional layer vs the extended convolutional layer (xonv):

Installation

Run the command below to install the package to be used in your Python environment.

pip install xonv

For further development and to run the examples, clone the repository and install the package in editable mode. Make sure to adapt CUDA version in setup.cfg to the one installed on your system.

# Create a new conda environment.
conda create --name xonv "python<=3.12"
conda activate xonv

# Clone the repository and install the package in editable mode.
git clone ttps://github.com/alisiahkoohi/xonv
cd xonv/
pip install -e .

Usage

The extended convolutional layers can be used as a drop-in replacement for the PyTorch convolutional layers. The following example demonstrates how to use the extended convolutional layers:

from xonv.layer import Xonv2D

input_size = (32, 32)  # Height, Width of input
in_channels = 3
out_channels = 16
kernel_size = 3
stride = 2

layer = Xonv2D(
    in_channels,
    out_channels,
    kernel_size,
    input_size,
    stride=stride,
)

input_tensor = torch.randn(1, in_channels, *input_size)
output = layer(input_tensor)

print(layer)  # Xonv2D(in_channels=3, out_channels=16, kernel_size=3, input_size=(32, 32), stride=2)
print(output.shape)  # Should be [1, 16, 16, 16]

Examples

Visualizing the associated linear matrix

To visualize the toeplitz-like matrix associated with the convolutional layer, run the following command:

python scripts/create_toeplitz_like_matrix.py

Comparing the loss landscape of Xonv2d vs torch.nn.Conv2d for a regression task

To compare the loss landscape of the extended convolutional layer with the standard convolutional layer, run the following command:

python scripts/regression_loss_landscape_comparison.py

Comparing convergence rate of Xonv2d vs torch.nn.Conv2d for a regression task

To compare the convergence rate of the extended convolutional layer with the standard convolutional layer, run the following command:

python scripts/regression_convergence_comparison.py

Questions

Please contact alisk@rice.edu for questions.

Author

Ali Siahkoohi

Metadata

Release files for xonv 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xonv 0.2.5
File Size Uploaded
xonv-0.2.5.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xonv 0.2.5
File Interpreter ABI Platform
xonv-0.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 28.6 kB

Release files / xonv-0.2.5.tar.gz

Download URL xonv-0.2.5.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e66dd1c99cfc29755d64e44a8d5c1629d4d98205ce60a8cbcc70519d5ea03a32
BLAKE2b-256 checksum
How to use checksums
7200e9543bb13458bb47d722ea3b885ec2bb69f0171d2abd210196d950cdf4f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.13

Release files / xonv-0.2.5-py3-none-any.whl

Download URL xonv-0.2.5-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31bea40f8133990f5651fee9c323dd5675bf9fd75f705861fbc01b32b3fa19cc
BLAKE2b-256 checksum
How to use checksums
4b8b646f8e396b635139fd015afb997cbc75dd36c1e9af54c0cd0dbd18c26a3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page