MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / build_alibi_bias

Function build_alibi_bias

inference/models/mpt.py:32–44  ·  view source on GitHub ↗
(
    n_heads, seq_len, full=False, alibi_bias_max=8, dtype=torch.float32
)

Source from the content-addressed store, hash-verified

30
31
32def build_alibi_bias(
33 n_heads, seq_len, full=False, alibi_bias_max=8, dtype=torch.float32
34):
35 alibi_bias = torch.arange(1 - seq_len, 1, dtype=torch.int32).view(1, 1, 1, seq_len)
36 if full:
37 alibi_bias = alibi_bias - torch.arange(1 - seq_len, 1, dtype=torch.int32).view(
38 1, 1, seq_len, 1
39 )
40 alibi_bias = alibi_bias.abs().mul(-1)
41 slopes = gen_slopes(n_heads, alibi_bias_max)
42 alibi_bias = alibi_bias * slopes
43 slopes = slopes.squeeze(0).squeeze(-1).squeeze(-1)
44 return slopes.to(dtype=dtype), alibi_bias.to(dtype=dtype)
45
46
47def _cast_if_autocast_enabled(tensor):

Callers 1

__init__Method · 0.85

Calls 1

gen_slopesFunction · 0.85

Tested by

no test coverage detected