All problems
ConvNeXt Block (1D)
Problem
Forward pass of a simplified 1D ConvNeXt block. For each channel: apply a depthwise convolution with the shared kernel and same padding, normalize the result over the length dimension (LayerNorm), scale by the per-channel gamma, and add the residual: out = x + gamma * LN(DW(x)).
The signature is convnext_block_1d(x, dw_kernel, gamma, eps=1e-5). x has shape (channels, length).
Hint
ConvNeXt mixes a depthwise spatial conv with an inverted-bottleneck channel MLP; this simplified block keeps the depthwise conv, LayerNorm and layer scale.
Test cases
case 1
in: [[[1,2,3]],[1,1,1],[1]]
expected: [[-0.3363019143,3.0690415315,3.2672603829]]
case 2
in: [[[1,2,3],[4,5,6]],[1,1,1],[1,1]]
expected: [[-0.3363019143,3.0690415315,3.2672603829],[2.9309558914,6.3363051357,5.7327389729]]
case 3
in: [[[1,2,3]],[0,1,0],[0.5]]
expected: [[0.387632157,2,3.612367843]]
case 4
in: [[[1,2,3]],[1,1,1],[0]]
expected: [[1,2,3]]
Starter codePython
import math
def convnext_block_1d(x, dw_kernel, gamma, eps=1e-5):
# Your code here
pass4 test cases · run your code against them in the editor