Skip to content

combine hunyuan#1227

Open
Chernobyllight wants to merge 3 commits into
ModelTC:mainfrom
Chernobyllight:lightx2v-hunyuan
Open

combine hunyuan#1227
Chernobyllight wants to merge 3 commits into
ModelTC:mainfrom
Chernobyllight:lightx2v-hunyuan

Conversation

@Chernobyllight

Copy link
Copy Markdown

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +69 to 70
if not hasattr(self, "weight_diff") or not self.has_diff:
return self.weight

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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

Comment thread lightx2v/infer.py
Comment on lines +69 to +73
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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)

Comment on lines +855 to +857
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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))

Comment on lines +14 to +15
if self.mm_type != "Default":
assert config.get("dit_quantized") is True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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'")

Comment on lines +283 to +286
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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Comment on lines +4 to +5
lightx2v_path="/data/nvme0/lhd_codes/LightX2V"
model_path="/data/nvme0/models/Wan-AI/Wan2.1-I2V-14B-720P"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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}

Comment on lines +4 to +5
lightx2v_path="/data/nvme0/lhd_codes/LightX2V"
model_path="/data/nvme0/models/Wan-AI/Wan2.1-T2V-1.3B"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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}

Comment on lines +15 to +17
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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}

Comment on lines +27 to +29
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant