Skip to content

Commit

Permalink
Rename _find_placeholders
Browse files Browse the repository at this point in the history
Signed-off-by: DarkLight1337 <[email protected]>
  • Loading branch information
DarkLight1337 committed Jan 3, 2025
1 parent 95339d6 commit b5020c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
7 changes: 5 additions & 2 deletions vllm/model_executor/models/llava.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,11 @@ def get_replacement_mantis(item_idx: int):
)
orig_repls = self._bind_prompt_replacements(unbound_orig_repls)

mm_placeholders = self._find_placeholders(orig_repls, prompt_ids,
mm_item_counts)
mm_placeholders = self._find_placeholders_by_modality(
orig_repls,
prompt_ids,
mm_item_counts,
)

self._validate_placeholders(mm_placeholders, mm_item_counts)

Expand Down
8 changes: 4 additions & 4 deletions vllm/model_executor/models/qwen2_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def get_replacement_qwen2_audio(item_idx: int):

def _always_apply_prompt_replacements(self) -> bool:
# HF never applies prompt replacements, so we have to do it ourselves.
# NOTE: `_find_placeholders` may incorrectly think that HF has already
# performed processing for multi-audio input when the input audios are
# short (the corresponding placeholders may take up fewer tokens than
# the number of audio items)
# NOTE: `_find_placeholders_by_modality` may incorrectly think that HF
# has already performed processing for multi-audio input when the input
# audios are short (the corresponding placeholders may take up fewer
# tokens than the number of audio items)
return True

def _get_dummy_mm_inputs(
Expand Down
27 changes: 17 additions & 10 deletions vllm/multimodal/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def _get_prompt_replacements(
"""
raise NotImplementedError

def _find_placeholders(
def _find_placeholders_by_modality(
self,
all_prompt_repls: Sequence[_BoundPromptReplacement],
new_token_ids: list[int],
Expand Down Expand Up @@ -930,10 +930,11 @@ def _always_apply_prompt_replacements(self) -> bool:
"""
A flag which can be overridden so that
:meth:`_apply_prompt_replacements` is always called even if we
detect that HF has performed processing via :meth:`_find_placeholders`.
detect that HF has performed processing via
:meth:`_find_placeholders_by_modality`.
This is useful in cases where :meth:`_find_placeholders` cannot be
reliably used to detect whether HF has performed processing or not.
This is useful in cases where :meth:`_find_placeholders_by_modality`
cannot be reliably used to detect whether HF has performed processing.
"""
return False

Expand Down Expand Up @@ -986,8 +987,11 @@ def _apply_prompt_replacements(
token_ids = _encode(tokenizer, text)
matched_repls = [match.prompt_repl for match in text_matches]

placeholders = self._find_placeholders(matched_repls, token_ids,
mm_item_counts)
placeholders = self._find_placeholders_by_modality(
matched_repls,
token_ids,
mm_item_counts,
)

return token_ids, text, placeholders

Expand Down Expand Up @@ -1043,12 +1047,15 @@ def apply(
)
prompt_repls = self._bind_prompt_replacements(unbound_prompt_repls)

# If HF processor already inserts placeholder tokens,
# there is no need for us to insert them
mm_item_counts = mm_items.get_all_counts()
mm_placeholders = self._find_placeholders(prompt_repls, prompt_ids,
mm_item_counts)
mm_placeholders = self._find_placeholders_by_modality(
prompt_repls,
prompt_ids,
mm_item_counts,
)

# If HF processor already inserts placeholder tokens,
# there is no need for us to insert them
try:
self._validate_placeholders(mm_placeholders, mm_item_counts)
except ValueError:
Expand Down

0 comments on commit b5020c2

Please sign in to comment.