def forward(self, in_idx, use_cache=False): # ... if use_cache: pos_ids = torch.arange( self.current_pos, self.current_pos + seq_len, device=in_idx.device, dtype=torch.long ) self.current_pos += seq_len else: pos_ids = torch.arange( 0, seq_len, device=in_idx.device, dtype=torch.long ) pos_embeds = self.pos_emb(pos_ids).unsqueeze(0) x = tok_embeds + pos_embeds # ... for blk in self.trf_blocks: x = blk(x, use_cache=use_cache)