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

Method forward

inference/models/llama.py:285–300  ·  view source on GitHub ↗
(self, tokens: torch.Tensor, start_pos: int)

Source from the content-addressed store, hash-verified

283
284 @torch.inference_mode()
285 def forward(self, tokens: torch.Tensor, start_pos: int):
286 _bsz, seqlen = tokens.shape
287 h = self.embed_tokens(tokens)
288 self.freqs_cis = self.freqs_cis.to(h.device)
289 freqs_cis = self.freqs_cis[start_pos : start_pos + seqlen]
290
291 mask = None
292 if seqlen > 1:
293 mask = torch.full(
294 (1, 1, seqlen, seqlen), float("-inf"), device=tokens.device
295 )
296 mask = torch.triu(mask, diagonal=start_pos + 1).type_as(h)
297 for layer in self.layers:
298 h = layer(h, start_pos, freqs_cis, mask)
299 h = self.norm(h)
300 return h
301
302
303class LlamaForCausalLM(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected