@@ -719,7 +719,7 @@ def _get_prompt_replacements(
719
719
"""
720
720
raise NotImplementedError
721
721
722
- def _find_placeholders (
722
+ def _find_placeholders_by_modality (
723
723
self ,
724
724
all_prompt_repls : Sequence [_BoundPromptReplacement ],
725
725
new_token_ids : list [int ],
@@ -930,10 +930,11 @@ def _always_apply_prompt_replacements(self) -> bool:
930
930
"""
931
931
A flag which can be overridden so that
932
932
:meth:`_apply_prompt_replacements` is always called even if we
933
- detect that HF has performed processing via :meth:`_find_placeholders`.
933
+ detect that HF has performed processing via
934
+ :meth:`_find_placeholders_by_modality`.
934
935
935
- This is useful in cases where :meth:`_find_placeholders` cannot be
936
- reliably used to detect whether HF has performed processing or not .
936
+ This is useful in cases where :meth:`_find_placeholders_by_modality`
937
+ cannot be reliably used to detect whether HF has performed processing.
937
938
"""
938
939
return False
939
940
@@ -986,8 +987,11 @@ def _apply_prompt_replacements(
986
987
token_ids = _encode (tokenizer , text )
987
988
matched_repls = [match .prompt_repl for match in text_matches ]
988
989
989
- placeholders = self ._find_placeholders (matched_repls , token_ids ,
990
- mm_item_counts )
990
+ placeholders = self ._find_placeholders_by_modality (
991
+ matched_repls ,
992
+ token_ids ,
993
+ mm_item_counts ,
994
+ )
991
995
992
996
return token_ids , text , placeholders
993
997
@@ -1043,12 +1047,15 @@ def apply(
1043
1047
)
1044
1048
prompt_repls = self ._bind_prompt_replacements (unbound_prompt_repls )
1045
1049
1046
- # If HF processor already inserts placeholder tokens,
1047
- # there is no need for us to insert them
1048
1050
mm_item_counts = mm_items .get_all_counts ()
1049
- mm_placeholders = self ._find_placeholders (prompt_repls , prompt_ids ,
1050
- mm_item_counts )
1051
+ mm_placeholders = self ._find_placeholders_by_modality (
1052
+ prompt_repls ,
1053
+ prompt_ids ,
1054
+ mm_item_counts ,
1055
+ )
1051
1056
1057
+ # If HF processor already inserts placeholder tokens,
1058
+ # there is no need for us to insert them
1052
1059
try :
1053
1060
self ._validate_placeholders (mm_placeholders , mm_item_counts )
1054
1061
except ValueError :
0 commit comments