Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions challenges/easy/9_1d_convolution/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ def reference_impl(
assert input.dtype == kernel.dtype == output.dtype
assert input.device == kernel.device == output.device

# Create strided view of input for all windows
windows = input.unfold(0, kernel_size, 1)

# Use einsum for explicit cross-correlation
# 'ij,j->i' means: for each window i, multiply with kernel j and sum over j
output.copy_(torch.einsum("ij,j->i", windows, kernel))
# Cross-correlation, valid padding, stride 1. conv1d avoids materializing the
# (output_size, kernel_size) windows matrix, which is 11.4 GiB at the
# performance size and OOMs on a 16 GB T4 next to JAX's GPU preallocation.
result = torch.nn.functional.conv1d(input.view(1, 1, -1), kernel.view(1, 1, -1))
output.copy_(result.view(-1))

def reference_impl_jax(self, input, kernel, input_size, kernel_size):
import jax
Expand Down
Loading