PIXELBANKv9.1.0
Menu

Problem Statement

Implement the SiLU / Swish activation out = x * sigmoid(x).

Background

Triton provides tl.sigmoid. SiLU is used in modern transformer MLP blocks.

Your Task

Implement silu_kernel and run(n=1024) comparing to torch.nn.functional.silu.

How it is tested

Your solution must define a top-level function run(...) that allocates inputs on the GPU, launches your Triton kernel, and returns a boolean from torch.allclose(triton_out, torch_reference, ...). The grader prints run(...); the expected output is True.

Example:

Input:
n = 1024
Output:
True
Reasoning:
  • The input value n = 1024 determines the size of the input array for the SiLU kernel implementation.
  • The silu_kernel function calculates the SiLU activation using the formula out=xโ‹…ฯƒ(x)out = x \cdot \sigma(x), where ฯƒ(x)\sigma(x) is the sigmoid function, for each element in the input array.
  • The result from the silu_kernel function is compared to the result from torch.nn.functional.silu using torch.allclose to check for numerical equivalence within a certain tolerance.
  • The comparison yields True if the results are close enough, indicating that the custom silu_kernel implementation matches the PyTorch reference implementation.

Constraints:

  • out = x * tl.sigmoid(x)
  • Mask the tail block
๐Ÿ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Triton SiLU (Swish) Kernel - Medium | PixelBank