[VLM] Florence-2 supports online serving (#16164)
Signed-off-by: Isotr0py <2037008807@qq.com>
This commit is contained in:
parent
95d63f38c0
commit
7c80368710
7
examples/template_florence2.jinja
Normal file
7
examples/template_florence2.jinja
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{%- for message in messages -%}
|
||||||
|
{%- if message['role'] == 'user' -%}
|
||||||
|
{{- message['content'] -}}
|
||||||
|
{%- elif message['role'] == 'assistant' -%}
|
||||||
|
{{- message['content'] -}}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
@ -487,8 +487,8 @@ class BaseMultiModalItemTracker(ABC, Generic[_T]):
|
|||||||
return "<|endoftext10|>" # 200010 (see vocab.json in hf model)
|
return "<|endoftext10|>" # 200010 (see vocab.json in hf model)
|
||||||
if model_type in ("minicpmo", "minicpmv"):
|
if model_type in ("minicpmo", "minicpmv"):
|
||||||
return "(<image>./</image>)"
|
return "(<image>./</image>)"
|
||||||
if model_type in ("blip-2", "fuyu", "paligemma", "pixtral",
|
if model_type in ("blip-2", "florence2", "fuyu", "paligemma",
|
||||||
"mistral3"):
|
"pixtral", "mistral3"):
|
||||||
# These models do not use image tokens in the prompt
|
# These models do not use image tokens in the prompt
|
||||||
return None
|
return None
|
||||||
if model_type == "qwen":
|
if model_type == "qwen":
|
||||||
|
@ -10,7 +10,7 @@ import torch
|
|||||||
import torch.nn as nn
|
import torch.nn as nn
|
||||||
import torch.nn.functional as F
|
import torch.nn.functional as F
|
||||||
from einops import rearrange
|
from einops import rearrange
|
||||||
from transformers import BatchFeature, PretrainedConfig
|
from transformers import BartTokenizer, BatchFeature, PretrainedConfig
|
||||||
|
|
||||||
from vllm.config import VllmConfig
|
from vllm.config import VllmConfig
|
||||||
from vllm.model_executor.layers.logits_processor import LogitsProcessor
|
from vllm.model_executor.layers.logits_processor import LogitsProcessor
|
||||||
@ -826,6 +826,18 @@ class Florence2MultiModalProcessor(
|
|||||||
) -> Union[str, list[int]]:
|
) -> Union[str, list[int]]:
|
||||||
return [self.info.get_hf_config().eos_token_id]
|
return [self.info.get_hf_config().eos_token_id]
|
||||||
|
|
||||||
|
def _apply_hf_processor_tokens_only(
|
||||||
|
self,
|
||||||
|
prompt_tokens: list[int],
|
||||||
|
) -> list[int]:
|
||||||
|
hf_processor = self.info.get_hf_processor()
|
||||||
|
tokenizer: BartTokenizer = hf_processor.tokenizer
|
||||||
|
prompt_text = tokenizer.decode(prompt_tokens)
|
||||||
|
# convert task tokens to prompt
|
||||||
|
prompt_text = hf_processor._construct_prompts([prompt_text])[0]
|
||||||
|
prompt_tokens = tokenizer.encode(prompt_text, add_special_tokens=False)
|
||||||
|
return prompt_tokens
|
||||||
|
|
||||||
def _call_hf_processor(
|
def _call_hf_processor(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
prompt: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user