Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions configs/dist_infer/hunyuan_image3_t2i_dist_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"target_height": 1024,
"target_width": 1024,
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"taylor_cache_interval": 5,
"taylor_cache_order": 2,
"taylor_cache_enable_first_enhance": false,
"taylor_cache_first_enhance_steps": 3,
"taylor_cache_enable_tailing_enhance": false,
"taylor_cache_tailing_enhance_steps": 1,
"taylor_cache_low_freqs_order": 2,
"taylor_cache_high_freqs_order": 2,
"pipeline_parallel": true,
"enable_cfg": true,
"hunyuan_cfg_mode": "parallel",
"parallel": {
"cfg_p_size": 2
},
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
30 changes: 30 additions & 0 deletions configs/dist_infer/hunyuan_image3_t2i_dist_cfg_kv_all_gather.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"target_height": 1024,
"target_width": 1024,
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"pipeline_parallel": true,
"hunyuan_image3_pipeline_layout": "interleaved",
"enable_cfg": true,
"hunyuan_cfg_mode": "parallel",
"moe_impl": "flashinfer",
"attn_impl": "flash_attention_2",
"flashinfer_autotune_mode": "tune",
"parallel": {
"cfg_p_size": 2,
"seq_p_size": 2,
"seq_p_attn_type": "kv_all_gather"
},
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
30 changes: 30 additions & 0 deletions configs/dist_infer/hunyuan_image3_t2i_dist_cfg_ulysses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"target_height": 1024,
"target_width": 1024,
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"pipeline_parallel": true,
"hunyuan_image3_pipeline_layout": "interleaved",
"enable_cfg": true,
"hunyuan_cfg_mode": "parallel",
"moe_impl": "flashinfer",
"attn_impl": "sdpa",
"flashinfer_autotune_mode": "tune",
"parallel": {
"cfg_p_size": 2,
"seq_p_size": 2,
"seq_p_attn_type": "ulysses"
},
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
29 changes: 29 additions & 0 deletions configs/dist_infer/hunyuan_image3_t2i_dist_kv_all_gather.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"target_height": 1024,
"target_width": 1024,
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"pipeline_parallel": true,
"enable_cfg": true,
"hunyuan_cfg_mode": "serial",
"moe_impl": "flashinfer",
"attn_impl": "sdpa",
"flashinfer_autotune_mode": "tune",
"parallel": {
"cfg_p_size": 1,
"seq_p_size": 2,
"seq_p_attn_type": "kv_all_gather"
},
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
29 changes: 29 additions & 0 deletions configs/dist_infer/hunyuan_image3_t2i_dist_ulysses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"target_height": 1024,
"target_width": 1024,
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"pipeline_parallel": true,
"enable_cfg": true,
"hunyuan_cfg_mode": "serial",
"moe_impl": "flashinfer",
"attn_impl": "sdpa",
"flashinfer_autotune_mode": "tune",
"parallel": {
"cfg_p_size": 1,
"seq_p_size": 2,
"seq_p_attn_type": "ulysses"
},
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
28 changes: 28 additions & 0 deletions configs/hunyuan_image3/hunyuan_image3_i2i.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"image_size": "auto",
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"taylor_cache_interval": 5,
"taylor_cache_order": 2,
"taylor_cache_enable_first_enhance": false,
"taylor_cache_first_enhance_steps": 3,
"taylor_cache_enable_tailing_enhance": false,
"taylor_cache_tailing_enhance_steps": 1,
"taylor_cache_low_freqs_order": 2,
"taylor_cache_high_freqs_order": 2,
"pipeline_parallel": true,
"enable_cfg": true,
"infer_align_image_size": true,
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
28 changes: 28 additions & 0 deletions configs/hunyuan_image3/hunyuan_image3_t2i.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"infer_steps": 50,
"sample_guide_scale": 5.0,
"flow_shift": 1.0,
"target_height": 1024,
"target_width": 1024,
"feature_caching": "NoCaching",
"enable_kv_cache": true,
"enable_text_kv_cache": true,
"use_taylor_cache": false,
"taylor_cache_interval": 5,
"taylor_cache_order": 2,
"taylor_cache_enable_first_enhance": false,
"taylor_cache_first_enhance_steps": 3,
"taylor_cache_enable_tailing_enhance": false,
"taylor_cache_tailing_enhance_steps": 1,
"taylor_cache_low_freqs_order": 2,
"taylor_cache_high_freqs_order": 2,
"pipeline_parallel": true,
"enable_cfg": true,
"bot_task": "think_recaption",
"use_system_prompt": "en_unified",
"max_new_tokens": 2048,
"text_do_sample": true,
"text_top_k": 1024,
"text_top_p": 0.95,
"text_temperature": 0.6
}
5 changes: 4 additions & 1 deletion lightx2v/common/ops/norm/rms_norm_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ def _get_lora_attr_mapping(self):
self.weight_diff = torch.tensor(0.0, dtype=GET_DTYPE(), device=AI_DEVICE)

def _get_actual_weight(self):
if not hasattr(self, "weight_diff"):
if not hasattr(self, "weight_diff") or not self.has_diff:
return self.weight
if self.weight_diff.device != self.weight.device or self.weight_diff.dtype != self.weight.dtype:
self.weight_diff = self.weight_diff.to(device=self.weight.device, dtype=self.weight.dtype)
return self.weight + self.weight_diff

def register_diff(self, weight_dict):
if not self.lazy_load or self.create_cuda_buffer or self.create_cpu_buffer:
if self.weight_diff_name in weight_dict:
self.weight_diff = weight_dict[self.weight_diff_name]
self.has_diff = True
logger.debug(f"Register Diff to {self.weight_name}")

def load(self, weight_dict):
Expand Down
117 changes: 117 additions & 0 deletions lightx2v/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from lightx2v.models.runners.flux2.flux2_runner import Flux2DevRunner, Flux2KleinRunner # noqa: F401
from lightx2v.models.runners.hidream_o1_image.hidream_o1_image_runner import HidreamO1ImageRunner # noqa: F401
from lightx2v.models.runners.hunyuan3d.hunyuan3d_shape_runner import Hunyuan3DShapeRunner # noqa: F401
from lightx2v.models.runners.hunyuan_image3.hunyuan_image3_runner import HunyuanImage3Runner # noqa: F401
from lightx2v.models.runners.hunyuan_video.hunyuan_video_15_distill_runner import HunyuanVideo15DistillRunner # noqa: F401
from lightx2v.models.runners.hunyuan_video.hunyuan_video_15_runner import HunyuanVideo15Runner # noqa: F401
from lightx2v.models.runners.lingbot_video.lingbot_video_runner import LingBotVideoRunner # noqa: F401
Expand Down Expand Up @@ -49,6 +50,17 @@
from lightx2v_platform.registry_factory import PLATFORM_DEVICE_REGISTER


def _str2bool(value):
if isinstance(value, bool):
return value
lowered = value.lower()
if lowered in ("1", "true", "yes", "y", "on"):
return True
if lowered in ("0", "false", "no", "n", "off"):
return False
raise argparse.ArgumentTypeError(f"Expected a boolean value, got {value!r}")


