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

Method __init__

inference/models/mpt.py:96–149  ·  view source on GitHub ↗
(self, args)

Source from the content-addressed store, hash-verified

94
95class MPTAttentionFused(nn.Module):
96 def __init__(self, args):
97 super().__init__()
98 self.args = args
99 self.n_local_heads = args.n_heads
100 self.head_dim = args.d_model // args.n_heads
101 args.max_seq_len = min(args.max_seq_len, global_max_seq_len)
102
103 self.Wqkv = nn.Linear(
104 args.d_model,
105 args.n_heads * self.head_dim * 3,
106 bias=False,
107 )
108
109 self.out_proj = nn.Linear(
110 args.n_heads * self.head_dim,
111 args.d_model,
112 bias=False,
113 )
114
115 # following fastertransformer definition
116
117 self.cache_v = (
118 torch.zeros(
119 (
120 max_batch_size,
121 self.n_local_heads,
122 args.max_seq_len,
123 self.head_dim,
124 )
125 )
126 .cuda()
127 .half()
128 ) # added to half
129 # 8: pack 8 fp16 in FT, if fp32 then use 4
130 self.cache_k = (
131 torch.zeros(
132 (
133 max_batch_size,
134 self.n_local_heads,
135 self.head_dim // 8,
136 args.max_seq_len,
137 8,
138 )
139 )
140 .cuda()
141 .half()
142 ) # added to half
143
144 alibi_slopes, alibi_bias = build_alibi_bias(
145 self.n_local_heads, args.max_seq_len
146 )
147 # TODO (Haotian): fix device
148 self.alibi_slopes = alibi_slopes.float().to("cuda:0")
149 self.alibi_bias = alibi_bias.to("cuda:0")
150
151 def forward(
152 self,

Callers

nothing calls this directly

Calls 2

build_alibi_biasFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected