Transformers serve VLM - #39454
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
zucchini-nlp
left a comment
There was a problem hiding this comment.
Great, looking forward to get it shipped! Left a few questions below, to make sure it will work for all VLMs. I will also try to set up an env for playing around
| eos_token_id=self.processor.eos_token_id, | ||
| pad_token_id=self.processor.pad_token_id, |
There was a problem hiding this comment.
not all processor's have direct access to special tokens. For a general approach we'd do processor.tokenizer.bos_token_ids
Or maybe we could add direct access through ProcessorMixin, lemme see, Makes sense
| file = tempfile.NamedTemporaryFile(suffix=".png", delete=False) | ||
| image.save(file.name) | ||
|
|
||
| parsed_message["content"].append({"type": "image", "url": file.name}) |
There was a problem hiding this comment.
nit: i think we don't need to save temporarily the image, templates can load from any source
There was a problem hiding this comment.
Alright, I'll take a look to see how to handle base64 directly, thx!
| text = self.tokenizer.apply_chat_template(req["input"], add_generation_prompt=True, tokenize=False) | ||
| inputs = self.tokenizer(text, return_tensors="pt").to(self.model.device)["input_ids"] | ||
| text = self.processor.apply_chat_template(req["input"], add_generation_prompt=True, tokenize=False) | ||
| inputs = self.processor(text, return_tensors="pt").to(self.model.device)["input_ids"] |
There was a problem hiding this comment.
Has to be keyword argument, because positionally images are always the first arg. In general after Pablo's refactor we've been recommending to use only keyword args in processor. And just a few days ago I removed all BC workarounds we had
processor(text=text, return_tensors="pt")
There was a problem hiding this comment.
Thanks Raushan! Actually this can be simplified to do the tokenization within the chat template application directly:
- text = processor.apply_chat_template(req["input"], add_generation_prompt=True, tokenize=False)
- inputs = processor(text, return_tensors="pt").to(model.device)["input_ids"]
+ inputs = processor.apply_chat_template(req["input"], add_generation_prompt=True).to(model.device)Given that the req["input"] contains both text and images, what do you recommend regarding explicit kwargs?
There was a problem hiding this comment.
Yeah, in that case it's perfect. Image-only templates are already settled, tested and won't change in the future. We can pass any keyword kwargs and those will be passed:
- To Jinja template in case the template has if/else controlled by users flags, e.g.
add_vision_id=Truein Qwen - To the processor, after filtering unused kwargs. No warning raised here
| elements_are_dicts = any(isinstance(content, str) for content in message["content"]) | ||
|
|
||
| if isinstance(message["content"], str): | ||
| if elements_are_dicts: | ||
| # If other elements are dictionaries, then plain strings should be as well | ||
| parsed_message["content"].append({"type": "text", "text": message["content"]}) | ||
| else: | ||
| # If no other elements are dicts, then the string is the entire content. | ||
| parsed_message["content"] = message["content"] |
There was a problem hiding this comment.
these part is a bit confusing, is the content is single string, how we can have elements_are_dicts within the content? Prob I am missing smth with OpenAI format
There was a problem hiding this comment.
Simplified it! Thanks
5f3d658 to
ebc0c4a
Compare
ebc0c4a to
e81c243
Compare
e81c243 to
a34e597
Compare
|
Looking great! qq from our side (without having done much research): how difficult would it be to simply spawn up the chat completion endpoint/function directly from our backend? It would be great to have |
gante
left a comment
There was a problem hiding this comment.
Other than the model loading abstractions, which are out of sync with the (merged) stt serving PR, LGTM 馃檶
| "Qwen/Qwen2.5-VL-7B-Instruct", | ||
| ] | ||
|
|
||
| if HF_HUB_OFFLINE: |
|
@tjbck from my experience, with the exception of changing the OpenAI address manually, integration with If we can ask for features on your side, it would be nice to be able to specify arbitrary models from the model selection dropdown (as opposed to being limited to the list from Let us know if we can help from our side 馃 |
|
Thanks for dropping by @tjbck! As Joao said above, it should be pretty seamless. You might want to specify some specific extras when installing As Joao highlights there is a question around which LLMs/VLMs are shown as Let us know in case you run into any issues, we'd be happy to add in features that would make your life simpler. |
Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com>
Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
* Add support for VLMs in Transformers Serve * Raushan comments * Update src/transformers/commands/serving.py Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> * Quick fix * CPU -> Auto * Update src/transformers/commands/serving.py Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com> * Fixup --------- Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
Add VLM support for
transformers serve.In case you're interested in playing around with it, Open WebUI is a good tool to work with.
Launching
transformers servewith VLM support:To install Open WebUI:
To set it up to work with the transformers serve backend:
You should now find a limited (but growing) list of available models:
Enjoy chatting with the model!