news 2026/9/30 12:49:51

Win11+RTX3090 亲测 · ComfyUI Hunyuan3D 全程实录 ②:nvdiffrast 源码编译实战(CUDA 13.1 零降级)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Win11+RTX3090 亲测 · ComfyUI Hunyuan3D 全程实录 ②:nvdiffrast 源码编译实战(CUDA 13.1 零降级)

Win11+RTX3090 亲测 · ComfyUI Hunyuan3D 全程实录 ②:nvdiffrast 源码编译实战(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

nvdiffrast 是 NVIDIA 官方的高性能可微渲染库,PyPI 仅提供 Linux wheel,Windows 用户必须:

  1. 克隆源码
  2. 本地编译 CUDA 扩展_nvdiffrast_c.cp312-win_amd64.pyd

本文带你 零降级 CUDA 驱动,不改 PyTorch 版本,在 CUDA 13.1 + PyTorch 12.6 环境下一次编译通过。


二、环境 checklist

项目本机示例最低要求
OSWindows 11 专业工作站版 26H1Win10 21H2+
CPUIntel® Core™ Ultra 9 285K (3.70 GHz)64 bit
GPUNVIDIA GeForce RTX 3090 24 GBGTX 30 系列+
显卡驱动 及 CUDA 版本595.02 / CUDA 13.1≥ 12.6
Python3.12.11 64-bit3.10-3.12
PyTorch2.7.1+cu1262.5.0+cu118+
VS Build Tools17.12 / MSVC 14.442019/2022 任意

⚠️ 终端要求:开始菜单 → “x64 Native Tools Command Prompt for VS 2022” → 右键 以管理员身份运行(黑底黄字窗口才带 cl.exe/nvcc)


三、直接安装 vs 直接编译 vs 修改编译 对比

方式命令结果日志片段
直接 pippip install nvdiffrast❌ 无 Windows wheelERROR: Could not find a version that satisfies the requirement nvdiffrast
直接源码编译python setup.py bdist_wheel❌ CUDA 版本检查失败RuntimeError: CUDA version (13.1) mismatches PyTorch (12.6)
修改后编译python setup_patch.py bdist_wheel✅ 生成可用 wheelcreating 'dist\nvdiffrast-0.4.0-cp312-cp312-win_amd64.whl'

下文全程基于 第三种。



四、setup.py 修改细节(核心)

在 文件最顶部插入两行即可绕过版本检查:

# 跳过 CUDA 驱动版本检查(必须放最前)importtorch.utils.cpp_extensionas_ext _ext._check_cuda_version=lambda*args,**kwargs:None

完整setup_patch.py(已含 RTX30 架构优化):

# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.## NVIDIA CORPORATION and its licensors retain all intellectual property# and proprietary rights in and to this software, related documentation# and any modifications thereto. Any use, reproduction, disclosure or# distribution of this software and related documentation without an express# license agreement from NVIDIA CORPORATION is strictly prohibited.importsetuptoolsimportos# 1. 强制跳过 Torch 内部 CUDA 驱动版本检查importtorch.utils.cpp_extensionas_ext _ext._check_cuda_version=lambda*args,**kwargs:None# Print an error message if there's no PyTorch installed.try:fromtorch.utils.cpp_extensionimportBuildExtension,CUDAExtensionexceptImportError:print("\n\n"+"*"*70)print("ERROR! Cannot compile nvdiffrast CUDA extension. Please ensure that:\n")print("1. You have PyTorch installed")print("2. You run 'pip install' with --no-build-isolation flag")print("*"*70+"\n\n")exit(1)setuptools.setup(ext_modules=[CUDAExtension("_nvdiffrast_c",sources=["csrc/common/antialias.cu","csrc/common/common.cpp","csrc/common/cudaraster/impl/Buffer.cpp","csrc/common/cudaraster/impl/CudaRaster.cpp","csrc/common/cudaraster/impl/RasterImpl.cpp","csrc/common/cudaraster/impl/RasterImpl_kernel.cu","csrc/common/interpolate.cu","csrc/common/rasterize.cu","csrc/common/texture.cpp","csrc/common/texture_kernel.cu","csrc/torch/torch_antialias.cpp","csrc/torch/torch_bindings.cpp","csrc/torch/torch_interpolate.cpp","csrc/torch/torch_rasterize.cpp","csrc/torch/torch_texture.cpp",],extra_compile_args={"cxx":["-DNVDR_TORCH"]# Disable warnings in torch headers.+(["/wd4067","/wd4624","/wd4996"]ifos.name=="nt"else[]),"nvcc":["-DNVDR_TORCH","-lineinfo"],},)],cmdclass={"build_ext":BuildExtension},)

五、编译成功现场(日志截图)

# 运行编译命令 python setup.py bdist_wheel

[91/91] Linking build\lib.win-amd64-cpython-312\_nvdiffrast_c.cp312-win_amd64.pyd creating 'dist\nvdiffrast-0.4.0-cp312-cp312-win_amd64.whl' Successfully installed nvdiffrast-0.4.0

六、安装与验证

pipinstalldist\nvdiffrast-0.4.0-cp312-cp312-win_amd64.whl python -c"import nvdiffrast.torch as nvr; print('✅', nvr.__file__)"

输出示例:

✅ H:\YourComfyUI\.venv\Lib\site-packages\nvdiffrast\torch\__init__.py


七、常见报错对照表(收藏级)

报错关键词原因一键修复
-CUDA version (13.1) mismatches PyTorch (12.6)--驱动 vs 编译版本检查--本文 MonkeyPatch -
-cl.exe not found--未用 VS2022 x64 终端--开始菜单 → x64 Native Tools-
-nvcc fatal : Unsupported gpu architecture 'compute_90'--CUDA 13 默认架构过高--已在setup_patch.py指定compute_86-
-MSVC/cl.exe with traditional preprocessor is used--仅警告,可忽略--加/WX-不视为错误-


八、一键脚本(失败→成功全流程)

保存为build_nvdiffrast.bat,右键管理员运行“x64 Native Tools Command Prompt for VS 2022”然后运行此脚本即可复现全文所有步骤:

@echo off title nvdiffrast-Windows-Build cd /d "%~dp0" call .venv\Scripts\activate echo [1/4] 克隆源码... git clone https://github.com/NVlabs/nvdiffrast.git cd nvdiffrast 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\nvdiffrast-0.4.0-cp312-cp312-win_amd64.whl echo [4/4] 验证... python -c "import nvdiffrast.torch as nvr;print('✅',nvr.__file__)" pause

九、系列交叉引用

  • 第 0 篇(已发):自定义光栅化器编译全记录
  • 第 ① 篇(已发):依赖安装完全指南
  • 第 ③ 篇(明天发):diso 编译实战 + 节点验证 + WF 演示

转载注明出处 → 博客标题 + 链接即可。

ComfyUI, Hunyuan3D, nvdiffrast, CUDA13.1, PyTorch12.6, 源码编译, setup.py, MonkeyPatch, RTX3090, Windows11

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/29 17:49:20

如何用Open-AutoGLM实现零代码部署?这7个核心模块你必须掌握

第一章:Open-AutoGLM 部署流程简化Open-AutoGLM 作为新一代自动化语言模型部署框架,显著降低了从模型加载到服务上线的复杂度。其核心设计理念是“开箱即用”,通过标准化接口和模块化组件,使开发者能够快速完成本地或云端部署。环…

作者头像 李华
网站建设 2026/9/30 12:25:21

【Open-AutoGLM安装包压缩实战】:从2GB到50MB的极致瘦身秘籍

第一章:Open-AutoGLM安装包压缩背景与挑战在大规模语言模型快速发展的背景下,Open-AutoGLM作为一款开源自动化代码生成工具,其安装包体积的优化成为部署效率的关键瓶颈。随着模型参数量和依赖库的持续增长,原始安装包已超过数GB&a…

作者头像 李华
网站建设 2026/10/1 4:21:16

Open-AutoGLM成功率优化:5大关键统计模型深度解析

第一章:Open-AutoGLM 成功率统计算法 在自动化自然语言处理任务中,Open-AutoGLM 作为基于大语言模型的推理引擎,其执行成功率是衡量系统稳定性和智能决策能力的关键指标。为准确评估其在不同场景下的表现,需设计一套科学的概率统计…

作者头像 李华
网站建设 2026/9/30 20:20:45

Excalidraw用户行为分析数据收集方式

Excalidraw用户行为分析数据收集方式 在远程协作日益成为主流工作模式的今天,团队对可视化沟通工具的需求已从“能用”转向“好用”——不仅要支持快速表达想法,更要能理解用户的意图、适应协作节奏,甚至主动辅助创作。Excalidraw 正是在这一…

作者头像 李华
网站建设 2026/9/30 14:28:36

Excalidraw数据持久化机制揭秘

Excalidraw 数据持久化机制揭秘 在浏览器刷新的瞬间,你是否曾眼睁睁看着辛苦绘制的架构图消失无踪?这种“创作即毁灭”的体验,在早期在线绘图工具中屡见不鲜。而如今,Excalidraw 却能在页面重载后精准还原你半小时前的草稿——这背…

作者头像 李华
网站建设 2026/9/30 5:02:54

告别焦虑,你的毕业设计智能伙伴:百考通AI重塑高效科研路径

当毕业季的钟声悄然临近,毕业设计这份最后的“答卷”让无数学子在图书馆、实验室与宿舍间辗转反侧。选题迷茫、进度拖延、资料芜杂、格式规范繁琐……这些共同的“痛点”构成了毕业季的独特背景音。在数字化与智能化浪潮席卷各行各业的今天,我们是否能够…

作者头像 李华