combine hunyuan#1227
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the native Hunyuan Image3 implementation, including model components, runner, scheduler, configuration files, shell scripts, and integration tests. The code review feedback highlights several key improvements: safely accessing self.has_diff to avoid potential AttributeError crashes, ensuring global_seed is not None before seeding to prevent TypeError, adding a fallback to retrieve dimensions from tensor shapes in the runner, replacing configuration assert statements with explicit ValueError exceptions, robustly handling scalar values for vae_downsample_factor, and replacing hardcoded absolute paths in the shell scripts with portable relative paths.
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 not hasattr(self, "weight_diff") or not self.has_diff: | ||
| return self.weight |
There was a problem hiding this comment.
The self.has_diff attribute is not initialized in __init__. If _get_actual_weight is called before register_diff (or if register_diff is called but self.weight_diff_name is not in weight_dict), this will raise an AttributeError. Using getattr(self, "has_diff", False) is safer and avoids this potential runtime crash.
| if not hasattr(self, "weight_diff") or not self.has_diff: | |
| return self.weight | |
| if not hasattr(self, "weight_diff") or not getattr(self, "has_diff", False): | |
| return self.weight |
| random.seed(global_seed) | ||
| np.random.seed(global_seed) | ||
| torch.manual_seed(global_seed) | ||
| if torch.cuda.is_available(): | ||
| torch.cuda.manual_seed_all(global_seed) |
There was a problem hiding this comment.
If global_seed is None, calling torch.manual_seed(None) will raise a TypeError: manual_seed(): Argument 'seed' must be int, not NoneType. Seeding should only be performed when global_seed is not None.
| random.seed(global_seed) | |
| np.random.seed(global_seed) | |
| torch.manual_seed(global_seed) | |
| if torch.cuda.is_available(): | |
| torch.cuda.manual_seed_all(global_seed) | |
| if global_seed is not None: | |
| random.seed(global_seed) | |
| np.random.seed(global_seed) | |
| torch.manual_seed(global_seed) | |
| if torch.cuda.is_available(): | |
| torch.cuda.manual_seed_all(global_seed) |
| if hasattr(vae_image, "i"): | ||
| return int(vae_image.i.image_height), int(vae_image.i.image_width) | ||
| return int(self.config.get("target_height", 1024)), int(self.config.get("target_width", 1024)) |
There was a problem hiding this comment.
If vae_image is a PyTorch tensor, it will not have the attribute i, causing the method to always fall back to the default target_height and target_width (1024x1024). This ignores the actual aspect ratio and dimensions of the input image. Adding a fallback to check hasattr(vae_image, "shape") allows retrieving the correct dimensions from the tensor shape.
| if hasattr(vae_image, "i"): | |
| return int(vae_image.i.image_height), int(vae_image.i.image_width) | |
| return int(self.config.get("target_height", 1024)), int(self.config.get("target_width", 1024)) | |
| if hasattr(vae_image, "i"): | |
| return int(vae_image.i.image_height), int(vae_image.i.image_width) | |
| if hasattr(vae_image, "shape") and len(vae_image.shape) >= 2: | |
| return int(vae_image.shape[-2]), int(vae_image.shape[-1]) | |
| return int(self.config.get("target_height", 1024)), int(self.config.get("target_width", 1024)) |
| if self.mm_type != "Default": | ||
| assert config.get("dit_quantized") is True |
There was a problem hiding this comment.
Using assert statements for configuration validation is discouraged because assertions can be disabled in production when Python is run with optimization flags (e.g., -O). It is safer to explicitly raise a ValueError.
| if self.mm_type != "Default": | |
| assert config.get("dit_quantized") is True | |
| if self.mm_type != "Default" and not config.get("dit_quantized"): | |
| raise ValueError("dit_quantized must be True when dit_quant_scheme is not 'Default'") |
| if "vae_scale_factor" not in config: | ||
| vae_downsample_factor = config.get("vae_downsample_factor") | ||
| if isinstance(vae_downsample_factor, list) and vae_downsample_factor: | ||
| config["vae_scale_factor"] = int(vae_downsample_factor[0]) |
There was a problem hiding this comment.
If vae_downsample_factor is a scalar integer (e.g., 8) rather than a list, vae_scale_factor is not set. This can cause missing configuration errors in other parts of the codebase. Adding a fallback to handle scalar integers/floats ensures robustness.
| if "vae_scale_factor" not in config: | |
| vae_downsample_factor = config.get("vae_downsample_factor") | |
| if isinstance(vae_downsample_factor, list) and vae_downsample_factor: | |
| config["vae_scale_factor"] = int(vae_downsample_factor[0]) | |
| if "vae_scale_factor" not in config: | |
| vae_downsample_factor = config.get("vae_downsample_factor") | |
| if isinstance(vae_downsample_factor, list) and vae_downsample_factor: | |
| config["vae_scale_factor"] = int(vae_downsample_factor[0]) | |
| elif isinstance(vae_downsample_factor, (int, float)): | |
| config["vae_scale_factor"] = int(vae_downsample_factor) |
| 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.
Hardcoding absolute paths on a specific machine makes the script non-portable and prone to failure for other users or environments. It is better to use relative path resolution or generic placeholders with environment variable fallbacks, similar to the pattern used in run_hunyuan_image3_i2i.sh.
| 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.
Hardcoding absolute paths on a specific machine makes the script non-portable and prone to failure for other users or environments. It is better to use relative path resolution or generic placeholders with environment variable fallbacks, similar to the pattern used in run_hunyuan_image3_i2i.sh.
| 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} |
| export lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | ||
| export model_path="/data/nvme0/lhd_codes/HunyuanImage-3.0-instruct/HunyuanImage-3-Instruct" | ||
| export HUNYUAN_IMAGE3_REPO_PATH="${HUNYUAN_IMAGE3_REPO_PATH:-/data/nvme0/lhd_codes/HunyuanImage-3.0}" |
There was a problem hiding this comment.
Hardcoding absolute paths on a specific machine makes the script non-portable and prone to failure for other users or environments. It is better to use relative path resolution or generic placeholders with environment variable fallbacks, similar to the pattern used in run_hunyuan_image3_i2i.sh.
| export lightx2v_path="/data/nvme0/lhd_codes/LightX2V" | |
| export model_path="/data/nvme0/lhd_codes/HunyuanImage-3.0-instruct/HunyuanImage-3-Instruct" | |
| export HUNYUAN_IMAGE3_REPO_PATH="${HUNYUAN_IMAGE3_REPO_PATH:-/data/nvme0/lhd_codes/HunyuanImage-3.0}" | |
| export lightx2v_path=${lightx2v_path:-$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)} | |
| export model_path=${model_path:-/path/to/HunyuanImage-3-Instruct} | |
| export HUNYUAN_IMAGE3_REPO_PATH=${HUNYUAN_IMAGE3_REPO_PATH:-/path/to/HunyuanImage-3.0} |
| 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 HUNYUAN_IMAGE3_REPO_PATH="${HUNYUAN_IMAGE3_REPO_PATH:-/data/nvme0/lhd_codes/HunyuanImage-3.0}" |
There was a problem hiding this comment.
Hardcoding absolute paths on a specific machine makes the script non-portable and prone to failure for other users or environments. It is better to use relative path resolution or generic placeholders with environment variable fallbacks, similar to the pattern used in run_hunyuan_image3_i2i.sh.
| 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 HUNYUAN_IMAGE3_REPO_PATH="${HUNYUAN_IMAGE3_REPO_PATH:-/data/nvme0/lhd_codes/HunyuanImage-3.0}" | |
| export lightx2v_path=${lightx2v_path:-$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)} | |
| export model_path=${model_path:-/path/to/HunyuanImage-3-Instruct} | |
| export HUNYUAN_IMAGE3_REPO_PATH=${HUNYUAN_IMAGE3_REPO_PATH:-/path/to/HunyuanImage-3.0} |
No description provided.