def init_runner(config):
torch.set_grad_enabled(False)
runner = RUNNER_REGISTER[config["model_cls"]](config)
Expand Down Expand Up @@ -91,6 +103,7 @@ def main():
"wan2.2_s2v",
"hunyuan_video_1.5",
"hunyuan_video_1.5_distill",
"hunyuan_image3",
"hunyuan3d",
"worldplay_distill",
"worldplay_ar",
Expand Down Expand Up @@ -120,6 +133,110 @@ def main():
parser.add_argument("--support_tasks", type=str, nargs="+", default=[], help="Set supported tasks for the model")
parser.add_argument("--model_path", type=str, required=True)
parser.add_argument("--config_json", type=str, required=True)
hunyuan_cache_args = parser.add_argument_group("HunyuanImage3 cache options")
hunyuan_cache_args.add_argument("--enable_kv_cache", "--enable-kv-cache", dest="enable_kv_cache", type=_str2bool, nargs="?", const=True, default=None)
hunyuan_cache_args.add_argument("--enable_text_kv_cache", "--enable-text-kv-cache", dest="enable_text_kv_cache", type=_str2bool, nargs="?", const=True, default=None)
hunyuan_cache_args.add_argument("--use_taylor_cache", "--use-taylor-cache", dest="use_taylor_cache", type=_str2bool, nargs="?", const=True, default=None)
hunyuan_cache_args.add_argument("--taylor_cache_interval", "--taylor-cache-interval", dest="taylor_cache_interval", type=int, default=None)
hunyuan_cache_args.add_argument("--taylor_cache_order", "--taylor-cache-order", dest="taylor_cache_order", type=int, default=None)
hunyuan_cache_args.add_argument(
"--taylor_cache_enable_first_enhance",
"--taylor-cache-enable-first-enhance",
dest="taylor_cache_enable_first_enhance",
type=_str2bool,
nargs="?",
const=True,
default=None,
)
hunyuan_cache_args.add_argument("--taylor_cache_first_enhance_steps", "--taylor-cache-first-enhance-steps", dest="taylor_cache_first_enhance_steps", type=int, default=None)
hunyuan_cache_args.add_argument(
"--taylor_cache_enable_tailing_enhance",
"--taylor-cache-enable-tailing-enhance",
dest="taylor_cache_enable_tailing_enhance",
type=_str2bool,
nargs="?",
const=True,
default=None,
)
hunyuan_cache_args.add_argument("--taylor_cache_tailing_enhance_steps", "--taylor-cache-tailing-enhance-steps", dest="taylor_cache_tailing_enhance_steps", type=int, default=None)
hunyuan_cache_args.add_argument("--taylor_cache_low_freqs_order", "--taylor-cache-low-freqs-order", dest="taylor_cache_low_freqs_order", type=int, default=None)
hunyuan_cache_args.add_argument("--taylor_cache_high_freqs_order", "--taylor-cache-high-freqs-order", dest="taylor_cache_high_freqs_order", type=int, default=None)
hunyuan_native_args = parser.add_argument_group("HunyuanImage3 native implementation options")
hunyuan_native_args.add_argument("--moe_impl", "--moe-impl", dest="moe_impl", type=str, choices=["eager", "flashinfer"], default=None)
hunyuan_native_args.add_argument(
"--hunyuan_cfg_mode",
"--hunyuan-cfg-mode",
dest="hunyuan_cfg_mode",
type=str,
choices=["batch", "serial", "parallel"],
default=None,
help="HunyuanImage3 CFG execution mode: batch packs cond/uncond, serial runs two batch=1 forwards, parallel splits cond/uncond by cfg rank.",
)
hunyuan_native_args.add_argument(
"--attn_impl",
"--attn-impl",
dest="attn_impl",
type=str,
choices=[
"eager",
"sdpa",
"torch_sdpa",
"flash_attention_2",
"flash_attn2",
"flash_attention_3",
"flash_attn3",
"sage_attn2",
"sage_attn3",
],
default=None,
)
hunyuan_sp_args = parser.add_argument_group("HunyuanImage3 sequence parallel options")
hunyuan_sp_args.add_argument(
"--hunyuan_sp_size",
"--hunyuan-sp-size",
dest="hunyuan_sp_size",
type=int,
default=None,
)
hunyuan_sp_args.add_argument(
"--hunyuan_sp_attn_type",
"--hunyuan-sp-attn-type",
dest="hunyuan_sp_attn_type",
type=str,
choices=["kv_all_gather", "kv-all-gather", "ulysses"],
default=None,
)
hunyuan_sp_args.add_argument(
"--hunyuan_pipeline_layout",
"--hunyuan-pipeline-layout",
dest="hunyuan_image3_pipeline_layout",
type=str,
choices=["interleaved", "contiguous"],
default=None,
)
hunyuan_flashinfer_args = parser.add_argument_group("HunyuanImage3 FlashInfer autotune options")
hunyuan_flashinfer_args.add_argument("--flashinfer_autotune", "--flashinfer-autotune", dest="flashinfer_autotune", type=_str2bool, nargs="?", const=True, default=None)
hunyuan_flashinfer_args.add_argument(
"--flashinfer_autotune_mode",
"--flashinfer-autotune-mode",
dest="flashinfer_autotune_mode",
type=str,
choices=["off", "tune", "load"],
default=None,
help="'tune' profiles missing FlashInfer fused MoE tactics and saves cache; 'load' only loads cache; 'off' disables autotune.",
)
hunyuan_flashinfer_args.add_argument("--flashinfer_autotune_cache", "--flashinfer-autotune-cache", dest="flashinfer_autotune_cache", type=str, default=None)
hunyuan_flashinfer_args.add_argument("--flashinfer_tuning_buckets", "--flashinfer-tuning-buckets", dest="flashinfer_tuning_buckets", type=str, default=None)
hunyuan_flashinfer_args.add_argument(
"--flashinfer_autotune_round_up",
"--flashinfer-autotune-round-up",
dest="flashinfer_autotune_round_up",
type=_str2bool,
nargs="?",
const=True,
default=None,
)
hunyuan_flashinfer_args.add_argument("--flashinfer_tune_max_num_tokens", "--flashinfer-tune-max-num-tokens", dest="flashinfer_tune_max_num_tokens", type=int, default=None)
parser.add_argument("--use_prompt_enhancer", action="store_true")
parser.add_argument("--warmup", action="store_true", help="Warm up the model before inference. Disabled by default.")
parser.add_argument("--prompt", type=str, default="", help="The input prompt for text-to-video generation")
Expand Down
3 changes: 3 additions & 0 deletions lightx2v/models/networks/hunyuan_image3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .model import HunyuanImage3Model

__all__ = ["HunyuanImage3Model"]
Loading