-
Notifications
You must be signed in to change notification settings - Fork 473
[Model] Add Hunyuan Image3 AR Support #759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
usberkeley
wants to merge
18
commits into
vllm-project:main
Choose a base branch
from
usberkeley:hunyuan-image3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,190
−0
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b77e9b0
[model] Add Hunyuan-Image3 AR support (text + image)
usberkeley 1978591
[model] format code
usberkeley fcc168f
[model] format code
usberkeley aaddcfc
[model] format code
usberkeley ab52e7f
[model] add base size & ratio token and example
usberkeley ceda66c
[model] change autoencoder to ReplicatedLinear
usberkeley 1dc744c
[model] format code
usberkeley d7c671f
[model] format code
usberkeley 470fbfb
[model] format code
usberkeley 0627a2c
[model] fix bug
usberkeley 571eaa6
[model] trim padding token
usberkeley ed2eaf5
add mrope and change vit padding token numbers
princepride a4c0725
Remove load_sharded_safetensors function
princepride cddb02d
Remove unused imports in autoencoder_kl_3d.py
princepride fe66e75
fix HunyuanModel#load_weights, remove Upsample and optimize log
usberkeley bcb6cf5
format code
usberkeley 202a53a
add image rgba to rgb and doc for model, optimize example
usberkeley c950a19
format code
usberkeley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions
81
examples/offline_inference/hunyuan_image3/image_to_text.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| from PIL import Image | ||
|
|
||
| from vllm_omni.entrypoints.omni import Omni | ||
|
|
||
| """ | ||
| The tencent/HunyuanImage-3.0-Instruct base model is built on the Hunyuan v1 architecture, specifically the tencent/Hunyuan-A13B-Instruct model. It utilizes two tokenizer delimiter templates: | ||
|
|
||
| 1) Pretrained template (default for gen_text mode), which concatenates system, image | ||
| tokens, and user question WITHOUT role delimiters: | ||
| "<|startoftext|>{system_prompt}{image_tokens}{user_question}" | ||
|
|
||
hsliuustc0106 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Example (before image token expansion): | ||
| "<|startoftext|>You are an assistant that understands images and outputs text.<img>Describe the content of the picture." | ||
|
|
||
| 2) Instruct template, which uses explicit role prefixes and separators. | ||
| """ | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser(description="Generate text from image using HunyuanImage-3.0-Instruct.") | ||
| parser.add_argument( | ||
| "--model", | ||
| default="tencent/HunyuanImage-3.0-Instruct", | ||
| help="Model name or local path.", | ||
| ) | ||
| parser.add_argument( | ||
| "--image", | ||
| type=str, | ||
| default="./image.png", | ||
| help="Path to input image file (PNG, JPG, etc.).", | ||
| ) | ||
| parser.add_argument( | ||
| "--prompt", | ||
| type=str, | ||
| default="<|startoftext|>You are an assistant that understands images and outputs text.<img>Identify the animal in this image and describe this animal's characteristics in the image.", | ||
| help="Pretrain template prompt: <|startoftext|>{system}<img>{question}", | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def load_image(image_path: str) -> Image.Image: | ||
| """Load an image from file path.""" | ||
| if not os.path.exists(image_path): | ||
| raise FileNotFoundError(f"Image file not found: {image_path}") | ||
| return Image.open(image_path).convert("RGB") | ||
|
|
||
|
|
||
| def main(args: argparse.Namespace) -> None: | ||
| omni = Omni(model=args.model) | ||
|
|
||
| prompt_dict = { | ||
| "prompt": args.prompt, | ||
| "modalities": ["text"], | ||
| } | ||
|
|
||
| # Add image input if provided | ||
| if args.image: | ||
| if not os.path.exists(args.image): | ||
| raise FileNotFoundError(f"Input image not found: {args.image}") | ||
|
|
||
| input_image = load_image(args.image) | ||
| prompt_dict["multi_modal_data"] = {"image": input_image} | ||
|
|
||
| prompts = [prompt_dict] | ||
| omni_outputs = omni.generate(prompts=prompts) | ||
usberkeley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| prompt_text = omni_outputs[0].request_output[0].prompt | ||
| generated_text = omni_outputs[0].request_output[0].outputs[0].text | ||
| print(f"Prompt: {prompt_text}") | ||
| print(f"Text: {generated_text}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| args = parse_args() | ||
| main(args) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| from .hunyuan_image3 import HunyuanImage3ForConditionalGeneration | ||
|
|
||
| __all__ = ["HunyuanImage3ForConditionalGeneration"] | ||
hsliuustc0106 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove it, we don't need.