Win11+RTX3090 亲测 · ComfyUI Hunyuan3D 全程实录 ③:diso 源码编译实战(CUDA 13.1 零降级)
环境:Windows 11 23H2 | Intel Ultra 9 285K | RTX 3090 24 GB | CUDA 13.1 | Python 3.12.11 | PyTorch 2.7.1+cu126 | VS2022 17.12
系列:全程实录第 ③ 篇(第 ② 篇见nvdiffrast 编译实战)
一、前言:diso 作用与编译必要性

diso(Differentiable Iso-Surface Extraction)为 Hunyuan3DWrapper 提供 可微等值面提取 能力,
PyPI 无 Windows wheel ,必须本地编译 _C.pyd 才能启用 Quad Remesh / Fast Decimation 节点。
本文继续 零降级 CUDA 驱动 ,不改 PyTorch 版本,一次生成可用 wheel。
二、环境 checklist(与第 ② 篇一致)
| 项目 | 本机示例 | 最低要求 |
|---|---|---|
| OS | Windows 11 23H2 | Win10 21H2+ |
| GPU | RTX 3090 24 GB | Compute Capability ≥ 8.6 |
| 驱动 | 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" → 右键 以管理员身份运行
三、直接安装 vs 本地编译 对比
| 方式 | 命令 | 结果 | 本机日志片段 |
|---|---|---|---|
| 直接 pip | pip install diso |
❌ CUDA 版本检查失败 | RuntimeError: CUDA version (13.1) mismatches PyTorch (12.6) |
| 本地编译 | python setup_patch.py bdist_wheel |
✅ 生成可用 wheel | creating 'dist\diso-0.1.4-cp312-cp312-win_amd64.whl' |
下文全程基于 第二种。
四、一键脚本(失败→成功全流程)
保存为 build_diso.bat,在"x64 Native Tools Command Prompt for VS 2022"中运行:
bat
@echo off
title diso-Windows-Build
cd /d "%~dp0"
call .venv\Scripts\activate
echo [1/4] 克隆源码...
git clone https://github.com/SarahWeiii/diso.git
cd diso
echo [2/4] 应用 MonkeyPatch...
copy setup.py setup.py.bak
python -c "import torch.utils.cpp_extension as _ext;_ext._check_cuda_version=lambda *a,**k:None" setup.py bdist_wheel
echo [3/4] 安装 wheel...
pip install dist\diso-0.1.4-cp312-cp312-win_amd64.whl
echo [4/4] 验证...
python -c "import diso;print('✅',diso.__file__)"
pause
五、setup.py 修改细节(核心)
在 文件最顶部插入两行即可绕过版本检查:
python
# 跳过 CUDA 驱动版本检查(必须放最前)
import torch.utils.cpp_extension as _ext
_ext._check_cuda_version = lambda *args, **kwargs: None
完整 setup_patch.py(已含 RTX30 架构优化):
python
import glob
import os
import torch
from setuptools import find_packages, setup
from torch.utils.cpp_extension import (
CUDA_HOME,
BuildExtension,
CppExtension,
CUDAExtension,
)
# 1. 强制跳过 Torch 内部 CUDA 驱动版本检查
import torch.utils.cpp_extension as _ext
_ext._check_cuda_version = lambda *args, **kwargs: None
def get_extensions():
"""Refer to torchvision."""
main_file = [os.path.join("src", "pybind.cpp")]
source_cuda = glob.glob(os.path.join("src", "*.cu"))
sources = main_file
extension = CppExtension
define_macros = []
extra_compile_args = {}
if (torch.cuda.is_available() and (CUDA_HOME is not None)) or os.getenv(
"FORCE_CUDA", "0"
) == "1":
extension = CUDAExtension
sources += source_cuda
define_macros += [("WITH_CUDA", None)]
nvcc_flags = os.getenv("NVCC_FLAGS", "")
if nvcc_flags == "":
nvcc_flags = ["-O3"]
else:
nvcc_flags = nvcc_flags.split(" ")
extra_compile_args = {
"cxx": ["-O3"],
"nvcc": nvcc_flags,
}
sources = [s for s in sources]
include_dirs = ["src"]
print("sources:", sources)
ext_modules = [
extension(
"diso._C",
sources,
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
)
]
return ext_modules
setup(
name="diso",
version="0.1.4",
author_email="xiwei@ucsd.edu",
keywords="differentiable iso-surface extraction",
description="Differentiable Iso-Surface Extraction Package",
classifiers=[
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Other Audience",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"Framework :: Robot Framework :: Tool",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
],
license="CC BY-NC 4.0",
packages=find_packages(exclude=["tests"]),
python_requires=">=3.6",
install_requires=["trimesh"],
ext_modules=get_extensions(),
cmdclass={
"build_ext": BuildExtension.with_options(no_python_abi_suffix=True),
},
zip_safe=False
)
六、编译成功现场(日志片段)
[3/3] Linking build\lib.win-amd64-cpython-312\diso\_C.cp312-win_amd64.pyd
creating 'dist\diso-0.1.4-cp312-cp312-win_amd64.whl'
Successfully installed diso-0.1.4

七、安装与验证
bash
pip install dist\diso-0.1.4-cp312-cp312-win_amd64.whl
python -c "import diso; print('✅', diso.__file__)"

输出示例:
✅ H:\YourComfyUI\.venv\Lib\site-packages\diso\__init__.py

八、常见报错对照表(收藏级)
| 报错关键词 | 原因 | 一键修复 |
|---|---|---|
CUDA version (13.1) mismatches PyTorch (12.6) |
驱动 vs 编译版本检查 | 本文 MonkeyPatch |
cl.exe not found |
未用 VS2022 x64 终端 | 开始菜单 → x64 Native Tools |
MSVC/cl.exe with traditional preprocessor is used |
仅警告,可忽略 | 已加 /WX- 不视为错误 |
九、一键脚本(失败→成功全流程)
保存为 build_diso.bat,在"x64 Native Tools Command Prompt for VS 2022"中运行:
bat
@echo off
title diso-Windows-Build
cd /d "%~dp0"
call .venv\Scripts\activate
echo [1/4] 克隆源码...
git clone https://github.com/SarahWeiii/diso.git
cd diso
echo [2/4] 应用 MonkeyPatch...
copy setup.py setup.py.bak
python -c "import torch.utils.cpp_extension as _ext;_ext._check_cuda_version=lambda *a,**k:None" setup.py bdist_wheel
echo [3/4] 安装 wheel...
pip install dist\diso-0.1.4-cp312-cp312-win_amd64.whl
echo [4/4] 验证...
python -c "import diso;print('✅',diso.__file__)"
pause
十、系列交叉引用
- 第 0 篇(已发):自定义光栅化器编译全记录
- 第 ① 篇(已发):依赖安装完全指南
- 第 ② 篇(已发):nvdiffrast 编译实战
转载注明出处 → 博客标题 + 链接即可。
ComfyUI, Hunyuan3D, diso, CUDA13.1, PyTorch12.6, 源码编译, setup.py, MonkeyPatch, RTX3090, Windows11