TensorTonic
Problems
Dropout (Inverted Scaling) in Triton
GPU ProgrammingNeural Networks
Easy

Implement inference-time dropout in Triton with an externally provided mask. Given an input xxx, a precomputed 0/10/10/1 mask, and a drop probability ppp:

out[i]=x[i]⋅mask[i]⋅11−p\texttt{out}[i] = x[i] \cdot \texttt{mask}[i] \cdot \frac{1}{1 - p}out[i]=x[i]⋅mask[i]⋅1−p1​

This is a pure elementwise map: one tile per program, with a tail mask to handle lengths that are not multiples of the block. The dropout mask is supplied by the caller rather than generated inside the kernel, so this problem isolates the launch and masking pattern without pulling in an on-device random number generator.

Loading visualization...

Examples

Input: x = [1.0, 2.0, 3.0, 4.0], mask = [1, 0, 1, 0], p = 0.5

Output: [2.0, 0.0, 6.0, 0.0]

Input: x = [1.0, 2.0, 3.0], mask = [1, 1, 1], p = 0.0

Output: [1.0, 2.0, 3.0]

Hint 1

Load xxx and the dropout mask under the same tail mask. The dropout mask is a regular float tensor of zeros and ones; just multiply.

Hint 2

Compute the inverted-scaling factor 1/(1−p)1 / (1 - p)1/(1−p) once per program from the scalar ppp. Triton broadcasts the Python float to every lane automatically.

Hint 3

No reduction. The kernel is one load per input, one multiply, one store. The mask discipline is identical to vector add.

Requirements

  • Use one Triton program per contiguous tile of the input
  • Multiply by the supplied mask and scale by 1/(1−p)1 / (1 - p)1/(1−p) in registers
  • Mask the tail so partial tiles never read or write out of bounds
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1,048,5761 \le N \le 1{,}048{,}5761≤N≤1,048,576.
  • x, mask, and out are torch.float32 on cuda. mask contains only 0.0 or 1.0 values.
  • p∈[0,0.99]p \in [0, 0.99]p∈[0,0.99].
  • Comparisons use atol = 1e-3.
Try Similar Problems
LayerNorm Forward in TritonMediumRMSNorm Forward in TritonMediumLayerNorm Backward in TritonHardDropout as a CUDA KernelEasyCross Entropy Loss (Mean Reduction) in TritonMediumRMS Normalization as a CUDA KernelMediumLayer Normalization as a CUDA KernelMediumVector Sum Reduction in TritonEasyVector Addition in TritonEasyKV Cache Append in TritonEasyFused Multiply-Add in TritonEasyVector Max Reduction in TritonEasy

Accepts: array

Accepts: array

Accepts: number

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Dropout (Inverted Scaling) in Triton

Dropout (Inverted Scaling) in Triton

GPU ProgrammingNeural Networks
Easy

Implement inference-time dropout in Triton with an externally provided mask. Given an input xxx, a precomputed 0/10/10/1 mask, and a drop probability ppp:

out[i]=x[i]⋅mask[i]⋅11−p\texttt{out}[i] = x[i] \cdot \texttt{mask}[i] \cdot \frac{1}{1 - p}out[i]=x[i]⋅mask[i]⋅1−p1​

This is a pure elementwise map: one tile per program, with a tail mask to handle lengths that are not multiples of the block. The dropout mask is supplied by the caller rather than generated inside the kernel, so this problem isolates the launch and masking pattern without pulling in an on-device random number generator.

Loading visualization...

Examples

Input: x = [1.0, 2.0, 3.0, 4.0], mask = [1, 0, 1, 0], p = 0.5

Output: [2.0, 0.0, 6.0, 0.0]

Input: x = [1.0, 2.0, 3.0], mask = [1, 1, 1], p = 0.0

Output: [1.0, 2.0, 3.0]

Hint 1

Load xxx and the dropout mask under the same tail mask. The dropout mask is a regular float tensor of zeros and ones; just multiply.

Hint 2

Compute the inverted-scaling factor 1/(1−p)1 / (1 - p)1/(1−p) once per program from the scalar ppp. Triton broadcasts the Python float to every lane automatically.

Hint 3

No reduction. The kernel is one load per input, one multiply, one store. The mask discipline is identical to vector add.

Requirements

  • Use one Triton program per contiguous tile of the input
  • Multiply by the supplied mask and scale by 1/(1−p)1 / (1 - p)1/(1−p) in registers
  • Mask the tail so partial tiles never read or write out of bounds
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1,048,5761 \le N \le 1{,}048{,}5761≤N≤1,048,576.
  • x, mask, and out are torch.float32 on cuda. mask contains only 0.0 or 1.0 values.
  • p∈[0,0.99]p \in [0, 0.99]p∈[0,0.99].
  • Comparisons use atol = 1e-3.
Try Similar Problems
LayerNorm Forward in TritonMediumRMSNorm Forward in TritonMediumLayerNorm Backward in TritonHardDropout as a CUDA KernelEasyCross Entropy Loss (Mean Reduction) in TritonMediumRMS Normalization as a CUDA KernelMediumLayer Normalization as a CUDA KernelMediumVector Sum Reduction in TritonEasyVector Addition in TritonEasyKV Cache Append in TritonEasyFused Multiply-Add in TritonEasyVector Max Reduction in TritonEasy

Accepts: array

Accepts: array

Accepts: number

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1