Hunyuan-GameCraft: High-dynamic Interactive Game Video Generation with Hybrid History Condition
| Files | Last commit | Last update |
|---|---|---|
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 11 months ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago |
Hunyuan-GameCraft 🎮

🔥🔥🔥 最新动态!!
📑 开源计划
- Hunyuan-GameCraft
目录
摘要
近年来,基于扩散模型和可控视频生成技术的进步,已能够合成高质量且时间连贯的视频,为沉浸式互动游戏体验奠定了基础。然而,当前方法在动态性、物理真实性、长期一致性和效率方面存在局限,限制了创建多样化游戏视频的能力。为解决这些问题,我们提出了Hunyuan-GameCraft,一个用于游戏环境中高动态交互视频生成的新型框架。为实现细粒度的动作控制,我们将标准键盘和鼠标输入统一到共享相机表示空间,促进不同相机和移动操作之间的平滑插值。然后,我们提出混合历史条件训练策略,在自回归扩展视频序列的同时保留游戏场景信息。此外,为提高推理效率和可玩性,我们通过模型蒸馏减少计算开销,同时保持长时序序列的一致性,使其适用于复杂交互环境中的实时部署。该模型在包含超过100款AAA游戏的一百万条游戏录制数据的大规模数据集上进行训练,确保广泛的覆盖性和多样性,然后在精心标注的合成数据集上进行微调,以提高精度和可控性。精选的游戏场景数据显著提升了视觉保真度、真实感和动作可控性。大量实验表明,Hunyuan-GameCraft显著优于现有模型,推动了交互游戏视频生成的真实感和可玩性。
整体架构

