From a0937ce2aea5bd9c836b227aff13292c0569acf1 Mon Sep 17 00:00:00 2001 From: Kunal Mansukhani <24417742+kunal-mansukhani@users.noreply.github.com> Date: Sun, 22 Nov 2026 09:26:27 -0800 Subject: [PATCH] 1D Convolution: compute reference with conv1d instead of materialized unfold+einsum The perf case (1.5M x 2047) made einsum copy the strided windows view into an 11.42 GiB tensor. On a 16 GB T4 with JAX's default 75% GPU preallocation only ~3.4 GiB is free, so every JAX submit on T4 OOMed in the reference. --- challenges/easy/9_1d_convolution/challenge.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/challenges/easy/9_1d_convolution/challenge.py b/challenges/easy/9_1d_convolution/challenge.py index f3f059b2..e30c7a4b 100644 --- a/challenges/easy/9_1d_convolution/challenge.py +++ b/challenges/easy/9_1d_convolution/challenge.py @@ -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