Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-303

2:4 Sparsity Metadata

Problem

For each group of four consecutive mask entries, list the global indices of the two kept ones. Input masks are assumed to have exactly two ones per group and a length divisible by four.

The signature is sparsity_24_metadata(mask). Return the list of index pairs.

Hint

2:4 sparsity stores two 2-bit indices per group, halving weight storage.

Test cases

case 1
in: [[1,0,1,0,0,1,0,1]]
expected: [[0,2],[5,7]]
case 2
in: [[1,1,0,0]]
expected: [[0,1]]
case 3
in: [[0,0,1,1,1,1,0,0]]
expected: [[2,3],[4,5]]
case 4
in: [[0,1,1,0,1,0,0,1]]
expected: [[1,2],[4,7]]
Starter codePython
def sparsity_24_metadata(mask):
    # Your code here
    pass

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