当前位置: 首页 > news >正文

CANN/Hunyuan3D昇腾适配

在昇腾训练平台上适配Hunyuan3D 2.0 模型的推理

【免费下载链接】cann-recipes-spatial-intelligence本项目针对空间智能业务中的典型模型、加速算法,提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-spatial-intelligence

Hunyuan3D模型是腾讯混元系列在2025年推出的一款3D资产创作模型,用于生成带有高分辨率纹理贴图的高保真度3D模型,本项目旨在提供Hunyuan3D的NPU适配版本,方便用户能够在昇腾生态上直接使用Hunyuan3D。

此外,本样例基于Hunyuan3D模型在NPU进行了性能优化,目前texgen在2万平面mesh网格输入下,推理时间降至26秒。详细内容可至性能优化章节进行查看。

执行样例

环境准备

  1. 本样例采用CANN 8.2.RC1。请从CANN软件包下载地址下载Ascend-cann-toolkit_${version}_linux-${arch}.runAscend-cann-kernels-${chip_type}_${version}_linux-${arch}.run软件包,并参考CANN安装文档进行安装。

    conda create -n hunyuan3d python==3.10.18 conda activate hunyuan3d
  • 本样例的torch以及torch_npu版本为2.6,请从Ascend Extension for PyTorch插件下载torch与torch_npu安装包,同时指定decorator版本
    pip install torch==2.6.0 pip install torchvision==0.21.0 pip install torch-npu==2.6.0.post3 pip install decorator==5.2.1 pip install ninja

