Skip to content

Commit

Permalink
[Hardware] [HPU]add mark_step for hpu (#10239)
Browse files Browse the repository at this point in the history
Signed-off-by: Kunshang Ji <[email protected]>
  • Loading branch information
jikunshang authored Nov 17, 2024
1 parent 8d74b5a commit 76aab90
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vllm/worker/hpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ def precompute_indices_and_offsets(block_size, slot_mapping, is_prompt):
return indices, offsets


def modify_decoder_layer(module: torch.nn.Module, suffix="DecoderLayer"):
if module.__class__.__name__.endswith(suffix):

def forward_hook(module, args, output):
htorch.core.mark_step()
return output

module.register_forward_hook(forward_hook)

for child_name, child_module in module.named_children():
modify_decoder_layer(child_module)


class HpuModelAdapter:

def __init__(self, model, block_size, dtype, enforce_eager):
Expand Down Expand Up @@ -636,6 +649,7 @@ def load_model(self) -> None:
else:
self.model = self.model.to("hpu")
htcore.mark_step()
modify_decoder_layer(self.model)
torch.hpu.synchronize()

with HabanaMemoryProfiler() as m_wrap:
Expand Down

0 comments on commit 76aab90

Please sign in to comment.