Skip to content
Merged
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
4 changes: 2 additions & 2 deletions vllm_ascend/spec_decode/eagle_proposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def dummy_run(self,
model_positions = self._get_positions(num_tokens)
model_previous_hidden_states = self.hidden_states[:num_tokens]

batch_size = num_tokens // (self.num_speculative_tokens + 1)
batch_size = num_tokens // (self.num_speculative_tokens + 1) if not is_profile else self.runner.max_num_reqs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The calculation of batch_size when is_profile is true can lead to an IndexError. batch_size is set to self.runner.max_num_reqs, but num_tokens (the input to dummy_run) can be smaller than self.runner.max_num_reqs. This can cause issues later in _run_merged_draft where tensors of size num_tokens are indexed with values related to batch_size.

To fix this, batch_size should first be derived from num_tokens and then capped by self.runner.max_num_reqs during profiling to ensure it doesn't exceed the number of available tokens.

        batch_size = num_tokens // (self.num_speculative_tokens + 1)
        if is_profile:
            batch_size = min(batch_size, self.runner.max_num_reqs)


with set_ascend_forward_context(
multi_steps_attn_metadata[0] if multi_steps_attn_metadata else None,
Expand Down Expand Up @@ -665,7 +665,7 @@ def _run_merged_draft(self,
hidden_states = hidden_states[last_token_indices]
last_token_indices = self.arange[:batch_size]

input_batch_size = num_input_tokens
input_batch_size = num_input_tokens if (self.method == "mtp" or self.use_cuda_graph) else batch_size

forward_context = get_forward_context()
forward_context.num_tokens = input_batch_size
Expand Down