网络模型代码准备

  • 本仓库依赖Hunyuan3D的开源仓库代码。

  • 进入Hunyuan3D的官方仓库,下载Hunyuan3D模型网络结构代码

    git clone https://github.com/Tencent-Hunyuan/Hunyuan3D-2.git
  • 下载本仓库代码

    git clone https://gitcode.com/cann/cann-recipes-spatial-intelligence.git
  • 将Hunyuan3D仓库的网络模型文件以非覆盖模式复制到本项目目录下。其中下方命令里的/path/to/Hunyuan3D-2/改为Hunyuan3D-2文件路径。

    cd cann-recipes-spatial-intelligence/models/Hunyuan3D cp -rn /path/to/Hunyuan3D-2/* ./
  • 安装Python依赖

    pip install -r requirements.txt
  • 编译第三方代码

    cd hy3dgen/texgen/differentiable_renderer python3 setup.py install
  • 模型结构修改部分如下所示

    Hunyuan3D +--- hy3dgen +--- texgen +--- custom_rasterizer ==> custom_rasterizer in current depository #替换当前文件 +--- differentiable_renderer +--- mesh_render.py ==> differentiable_renderer/mesh_render.py #替换文件 +--- rasterizer.py #添加新文件 +--- minimal_demo_npu.py #添加新文件

权重模型

NPU环境支持Hunyuan3D模型列表,用户可根据需要下载蒸馏版本:

Hunyuan3D-2mv 系列

ModelDescriptionDateSizeHuggingface
Hunyuan3D-DiT-v2-mvMultiview Image to Shape Model2025-03-181.1BDownload

Hunyuan3D-2 系列

ModelDescriptionDateSizeHuggingface
Hunyuan3D-DiT-v2-0Image to Shape Model2025-01-211.1BDownload
Hunyuan3D-Paint-v2-0Texture Generation Model2025-01-211.3BDownload
Hunyuan3D-Delight-v2-0Image Delight Model2025-01-211.3BDownload
  • 权重安装地址为base_dir+model_path,默认base_dir~/.cache/hy3dgen/,如需修改base_dir,需将./hy3dgen/shapegen/utils.py中第97行和./hy3dgen/texgen/pipelines.py中第61行进行修改

    class Hunyuan3DPaintPipeline: @classmethod def from_pretrained(cls, model_path, subfolder='hunyuan3d-paint-v2-0-turbo'): original_model_path = model_path if not os.path.exists(model_path): # try local path base_dir = os.environ.get('HY3DGEN_MODELS', '~/.cache/hy3dgen/') model_path = os.path.expanduser(os.path.join(base_dir, model_path))
  • 最后模型权重路径为

    base_dir+model_path +--- hunyuan3d-dit-v2-0 #单视角图像DIT模型 +--- hunyuan3d-dit-v2-mv #多视角图像DIT模型 +--- hunyuan3d-delight-v2-0 +--- hunyuan3d-paint-v2-0

执行推理

执行推理

由于本项目依靠 cann-recipes-spatial-intelligence 中的module所带的优化模块进行,因此在开始推理前,需要设置环境变量,执行如下指令

source set_env.sh

即可将module所带的优化模块加入环境变量中,之后执行

python minimal_demo_npu.py

minimal_demo_npu.py采用默认设置执行单图像推理,运行不同配置可参考以下脚本执行:

python minimal_demo_npu.py --model_path tencent/Hunyuan3D-2 --multiview --face_reduce --full_graph --multi_thread (--use_render_npu) --save_render

model_path选择模型路径,multiview设置是否采用多视角推理,face_reduce设置是否减少三角面片,full_graph设置是否采用图模式,multi_thread设置是否采用多线程并行执行光栅化,use_render_npu设置是否采用npu方式执行光栅化(不能与multi_thread共同使用),save_render设置是否复用光栅化结果。

推理步骤介绍

Hunyuan3D源码参考diffusers接口API,用于物体生成,包括Hunyuan3D-DiTHunyuan3D-Paint两个部分。

运行Hunyuan3D-DiT方式如下:

from hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline from torch_npu.contrib import transfer_to_npu pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2') mesh = pipeline(image='assets/demo.png')[0]

运行Hunyuan3D-Paint方式如下:

from hy3dgen.texgen import Hunyuan3DPaintPipeline from hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline from torch_npu.contrib import transfer_to_npu pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained('tencent/Hunyuan3D-2') mesh = pipeline(image='assets/demo.png')[0] pipeline = Hunyuan3DPaintPipeline.from_pretrained('tencent/Hunyuan3D-2') mesh = pipeline(mesh, image='assets/demo.png')

Hunyuan3D-DiT执行过程中,我们在NPU环境下提供多视角模型推理,具体方式如下:

from hy3dgen.texgen import Hunyuan3DPaintPipeline from hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline from torch_npu.contrib import transfer_to_npu images = { "front": "assets/example_mv_images/1/front.png", "left": "assets/example_mv_images/1/left.png", "back": "assets/example_mv_images/1/back.png" } pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained( 'tencent/Hunyuan3D-2mv', subfolder='hunyuan3d-dit-v2-mv', variant='fp16' ) mesh = pipeline( image=images, num_inference_steps=50, octree_resolution=380, num_chunks=20000, generator=torch.manual_seed(12345), output_type='trimesh' )[0] pipeline = Hunyuan3DPaintPipeline.from_pretrained('tencent/Hunyuan3D-2') mesh = pipeline(mesh, image=list(image.values()))

Citation

@misc{lai2025hunyuan3d25highfidelity3d, title={Hunyuan3D 2.5: Towards High-Fidelity 3D Assets Generation with Ultimate Details}, author={Tencent Hunyuan3D Team}, year={2025}, eprint={2506.16504}, archivePrefix={arXiv}, primaryClass={cs.CV}, url={https://arxiv.org/abs/2506.16504}, } @misc{hunyuan3d22025tencent, title={Hunyuan3D 2.0: Scaling Diffusion Models for High Resolution Textured 3D Assets Generation}, author={Tencent Hunyuan3D Team}, year={2025}, eprint={2501.12202}, archivePrefix={arXiv}, primaryClass={cs.CV} } @misc{yang2024hunyuan3d, title={Hunyuan3D 1.0: A Unified Framework for Text-to-3D and Image-to-3D Generation}, author={Tencent Hunyuan3D Team}, year={2024}, eprint={2411.02293}, archivePrefix={arXiv}, primaryClass={cs.CV} }

【免费下载链接】cann-recipes-spatial-intelligence本项目针对空间智能业务中的典型模型、加速算法,提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-spatial-intelligence

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

http://www.jsqmd.com/news/787890/

相关文章:

  • cann/cann-bench CrossEntropyLoss算子API描述
  • 算法模拟与生命智能:从架构差异看AI的本质与局限
  • CANN/ops-nn硬Sigmoid反向传播算子
  • 命令行办公自动化:officecli-skills技能库实战指南
  • ARM虚拟处理器模型在无线设备开发中的关键作用
  • 房价预测项目:自己手写线性回归,值不值?
  • AI赋能食品工业:从合成生物学到智能制造的全面革新
  • Datadog Cursor插件:用自然语言对话查询监控数据的完整指南
  • CANN/pyasc算子编程接口
  • 3PEAK思瑞浦 LM2902A-TS2R-S TSSOP14 运算放大器
  • Meta广告AI代理实战:基于MCP协议构建自动化广告管理工具
  • Animal-AI环境:用强化学习复现动物认知实验,评估AI智能水平
  • 智能代理框架ProxyAI:AI赋能API网关与微服务架构实践
  • 集成学习在药物虚拟筛选中的应用:构建稳健AI预测模型
  • 基于FNN与XAI的微射流速度预测及气泡位置影响机制研究
  • 3PEAK思瑞浦 TPA3672-SO1R SOP8 运算放大器
  • SEO地理优化利器:hreflang与JSON-LD实战指南
  • AI赋能密度泛函理论:量子张量学习与机器学习泛函实践
  • 抖音内容下载终极指南:从零开始构建你的专属素材库
  • 动物森友会存档编辑器NHSE:终极完整指南与实战教程
  • AI驱动蛋白质工程:机器学习与拓扑数据分析的融合实践
  • AI接管运维:工程师秒变甩手掌柜
  • 5分钟掌握qmc-decoder:终极QQ音乐加密格式解密指南
  • 华为CANN通信远端内存API
  • CANN随机数算子库文档
  • Spring Boot 缓存优化:从入门到精通
  • 5G波形技术演进与新型解决方案对比
  • 钉钉机器人 Webhook 方式与 SDK 方式接入哪种更适合 CI/CD 场景?
  • 2026年四川地区钢材采购决策:如何筛选靠谱供应商与盛世钢联建立长期合作 - 四川盛世钢联营销中心
  • Arm安全协处理器寄存器架构与内存重映射技术解析