after add cache, this version support flashinfer#1229
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for the HunyuanImage3 model, including its architecture, inference logic, and weight loading. It also adds configuration support for cache options and native implementations, along with updated scripts for running the model. The review feedback highlights potential runtime errors when accessing configuration attributes and suggests using safer getattr patterns, as well as replacing hardcoded absolute paths in shell scripts with dynamic path resolution to improve portability. One high-severity issue regarding the detection of runtime diff weights in the MoE implementation was also identified.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if hasattr(linear, "weight_diff"): | ||
| raise RuntimeError("HunyuanImage3 moe_impl='flashinfer' does not support runtime diff weights.") |
There was a problem hiding this comment.
The condition hasattr(linear, "weight_diff") always evaluates to True because weight_diff is initialized in __init__ as a dummy tensor. This prevents the use of flashinfer even when no runtime diff is active. Using getattr(linear, "has_diff", False) accurately detects active runtime diffs.
| if hasattr(linear, "weight_diff"): | |
| raise RuntimeError("HunyuanImage3 moe_impl='flashinfer' does not support runtime diff weights.") | |
| if getattr(linear, "has_diff", False): | |
| raise RuntimeError("HunyuanImage3 moe_impl='flashinfer' does not support runtime diff weights.") |
| if missing: | ||
| raise RuntimeError(f"HunyuanImage3 VAE weights are incomplete; missing {len(missing)} keys, first key: {missing[0]}") | ||
|
|
||
| vae_dtype = getattr(torch, self.hunyuan_config.vae_dtype, torch.float32) |
There was a problem hiding this comment.
Directly accessing self.hunyuan_config.vae_dtype can raise an AttributeError if the attribute is missing from the configuration. Using getattr with a default value provides a safe fallback.
| vae_dtype = getattr(torch, self.hunyuan_config.vae_dtype, torch.float32) | |
| vae_dtype_str = getattr(self.hunyuan_config, "vae_dtype", "float32") | |
| vae_dtype = getattr(torch, vae_dtype_str, torch.float32) |
| vae = self.vae_decoder | ||
| vae_device = self._vae_device() | ||
| image_tensor = image_tensor.unsqueeze(0).to(vae_device) | ||
| autocast_dtype = getattr(torch, self.hunyuan_config.vae_autocast_dtype, torch.float16) |
There was a problem hiding this comment.
Directly accessing self.hunyuan_config.vae_autocast_dtype can raise an AttributeError if the attribute is missing from the configuration. Using getattr with a default value provides a safe fallback.
vae_autocast_dtype_str = getattr(self.hunyuan_config, "vae_autocast_dtype", "float16")
autocast_dtype = getattr(torch, vae_autocast_dtype_str, torch.float16)| if hasattr(vae, "ffactor_temporal"): | ||
| latents = latents.unsqueeze(2) | ||
|
|
||
| autocast_dtype = getattr(torch, self.hunyuan_config.vae_autocast_dtype, torch.float16) |
There was a problem hiding this comment.
Directly accessing self.hunyuan_config.vae_autocast_dtype can raise an AttributeError if the attribute is missing from the configuration. Using getattr with a default value provides a safe fallback.
vae_autocast_dtype_str = getattr(self.hunyuan_config, "vae_autocast_dtype", "float16")
autocast_dtype = getattr(torch, vae_autocast_dtype_str, torch.float16)| export lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | ||
| export model_path="/data/nvme0/lhd_codes/HunyuanImage-3.0-instruct/HunyuanImage-3-Instruct" |
There was a problem hiding this comment.
The script uses hardcoded absolute paths specific to a local environment. Replacing them with dynamic path resolution or placeholder paths makes the script portable across different environments.
| export lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | |
| export model_path="/data/nvme0/lhd_codes/HunyuanImage-3.0-instruct/HunyuanImage-3-Instruct" | |
| export lightx2v_path=${lightx2v_path:-$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)} | |
| export model_path=${model_path:-/path/to/HunyuanImage-3-Instruct} |
| export lightx2v_path="${lightx2v_path:-/data/nvme0/lhd_codes/LightX2V}" | ||
| export model_path="${model_path:-/data/nvme0/lhd_codes/HunyuanImage-3.0-instruct/HunyuanImage-3-Instruct}" |
There was a problem hiding this comment.
The script uses hardcoded absolute paths specific to a local environment. Replacing them with dynamic path resolution or placeholder paths makes the script portable across different environments.
| export lightx2v_path="${lightx2v_path:-/data/nvme0/lhd_codes/LightX2V}" | |
| export model_path="${model_path:-/data/nvme0/lhd_codes/HunyuanImage-3.0-instruct/HunyuanImage-3-Instruct}" | |
| export lightx2v_path=${lightx2v_path:-$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)} | |
| export model_path=${model_path:-/path/to/HunyuanImage-3-Instruct} |
| lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | ||
| model_path="/data/nvme0/models/Wan-AI/Wan2.1-I2V-14B-720P" |
There was a problem hiding this comment.
The script uses hardcoded absolute paths specific to a local environment. Replacing them with dynamic path resolution or placeholder paths makes the script portable across different environments.
| lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | |
| model_path="/data/nvme0/models/Wan-AI/Wan2.1-I2V-14B-720P" | |
| lightx2v_path=${lightx2v_path:-$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)} | |
| model_path=${model_path:-/path/to/Wan2.1-I2V-14B-720P} |
| lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | ||
| model_path="/data/nvme0/models/Wan-AI/Wan2.1-T2V-1.3B" |
There was a problem hiding this comment.
The script uses hardcoded absolute paths specific to a local environment. Replacing them with dynamic path resolution or placeholder paths makes the script portable across different environments.
| lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | |
| model_path="/data/nvme0/models/Wan-AI/Wan2.1-T2V-1.3B" | |
| lightx2v_path=${lightx2v_path:-$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)} | |
| model_path=${model_path:-/path/to/Wan2.1-T2V-1.3B} |
No description provided.