Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-118

Drop-Path Mask (Seeded)

Problem

Stochastic depth (drop-path) for a batch of token rows. Call random.seed(seed), draw one random number per row, drop the entire row with probability p, and scale surviving rows by 1 / (1 - p).

The signature is drop_path(x, p, seed). Iterate rows in order so the mask is reproducible.

Hint

Drop-path drops whole residual branches, unlike dropout which drops individual activations.

Test cases

case 1
in: [[[1,2],[3,4],[5,6]],0.5,0]
expected: [[2,4],[6,8],[0,0]]
case 2
in: [[[1,2]],0,5]
expected: [[1,2]]
case 3
in: [[[1,1],[2,2]],0.25,42]
expected: [[1.3333333333,1.3333333333],[0,0]]
case 4
in: [[[1,2,3],[4,5,6]],0.8,7]
expected: [[0,0,0],[0,0,0]]
Starter codePython
import random
def drop_path(x, p, seed):
    # Your code here
    pass

4 test cases · run your code against them in the editor