Skip to content

Commit cb072ce

Browse files
authored
[Bugfix] Update Florence-2 tokenizer to make grounding tasks work (#16734)
Signed-off-by: Isotr0py <2037008807@qq.com>
1 parent 95aca28 commit cb072ce

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

examples/offline_inference/encoder_decoder_multimodal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ModelRequestData(NamedTuple):
2222
def run_florence2():
2323
engine_args = EngineArgs(
2424
model="microsoft/Florence-2-large",
25-
tokenizer="facebook/bart-large",
25+
tokenizer="Isotr0py/Florence-2-tokenizer",
2626
max_num_seqs=8,
2727
trust_remote_code=True,
2828
limit_mm_per_prompt={"image": 1},
@@ -165,6 +165,7 @@ def main(args):
165165
temperature=0,
166166
top_p=1.0,
167167
max_tokens=64,
168+
skip_special_tokens=False,
168169
)
169170

170171
start = time.time()

examples/offline_inference/vision_language.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def run_florence2(questions: list[str], modality: str) -> ModelRequestData:
150150

151151
engine_args = EngineArgs(
152152
model="microsoft/Florence-2-large",
153-
tokenizer="facebook/bart-large",
153+
tokenizer="Isotr0py/Florence-2-tokenizer",
154154
max_model_len=4096,
155155
max_num_seqs=2,
156156
trust_remote_code=True,

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,15 @@ def generate_encoder_decoder_greedy_logprobs(
925925
max_tokens: int,
926926
num_logprobs: int,
927927
num_prompt_logprobs: Optional[int] = None,
928+
skip_special_tokens: bool = True,
928929
) -> Union[list[TokensTextLogprobs],
929930
list[TokensTextLogprobsPromptLogprobs]]:
930931
greedy_logprobs_params = SamplingParams(
931932
temperature=0.0,
932933
max_tokens=max_tokens,
933934
logprobs=num_logprobs,
934935
prompt_logprobs=(num_prompt_logprobs),
936+
skip_special_tokens=skip_special_tokens,
935937
)
936938
'''
937939
Greedy logprobs generation for vLLM encoder/decoder models

tests/models/encoder_decoder/vision_language/test_florence2.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from ...utils import check_logprobs_close
1414

1515
MODELS = ["microsoft/Florence-2-base"]
16-
# Florence-2 uses BartFastTokenizer which can't be loaded from AutoTokenizer
17-
# Therefore, we borrow the BartTokenizer from the original Bart model
18-
TOKENIZER = "facebook/bart-base"
16+
# Florence-2 model repo's tokenizer config is missing some special tokens.
17+
# Therefore, we use a converted tokenizer from a forked repo
18+
TOKENIZER = "Isotr0py/Florence-2-tokenizer"
1919
HF_IMAGE_PROMPTS = IMAGE_ASSETS.prompts({
2020
"stop_sign":
21-
"<CAPTION>", # special task token
21+
"<OD>", # special task token which will output special tokens
2222
"cherry_blossom":
2323
"Describe in detail what is shown in the image.",
2424
})
@@ -45,7 +45,6 @@ def hf_to_vllm_output(hf_output: tuple[list[int], str,
4545
output_ids, output_str, out_logprobs = hf_output
4646

4747
output_str = output_str.replace("</s>", "").replace("<s>", "")
48-
output_ids = [ids for ids in output_ids if ids not in [0, 2]]
4948

5049
return output_ids, output_str, out_logprobs
5150

@@ -71,8 +70,11 @@ def run_test(
7170
enforce_eager=True) as vllm_model:
7271
vllm_outputs_per_case = [
7372
vllm_model.generate_encoder_decoder_greedy_logprobs(
74-
prompts, max_tokens, num_logprobs=num_logprobs)
75-
for prompts in inputs
73+
prompts,
74+
max_tokens,
75+
num_logprobs=num_logprobs,
76+
skip_special_tokens=False,
77+
) for prompts in inputs
7678
]
7779

7880
hf_inputs = [get_hf_images_prompts(prompts) for prompts in inputs]
@@ -93,6 +95,7 @@ def run_test(
9395
outputs_1_lst=vllm_outputs,
9496
name_0="hf",
9597
name_1="vllm",
98+
num_outputs_0_skip_tokens=1,
9699
)
97100

98101

tests/models/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def check_available_online(
366366
# Florence-2 uses BartFastTokenizer which can't be loaded from AutoTokenizer
367367
# Therefore, we borrow the BartTokenizer from the original Bart model
368368
"Florence2ForConditionalGeneration": _HfExamplesInfo("microsoft/Florence-2-base", # noqa: E501
369-
tokenizer="facebook/bart-base",
369+
tokenizer="Isotr0py/Florence-2-tokenizer",
370370
trust_remote_code=True), # noqa: E501
371371
"MllamaForConditionalGeneration": _HfExamplesInfo("meta-llama/Llama-3.2-11B-Vision-Instruct"), # noqa: E501
372372
"WhisperForConditionalGeneration": _HfExamplesInfo("openai/whisper-large-v3"), # noqa: E501

0 commit comments

Comments
 (0)