Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix][Habana_main][Multistep]Fix multistep deepcopy overhead #452

Open
wants to merge 2 commits into
base: habana_main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions vllm/worker/hpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ def execute_model(
# we only want to pythonize in the last step
sampling_metadata.skip_sampler_cpu_output = True
self.model.model.sampler.include_gpu_probs_tensor = True
cache_orig_output_token_ids: List[Dict] = []
for i in range(num_steps):
with self.profiler.record_event('internal', model_event_name):
hidden_states = self.model.forward(
Expand Down Expand Up @@ -2159,8 +2160,13 @@ def execute_model(
ctx = model_input.async_callback.keywords[ # type: ignore
"ctx"]
seq_group_metadata_list = ctx.seq_group_metadata_list
seq_group_metadata_list = copy.deepcopy(
seq_group_metadata_list)
# Cache the original output token ids
for i, seq_group_metadata in enumerate(
seq_group_metadata_list):
cache_orig_output_token_ids.append({})
for j, data in seq_group_metadata.seq_data.items():
cache_orig_output_token_ids[i][j] = \
copy.deepcopy(data.output_token_ids)
for seq_group_metadata in seq_group_metadata_list:
for data in seq_group_metadata.seq_data.values():
max_output_len = sampling_metadata.seq_groups[
Expand All @@ -2185,6 +2191,14 @@ def execute_model(
"attn_metadata":
self.trim_attn_metadata(result.attn_metadata)
})
else:
if len(cache_orig_output_token_ids) > 0:
# Reuse the original output token ids
for i, seq_group_metadata in enumerate(
seq_group_metadata_list):
for j, data in seq_group_metadata.seq_data.items():
data.output_token_ids = \
cache_orig_output_token_ids[i][j]

if self.is_driver_worker and self.profiler.enabled:
# Stop recording 'execute_model' event
Expand Down