给定一张参考图像及其对应的提示词、键盘或鼠标信号,我们将这些输入转换到连续相机空间。然后,我们设计一个轻量级动作编码器来对输入的相机轨迹进行编码。动作特征和图像特征在分块后相加。对于长视频扩展,我们设计了一个可变掩码指示器,其中1和0分别表示历史帧和预测帧。
📜 环境要求
- 需要配备支持 CUDA 的 NVIDIA 显卡。
- 该模型已在配备 8 张 H20/H800 GPU 的机器上完成测试。
- 最低配置:所需的最低 GPU 内存为 24GB,但生成速度会非常慢。
- 推荐配置:建议使用显存为 80GB 的 GPU,以获得更优的生成质量。
- 已测试的操作系统:Linux
🛠️ 依赖项与安装
首先克隆本仓库:
git clone https://github.com/Tencent-Hunyuan/Hunyuan-GameCraft-1.0.git
cd Hunyuan-GameCraft-1.0
Linux 安装指南
手动安装时,我们推荐使用 CUDA 12.4 版本。
Conda 的安装说明可在 此处 获取。
# 1. Create conda environment
conda create -n HYGameCraft python==3.10
# 2. Activate the environment
conda activate HYGameCraft
# 3. Install PyTorch and other dependencies using conda
conda install pytorch==2.5.1 torchvision==0.20.0 torchaudio==2.5.1 pytorch-cuda=12.4 -c pytorch -c nvidia
# 4. Install pip dependencies
python -m pip install -r requirements.txt
# 5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
python -m pip install ninja
python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.6.3
此外,您也可以使用HunyuanVideo Docker镜像。使用以下命令拉取并运行该Docker镜像。
# For CUDA 12.4 (updated to avoid float point exception)
docker pull hunyuanvideo/hunyuanvideo:cuda_12
docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_12
pip install diffusers==0.34.0 transformers==4.54.1
🧱 下载预训练模型
预训练模型的下载详情请参见此处。
🚀 多GPU并行推理
例如,要使用8块GPU生成视频,可运行以下命令。其中--action-list w s d a用于模拟键盘操作信号,以帮助生成对应内容的视频。--action-speed-list 0.2 0.2 0.2 0.2表示位移距离,可替换为0到3之间的任意数值。
您可以尝试任意组合和任意长度的动作列表(每33帧一个动作,25FPS)来生成长视频,并确保--action-speed-list的长度与--action-list相同。需要注意的是,推理时间与动作长度呈线性关系:
#!/bin/bash
JOBS_DIR=$(dirname $(dirname "$0"))
export PYTHONPATH=${JOBS_DIR}:$PYTHONPATH
export MODEL_BASE="weights/stdmodels"
checkpoint_path="weights/gamecraft_models/mp_rank_00_model_states.pt"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
modelname='Tencent_hunyuanGameCraft_720P'
torchrun --nnodes=1 --nproc_per_node=8 --master_port 29605 hymm_sp/sample_batch.py \
--image-path "asset/village.png" \
--prompt "A charming medieval village with cobblestone streets, thatched-roof houses, and vibrant flower gardens under a bright blue sky." \
--add-pos-prompt "Realistic, High-quality." \
--add-neg-prompt "overexposed, low quality, deformation, a poor composition, bad hands, bad teeth, bad eyes, bad limbs, distortion, blurring, text, subtitles, static, picture, black border." \
--ckpt ${checkpoint_path} \
--video-size 704 1216 \
--cfg-scale 2.0 \
--image-start \
--action-list w s d a \
--action-speed-list 0.2 0.2 0.2 0.2 \
--seed 250160 \
--infer-steps 50 \
--flow-shift-eval-video 5.0 \
--save-path './results/'
此外,我们支持FP8优化和SageAttn。要启用FP8,只需在命令中添加--use-fp8。
并通过以下方式安装SageAttention:
git clone https://github.com/thu-ml/SageAttention.git
cd SageAttention
python setup.py install # or pip install -e .
我们还提供了一个加速模型,您可以使用以下命令:
#!/bin/bash
JOBS_DIR=$(dirname $(dirname "$0"))
export PYTHONPATH=${JOBS_DIR}:$PYTHONPATH
export MODEL_BASE="weights/stdmodels"
checkpoint_path="weights/gamecraft_models/mp_rank_00_model_states_distill.pt"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
modelname='Tencent_hunyuanGameCraft_720P'
torchrun --nnodes=1 --nproc_per_node=8 --master_port 29605 hymm_sp/sample_batch.py \
--image-path "asset/village.png" \
--prompt "A charming medieval village with cobblestone streets, thatched-roof houses, and vibrant flower gardens under a bright blue sky." \
--add-neg-prompt "overexposed, low quality, deformation, a poor composition, bad hands, bad teeth, bad eyes, bad limbs, distortion, blurring, text, subtitles, static, picture, black border." \
--ckpt ${checkpoint_path} \
--video-size 704 1216 \
--cfg-scale 1.0 \
--image-start \
--action-list w s d a \
--action-speed-list 0.2 0.2 0.2 0.2 \
--seed 250160 \
--infer-steps 8 \
--use-fp8 \
--flow-shift-eval-video 5.0 \
--save-path './results_distill/'
🔑 单GPU低显存推理
例如,若要使用单块低显存GPU生成视频(生成704px1216p分辨率视频的最低GPU显存要求为24GB,但速度会非常慢),可使用以下命令:
#!/bin/bash
JOBS_DIR=$(dirname $(dirname "$0"))
export PYTHONPATH=${JOBS_DIR}:$PYTHONPATH
export MODEL_BASE="weights/stdmodels"
checkpoint_path="weights/gamecraft_models/mp_rank_00_model_states.pt"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
modelname='Tencent_hunyuanGameCraft_720P'
# disable sp and cpu offload
export DISABLE_SP=1
export CPU_OFFLOAD=1
torchrun --nnodes=1 --nproc_per_node=1 --master_port 29605 hymm_sp/sample_batch.py \
--image-path "asset/village.png" \
--prompt "A charming medieval village with cobblestone streets, thatched-roof houses, and vibrant flower gardens under a bright blue sky." \
--add-neg-prompt "overexposed, low quality, deformation, a poor composition, bad hands, bad teeth, bad eyes, bad limbs, distortion, blurring, text, subtitles, static, picture, black border." \
--ckpt ${checkpoint_path} \
--video-size 704 1216 \
--cfg-scale 2.0 \
--image-start \
--action-list w a d s \
--action-speed-list 0.2 0.2 0.2 0.2 \
--seed 250160 \
--sample-n-frames 33 \
--infer-steps 50 \
--flow-shift-eval-video 5.0 \
--cpu-offload \
--use-fp8 \
--save-path './results_poor/'
关于使用加速模型,您可以使用以下命令:
#!/bin/bash
JOBS_DIR=$(dirname $(dirname "$0"))
export PYTHONPATH=${JOBS_DIR}:$PYTHONPATH
export MODEL_BASE="weights/stdmodels"
checkpoint_path="weights/gamecraft_models/mp_rank_00_model_states_distill.pt"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
modelname='Tencent_hunyuanGameCraft_720P'
# disable sp and cpu offload
export DISABLE_SP=1
export CPU_OFFLOAD=1
torchrun --nnodes=1 --nproc_per_node=1 --master_port 29605 hymm_sp/sample_batch.py \
--image-path "asset/village.png" \
--prompt "A charming medieval village with cobblestone streets, thatched-roof houses, and vibrant flower gardens under a bright blue sky." \
--add-neg-prompt "overexposed, low quality, deformation, a poor composition, bad hands, bad teeth, bad eyes, bad limbs, distortion, blurring, text, subtitles, static, picture, black border." \
--ckpt ${checkpoint_path} \
--video-size 704 1216 \
--cfg-scale 1.0 \
--image-start \
--action-list w a d s \
--action-speed-list 0.2 0.2 0.2 0.2 \
--seed 250160 \
--sample-n-frames 33 \
--infer-steps 8 \
--flow-shift-eval-video 5.0 \
--cpu-offload \
--use-fp8 \
--save-path './results_distill_poor/'
🖥️ Gradio 启动
请参考相应注释,修改 scripts/launch_app_sp.sh 中的以下部分:
export MODEL_BASE="weights/stdmodels"
export CKPT_PATH="weights/gamecraft_models/mp_rank_00_model_states.pt"
export API_PORT="8082" # For distributed inference server port
export GRADIO_PORT="8080" # For GradioUI port
export VIDEO_ENC="vp09" # "avc1"(faster)
NUM_GPUS=8
安装 gradio(>5.0)和 flask 后,直接运行:
bash scripts/launch_app_sp.sh
这将自动启动分布式推理 API 服务和 Gradio Web 界面(默认地址:http://127.0.0.1:8080)。所有运行时日志可在 gradio_results/api.log(API 服务日志)和 gradio_results/worker.log(推理工作器日志)中查看。Web 界面如下所示:

🔗 BibTeX
如果您发现 Hunyuan-GameCraft 对您的研究和应用有所帮助,请使用以下 BibTeX 进行引用:
@misc{li2025hunyuangamecrafthighdynamicinteractivegame,
title={Hunyuan-GameCraft: High-dynamic Interactive Game Video Generation with Hybrid History Condition},
author={Jiaqi Li and Junshu Tang and Zhiyong Xu and Longhuang Wu and Yuan Zhou and Shuai Shao and Tianbao Yu and Zhiguo Cao and Qinglin Lu},
year={2025},
eprint={2506.17201},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2506.17201},
}
致谢
我们要感谢 HunyuanVideo、HunyuanVideo-Avatar、SD3、FLUX、Llama、LLaVA、Xtuner、diffusers 和 HuggingFace 等代码仓库的贡献者们,感谢他们在开放研究与探索方面所做的努力。
Introduction
Hunyuan-GameCraft: High-dynamic Interactive Game Video Generation with Hybrid History Condition
Customize your domain