Skip to content

Commit

Permalink
empty cache only for 1st token but rest token to speed up (#11665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxito-Ada authored Jul 26, 2024
1 parent fc7f8fe commit ba01b85
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/llm/src/ipex_llm/transformers/pipeline_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,9 +959,13 @@ def llama_causallm_forward_4_37_lowmem(
logits = [F.linear(hidden_states, lm_head_slices[i]) for i in range(self.config.pretraining_tp)] # noqa
logits = torch.cat(logits, dim=-1)
else:
torch.xpu.empty_cache()
# Only empty cache for first token
if hidden_states.shape[1] > 1:
torch.xpu.empty_cache()
logits = self.lm_head(hidden_states)
torch.xpu.empty_cache()
# Only empty cache for first token
if hidden_states.shape[1] > 1:
torch.xpu.empty_cache()
# logits = logits.float()

# ipex-llm change ends
Expand Down

0 comments on commit ba01b85

Please sign in to comment.