admin 管理员组文章数量: 1184232
Win11 + RTX 3090 亲测:ComfyUI Hunyuan3D 自定义光栅化器编译全记录(CUDA 13.1 vs PyTorch 12.6 完美绕过)
环境:Windows 11 23H2 | Intel Ultra 9 285K | RTX 3090 24 GB | CUDA 13.1 | Python 3.12.11 | PyTorch 2.7.1+cu126 | ComfyUI 0.5.1
插件:ComfyUI-Hunyuan3DWrapper v1.0.0 | Manager 3.39 | 节点数 221+ | 插件数 180+
一、背景与问题
ComfyUI-Hunyuan3DWrapper
Hunyuan3DWrapper 是 ComfyUI 的高人气 3D 生成插件,其「网格渲染」节点依赖自定义 CUDA 扩展 custom_rasterizer。
官方也提供了可直接使用的.whl文件:(在 -folder 中):
python.exe -m pip install ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\wheels\custom_rasterizer-0.1-cp312-cp312-win_amd64.whl
如果上述安装不行,或者没有适合自己系统使用的轮子。我们需要自己编译:
官方安装文档示例参考:
cd hy3dgen/texgen/custom_rasterizer
python setup.py install
实测直接编译会报 CUDA 版本不匹配:
RuntimeError: The detected CUDA version (13.1) mismatches the version that was used to compile PyTorch (12.6)
本文记录完整绕过方案,无需降级驱动,无需重装 PyTorch,记录下来以回顾。
二、解决思路总览
- 使用 VS2022 x64 终端 初始化编译环境
- Monkey Patch 掉 Torch 内部
_check_cuda_version - 正常
bdist_wheel编译 → 安装 → 验证节点加载
三、环境准备(参考对照清单)
| 项目 | 本机示例 | 最低要求 |
|---|---|---|
| OS | Windows 11 专业工作站版 26H1 | Win10 21H2+ |
| CPU | Intel® Core™ Ultra 9 285K (3.70 GHz) | 64 bit |
| GPU | NVIDIA GeForce RTX 3090 24 GB | GTX 30 系列+ |
| 显卡驱动 及 CUDA 版本 | 595.02 / CUDA 13.1 | ≥ 12.6 |
| Python | 3.12.11 64-bit | 3.10-3.12 |
| PyTorch | 2.7.1+cu126 | 2.5.0+cu118+ |
| VS Build Tools | 17.12 / MSVC 14.44 | 2019/2022 任意 |
⚠️ 编译终端:
开始菜单搜索 “x64 Native Tools Command Prompt for VS 2022” → 右键 以管理员身份运行
(自带 cl.exe/nvcc 环境变量)
四、一键脚本(复现参考)
# 1. 打开 VS2022 x64 终端 → 激活虚拟环境
cd /d H:\PythonProjects1\Win_ComfyUI
.\.venv\Scripts\activate
# 2. 进入 rasterizer 目录
cd custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer
# 3. 备份原 setup.py(可选)
copy setup.py setup.py.bak
# 4. 应用 Monkey-Patch(内容见第五节)
python setup_patch.py bdist_wheel
# 5. 安装生成的 wheel
pip install dist\custom_rasterizer-0.1.0+torch271.cuda126-cp312-cp312-win_amd64.whl
# 6. 重启 ComfyUI
# 日志出现 “Hunyuan3DWrapper: custom rasterizer loaded” 即成功
五、Monkey-Patch 细节(核心)
在 setup.py 最顶部增加两行即可绕过版本检查:
import torch.utils.cpp_extension as _ext
_ext._check_cuda_version = lambda *args, **kwargs: None
完整 setup_patch.py ,也可直接复制并替换:
from setuptools import setup, find_packages
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
import torch
# ===== 绕过 CUDA 驱动版本检查 =====
import torch.utils.cpp_extension as _ext
_ext._check_cuda_version = lambda *args, **kwargs: None
# ===================================
version = "0.1.0" # 写死版本号,不再计算
custom_rasterizer_module = CUDAExtension(
'custom_rasterizer_kernel',
[
'lib/custom_rasterizer_kernel/rasterizer.cpp',
'lib/custom_rasterizer_kernel/grid_neighbor.cpp',
'lib/custom_rasterizer_kernel/rasterizer_gpu.cu',
]
)
setup(
packages=find_packages(),
version=version,
name='custom_rasterizer',
include_package_data=True,
package_dir={'': '.'},
ext_modules=[custom_rasterizer_module],
cmdclass={'build_ext': BuildExtension}
)
六、成功标志
运行 python setup.py bdist_wheel 命令:
这是我在x64 Native Tools Command Prompt for VS 2022中激活环境并进入相应路径后的运行结果的部分日志:
MSVC/cl.exe with traditional preprocessor is used. This may lead to unexpected compilation errors. Please switch to the standard conforming preprocessor by passing `/Zc:preprocessor` to cl.exe. You can define CCCL_IGNORE_MSVC_TRADITIONAL_PREPROCESSOR_WARNING to suppress this warning.
H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\lib\custom_rasterizer_kernel\rasterizer_gpu.cu(57): warning #186-D: pointless comparison of unsigned integer with zero
if (f >= 0) {
^
Remark: The warnings can be suppressed with "-diag-suppress <warning-number>"
rasterizer_gpu.cu
tmpxft_00002ba0_00000000-7_rasterizer_gpu.cudafe1.cpp
"D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:H:\PythonProjects1\Win_ComfyUI\.venv\Lib\site-packages\torch\lib "/LIBPATH:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\lib\x64" /LIBPATH:H:\PythonProjects1\Win_ComfyUI\.venv\libs /LIBPATH:C:\Users\love\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\libs /LIBPATH:C:\Users\love\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none /LIBPATH:H:\PythonProjects1\Win_ComfyUI\.venv\PCbuild\amd64 "/LIBPATH:D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\ATLMFC\lib\x64" "/LIBPATH:D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.26100.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.26100.0\\um\x64" c10.lib torch.lib torch_cpu.lib torch_python.lib cudart.lib c10_cuda.lib torch_cuda.lib /EXPORT:PyInit_custom_rasterizer_kernel H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\build\temp.win-amd64-cpython-312\Release\lib\custom_rasterizer_kernel\grid_neighbor.obj H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\build\temp.win-amd64-cpython-312\Release\lib\custom_rasterizer_kernel\rasterizer.obj H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\build\temp.win-amd64-cpython-312\Release\lib\custom_rasterizer_kernel\rasterizer_gpu.obj /OUT:build\lib.win-amd64-cpython-312\custom_rasterizer_kernel.cp312-win_amd64.pyd /IMPLIB:H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\build\temp.win-amd64-cpython-312\Release\lib\custom_rasterizer_kernel\custom_rasterizer_kernel.cp312-win_amd64.lib
正在创建库 H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\build\temp.win-amd64-cpython-312\Release\lib\custom_rasterizer_kernel\custom_rasterizer_kernel.cp312-win_amd64.lib 和对象 H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\build\temp.win-amd64-cpython-312\Release\lib\custom_rasterizer_kernel\custom_rasterizer_kernel.cp312-win_amd64.exp
正在生成代码
已完成代码的生成
H:\PythonProjects1\Win_ComfyUI\.venv\Lib\site-packages\setuptools\_distutils\cmd.py:90: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` directly.
Instead, use pypa/build, pypa/installer or other
standards-based tools.
See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
********************************************************************************
!!
self.initialize_options()
installing to build\bdist.win-amd64\wheel
running install
running install_lib
creating build\bdist.win-amd64\wheel
creating build\bdist.win-amd64\wheel\custom_rasterizer
copying build\lib.win-amd64-cpython-312\custom_rasterizer\io_glb.py -> build\bdist.win-amd64\wheel\.\custom_rasterizer
copying build\lib.win-amd64-cpython-312\custom_rasterizer\io_obj.py -> build\bdist.win-amd64\wheel\.\custom_rasterizer
copying build\lib.win-amd64-cpython-312\custom_rasterizer\render.py -> build\bdist.win-amd64\wheel\.\custom_rasterizer
copying build\lib.win-amd64-cpython-312\custom_rasterizer\__init__.py -> build\bdist.win-amd64\wheel\.\custom_rasterizer
copying build\lib.win-amd64-cpython-312\custom_rasterizer_kernel.cp312-win_amd64.pyd -> build\bdist.win-amd64\wheel\.
running install_egg_info
Copying custom_rasterizer.egg-info to build\bdist.win-amd64\wheel\.\custom_rasterizer-0.1.0-py3.12.egg-info
running install_scripts
H:\PythonProjects1\Win_ComfyUI\.venv\Lib\site-packages\setuptools\command\bdist_wheel.py:103: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
if get_flag("Py_DEBUG", hasattr(sys, "gettotalrefcount"), warn=(impl == "cp")):
creating build\bdist.win-amd64\wheel\custom_rasterizer-0.1.0.dist-info\WHEEL
creating 'dist\custom_rasterizer-0.1.0-cp312-cp312-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'custom_rasterizer_kernel.cp312-win_amd64.pyd'
adding 'custom_rasterizer/__init__.py'
adding 'custom_rasterizer/io_glb.py'
adding 'custom_rasterizer/io_obj.py'
adding 'custom_rasterizer/render.py'
adding 'custom_rasterizer-0.1.0.dist-info/METADATA'
adding 'custom_rasterizer-0.1.0.dist-info/WHEEL'
adding 'custom_rasterizer-0.1.0.dist-info/top_level.txt'
adding 'custom_rasterizer-0.1.0.dist-info/RECORD'
removing build\bdist.win-amd64\wheel
(Win_ComfyUI) H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer>
1. 编译日志末尾出现:
creating 'dist\custom_rasterizer-0.1.0+torch271.cuda126-cp312-cp312-win_amd64.whl'
2. 安装编译的 whl 文件:
pip install H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\dist\custom_rasterizer-0.1.0+torch271.cuda126-cp312-cp312-win_amd64.whl
3. 控制台打印:
(Win_ComfyUI) H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer>pip install H:\PythonProjects1\Win_ComfyUI\custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer\dist\custom_rasterizer-0.1.0+torch271.cuda126-cp312-cp312-win_amd64.whl
Looking in indexes: https://pypi/simple, https://pypi.ngc.nvidia
Processing h:\pythonprojects1\win_comfyui\custom_nodes\comfyui-hunyuan3dwrapper\hy3dgen\texgen\custom_rasterizer\dist\custom_rasterizer-0.1.0+torch271.cuda126-cp312-cp312-win_amd64.whl
Requirement already satisfied: torch>=2.0.0 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from custom-rasterizer==0.1.0+torch271.cuda126) (2.7.1+cu126)
Requirement already satisfied: numpy>=1.20.0 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from custom-rasterizer==0.1.0+torch271.cuda126) (1.26.4)
Requirement already satisfied: filelock in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (3.17.0)
Requirement already satisfied: typing-extensions>=4.10.0 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (4.15.0)
Requirement already satisfied: sympy>=1.13.3 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (1.14.0)
Requirement already satisfied: networkx in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (3.5)
Requirement already satisfied: jinja2 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (3.1.6)
Requirement already satisfied: fsspec in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (2025.9.0)
Requirement already satisfied: setuptools in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (79.0.1)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from sympy>=1.13.3->torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (1.3.0)
Requirement already satisfied: MarkupSafe>=2.0 in h:\pythonprojects1\win_comfyui\.venv\lib\site-packages (from jinja2->torch>=2.0.0->custom-rasterizer==0.1.0+torch271.cuda126) (2.1.5)
Installing collected packages: custom-rasterizer
Successfully installed custom-rasterizer-0.1.0+torch271.cuda126
七、常见坑 & 快速排雷
现象 原因 一键修复
cl.exe not found 未使用 VS2022 x64 终端 见「三」
CUDA 13.x vs PyTorch 12.x 报错 Torch 内部检查 本文化解
nvcc fatal : Unsupported gpu architecture 'compute_90' CUDA 13 默认架构过高 在 setup.py 追加 extra_compile_args=['-gencode=arch=compute_86,code=sm_86'](RTX30 系列)
无声视频 Whisper 无输出 素材无音轨 换带声音视频
八、性能 & 体验
- 编译耗时:≈ 40 s(RTX 3090 + NVMe)
- 显存占用:+1.2 GB(网格渲染时)
- 生成速度:3 s/帧(512×512 网格)
九、参考 & 致谢
-
Hunyuan3D 官方仓库:https://github/Tencent/Hunyuan3D
-
ComfyUI-Hunyuan3DWrapper:https://github/kijai/ComfyUI-Hunyuan3DWrapper
-
PyTorch cpp_extension 文档:https://pytorch/docs/stable/cpp_extension.html
-
本博客脚本 Gist:https://gist.github/yourgist/setup_patch.py
(如链接失效请留言)
十、标签
ComfyUI, Hunyuan3D, CUDA13.1, PyTorch, 自定义光栅化器, Windows11, RTX3090, 编译报错, MonkeyPatch, 3D生成
十一、一键命令(自用回顾)
# 在当前窗口打开 x64 Native Tools Command Prompt for VS 2022 命令行工具
"D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
# Win11 + RTX 3090 + CUDA 13.1 一键编译 Hunyuan3D custom_rasterizer
cd /d H:\PythonProjects1\Win_ComfyUI
.\.venv\Scripts\activate
cd custom_nodes\ComfyUI-Hunyuan3DWrapper\hy3dgen\texgen\custom_rasterizer
python setup_patch.py bdist_wheel
pip install dist\custom_rasterizer-0.1.0+torch271.cuda126-cp312-cp312-win_amd64.whl
# 重启 ComfyUI → 节点可用
版权声明:本文标题:Win11 + RTX 3090 亲测:ComfyUI Hunyuan3D 自定义光栅化器编译全记录(CUDA 13.1 vs PyTorch 12.6 完美绕过) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1767925991a3518607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论