Implement inference-time dropout in Triton with an externally provided mask. Given an input x, a precomputed 0/1 mask, and a drop probability p:
out[i]=x[i]⋅mask[i]⋅1−p1This 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.
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]
Load x and the dropout mask under the same tail mask. The dropout mask is a regular float tensor of zeros and ones; just multiply.
Compute the inverted-scaling factor 1/(1−p) once per program from the scalar p. Triton broadcasts the Python float to every lane automatically.
No reduction. The kernel is one load per input, one multiply, one store. The mask discipline is identical to vector add.
x, mask, and out are torch.float32 on cuda. mask contains only 0.0 or 1.0 values.atol = 1e-3.Accepts: array
Accepts: array
Accepts: number
Submit a correct solution to see your kernel performance.
Implement inference-time dropout in Triton with an externally provided mask. Given an input x, a precomputed 0/1 mask, and a drop probability p:
out[i]=x[i]⋅mask[i]⋅1−p1This 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.
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]
Load x and the dropout mask under the same tail mask. The dropout mask is a regular float tensor of zeros and ones; just multiply.
Compute the inverted-scaling factor 1/(1−p) once per program from the scalar p. Triton broadcasts the Python float to every lane automatically.
No reduction. The kernel is one load per input, one multiply, one store. The mask discipline is identical to vector add.
x, mask, and out are torch.float32 on cuda. mask contains only 0.0 or 1.0 values.atol = 1e-3.Accepts: array
Accepts: array
Accepts: number
Submit a correct solution to see your kernel performance.