Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-390

ALiBi Head Slopes

Problem

Compute the ALiBi head slopes: head h gets slope 1 / 2^(h + 1), so earlier heads penalize distance the most.

The signature is alibi_slopes(num_heads). Return the list of slopes as floats.

Hint

Each head halves the previous slope, starting from 0.5.

Test cases

case 1
in: [4]
expected: [0.5,0.25,0.125,0.0625]
case 2
in: [1]
expected: [0.5]
case 3
in: [8]
expected: [0.5,0.25,0.125,0.0625,0.03125,0.015625,0.0078125,0.00390625]
case 4
in: [3]
expected: [0.5,0.25,0.125]
Starter codePython
def alibi_slopes(num_heads):
    # Your code here
    pass

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