NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.43k stars 158 forks source link

Error building extension 'nvdiffrast_plugin': ninja: error: loading 'build.ninja' on Windows10 #111

Closed voruin closed 1 year ago

voruin commented 1 year ago

Hello, I got the error during building extension 'nvdiffrast_plugin'. I struggled for hours and still haven't fixed it.

Traceback (most recent call last):
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1900, in _run_ninja_build
    subprocess.run(
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Voruin\test_dream\main.py", line 149, in <module>
    trainer.save_mesh()
  File "C:\Users\Voruin\test_dream\nerf\utils.py", line 506, in save_mesh
    self.model.export_mesh(save_path, resolution=self.opt.mcubes_resolution, decimate_target=self.opt.decimate_target)
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\Voruin\test_dream\nerf\renderer.py", line 362, in export_mesh
    _export(v, f)
  File "C:\Users\Voruin\test_dream\nerf\renderer.py", line 270, in _export
    glctx = dr.RasterizeCudaContext()
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\nvdiffrast\torch\ops.py", line 177, in __init__
    self.cpp_wrapper = _get_plugin().RasterizeCRStateWrapper(cuda_device_idx)
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\nvdiffrast\torch\ops.py", line 118, in _get_plugin
    torch.utils.cpp_extension.load(name=plugin_name, sources=source_paths, extra_cflags=opts, extra_cuda_cflags=opts+['-lineinfo'], extra_ldflags=ldflags, with_cuda=True, verbose=False)
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1284, in load
    return _jit_compile(
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1508, in _jit_compile
    _write_ninja_file_and_build_library(
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1623, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1916, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error building extension 'nvdiffrast_plugin': ninja: error: loading 'build.ninja': 系统找不到指定的路径。
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_19:00:59_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 526.98       Driver Version: 526.98       CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ... WDDM  | 00000000:01:00.0  On |                  N/A |
| 23%   26C    P8    12W / 250W |    687MiB / 11264MiB |      5%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      3940    C+G   ...me\Application\chrome.exe    N/A      |
|    0   N/A  N/A      4552    C+G   ...e\PhoneExperienceHost.exe    N/A      |
|    0   N/A  N/A      5856    C+G   ...8wekyb3d8bbwe\Cortana.exe    N/A      |
|    0   N/A  N/A      8072    C+G   ...batNotificationClient.exe    N/A      |
|    0   N/A  N/A     15884    C+G   ...\app-1.0.9011\Discord.exe    N/A      |
|    0   N/A  N/A     18988    C+G   ...obeNotificationClient.exe    N/A      |
|    0   N/A  N/A     21336    C+G   ...ter\ThermalController.exe    N/A      |
|    0   N/A  N/A     21396    C+G   ...lPanel\SystemSettings.exe    N/A      |
|    0   N/A  N/A     22628    C+G   ...icrosoft VS Code\Code.exe    N/A      |
|    0   N/A  N/A     26108    C+G   ...kyb3d8bbwe\HxAccounts.exe    N/A      |
|    0   N/A  N/A     26428    C+G   ...5n1h2txyewy\SearchApp.exe    N/A      |
|    0   N/A  N/A     26460    C+G   ...ekyb3d8bbwe\HxOutlook.exe    N/A      |
|    0   N/A  N/A     27344    C+G   ...y\ShellExperienceHost.exe    N/A      |
|    0   N/A  N/A     27436    C+G   ...reMobileConnectClient.exe    N/A      |
|    0   N/A  N/A     32420    C+G   ...onnectUniversalClient.exe    N/A      |
|    0   N/A  N/A     32456    C+G   ... Host\Razer Synapse 3.exe    N/A      |
|    0   N/A  N/A     32928    C+G   ...artMenuExperienceHost.exe    N/A      |
|    0   N/A  N/A     33740    C+G   ...oft\OneDrive\OneDrive.exe    N/A      |
|    0   N/A  N/A     34040    C+G   ...arp.BrowserSubprocess.exe    N/A      |
|    0   N/A  N/A     34736    C+G   ...cw5n1h2txyewy\LockApp.exe    N/A      |
|    0   N/A  N/A     35924    C+G   ...2txyewy\TextInputHost.exe    N/A      |
|    0   N/A  N/A     36232    C+G   C:\Windows\explorer.exe         N/A      |
+-----------------------------------------------------------------------------+

And here is the output when I run pip list:

Package                 Version
----------------------- ------------
absl-py                 1.4.0
accelerate              0.17.1
cachetools              5.3.0
certifi                 2022.12.7
charset-normalizer      3.1.0
clip                    1.0
colorama                0.4.6
contourpy               1.0.7
cycler                  0.11.0
dearpygui               1.8.0
diffusers               0.14.0
einops                  0.6.0
filelock                3.10.0
fonttools               4.39.2
freqencoder             0.0.0
ftfy                    6.1.1
google-auth             2.16.2
google-auth-oauthlib    0.4.6
gridencoder             0.0.0
grpcio                  1.51.3
huggingface-hub         0.13.3
idna                    3.4
imageio                 2.26.1
imageio-ffmpeg          0.4.8
importlib-metadata      6.1.0
joblib                  1.2.0
kiwisolver              1.4.4
Markdown                3.4.1
markdown-it-py          2.2.0
MarkupSafe              2.1.2
matplotlib              3.7.1
mdurl                   0.1.2
ninja                   1.11.1
numpy                   1.24.2
nvdiffrast              0.3.0
oauthlib                3.2.2
opencv-python           4.7.0.72
packaging               23.0
pandas                  1.5.3
Pillow                  9.4.0
pip                     23.0.1
protobuf                3.20.3
psutil                  5.9.4
pyasn1                  0.4.8
pyasn1-modules          0.2.8
Pygments                2.14.0
PyMCubes                0.1.4
pymeshlab               2022.2.post3
pyparsing               3.0.9
python-dateutil         2.8.2
pytz                    2022.7.1
PyYAML                  6.0
raymarching             0.0.0
regex                   2022.10.31
requests                2.28.2
requests-oauthlib       1.3.1
rich                    13.3.2
rsa                     4.9
scikit-learn            1.2.2
scipy                   1.10.1
setuptools              65.5.0
shencoder               0.0.0
six                     1.16.0
tensorboard             2.12.0
tensorboard-data-server 0.7.0
tensorboard-plugin-wit  1.8.1
tensorboardX            2.6
threadpoolctl           3.1.0
tinycudann              1.7
tokenizers              0.13.2
torch                   1.13.1+cu117
torch-ema               0.3
torchaudio              0.13.1+cu117
torchvision             0.14.1+cu117
tqdm                    4.65.0
transformers            4.27.2
trimesh                 3.20.2
typing_extensions       4.5.0
urllib3                 1.26.15
wcwidth                 0.2.6
Werkzeug                2.2.3
wheel                   0.40.0
xatlas                  0.0.7
zipp                    3.15.0

I also looked up your answers to similar questions and change the code torch.utils.cpp_extension.load(name=plugin_name, sources=source_paths, extra_cflags=opts, extra_cuda_cflags=opts+['-lineinfo'], extra_ldflags=ldflags, with_cuda=True, verbose=False) to ..., verbose=True)in nvdiffrast\torch\ops.py, and the errors are:

Using C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117 as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117\nvdiffrast_plugin\build.ninja...
Building extension module nvdiffrast_plugin...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
ninja: error: loading 'build.ninja': 系统找不到指定的路径。

Traceback (most recent call last):
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1900, in _run_ninja_build
    subprocess.run(
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Voruin\test_dream\main.py", line 149, in <module>
    trainer.save_mesh()
  File "C:\Users\Voruin\test_dream\nerf\utils.py", line 506, in save_mesh
    self.model.export_mesh(save_path, resolution=self.opt.mcubes_resolution, decimate_target=self.opt.decimate_target)
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\Voruin\test_dream\nerf\renderer.py", line 362, in export_mesh
    _export(v, f)
  File "C:\Users\Voruin\test_dream\nerf\renderer.py", line 270, in _export
    glctx = dr.RasterizeCudaContext()
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\nvdiffrast\torch\ops.py", line 177, in __init__
    self.cpp_wrapper = _get_plugin().RasterizeCRStateWrapper(cuda_device_idx)
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\nvdiffrast\torch\ops.py", line 118, in _get_plugin
    torch.utils.cpp_extension.load(name=plugin_name, sources=source_paths, extra_cflags=opts, extra_cuda_cflags=opts+['-lineinfo'], extra_ldflags=ldflags, with_cuda=True, verbose=True)
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1284, in load
    return _jit_compile(
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1508, in _jit_compile
    _write_ninja_file_and_build_library(
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1623, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch\utils\cpp_extension.py", line 1916, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error building extension 'nvdiffrast_plugin'

I also did not see nvdiffrast_plugin folder under C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117. I don't know why. Also don't know why ninja is giving me garbled errors

Can anyone help me out? Thanks a lot!!!

Best,

s-laine commented 1 year ago

Something seems to go wrong when the build file is being written, given that the log says Emitting ninja build file C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117\nvdiffrast_plugin\build.ninja... but you cannot see the file, or even the folder.

Could this be a permission issue, i.e., the process cannot write the file (or create the folder) in your AppData directory for some reason? The PyTorch installation you use also looks nonstandard, as it is located under your project directory (C:\Users\Voruin\test_dream\dreamfusion\lib\site-packages\torch) according to the traceback. I haven't seen this kind of installation before — maybe you have multiple versions of PyTorch on your system that are somehow clashing?

To debug this further, you could find where the log line about emitting the ninja build file is printed, and insert additional prints to indicate where the file actually goes or if any errors occur.

The garbled error message is a bug in ninja. I'd guess the error is that the file is not found.

voruin commented 1 year ago

Thanks for replying!

The weird PyTorch installation location is because I used py -m venv dreamfusion .\dreamfusion\scripts\activate and created a virtual environment. Will this matter?

Anyway, I tried running without virtual environment, also tried running as administrator in cmd or PowerShell, but still get the same error:

Using C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117 as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117\nvdiffrast_plugin\build.ninja...
Building extension module nvdiffrast_plugin...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
ninja: error: loading 'build.ninja': 系统找不到指定的路径。

Traceback (most recent call last):
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\utils\cpp_extension.py", line 1894, in _run_ninja_build
    subprocess.run(
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Voruin\stable-dreamfusion\main.py", line 149, in <module>
    trainer.save_mesh()
  File "C:\Users\Voruin\stable-dreamfusion\nerf\utils.py", line 506, in save_mesh
    self.model.export_mesh(save_path, resolution=self.opt.mcubes_resolution, decimate_target=self.opt.decimate_target)
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\Voruin\stable-dreamfusion\nerf\renderer.py", line 362, in export_mesh
    _export(v, f)
  File "C:\Users\Voruin\stable-dreamfusion\nerf\renderer.py", line 270, in _export
    glctx = dr.RasterizeCudaContext()
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nvdiffrast\torch\ops.py", line 177, in __init__
    self.cpp_wrapper = _get_plugin().RasterizeCRStateWrapper(cuda_device_idx)
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nvdiffrast\torch\ops.py", line 118, in _get_plugin
    torch.utils.cpp_extension.load(name=plugin_name, sources=source_paths, extra_cflags=opts, extra_cuda_cflags=opts+['-lineinfo'], extra_ldflags=ldflags, with_cuda=True, verbose=True)
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\utils\cpp_extension.py", line 1284, in load
    return _jit_compile(
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\utils\cpp_extension.py", line 1509, in _jit_compile
    _write_ninja_file_and_build_library(
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\utils\cpp_extension.py", line 1624, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\utils\cpp_extension.py", line 1910, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error building extension 'nvdiffrast_plugin'

I've put the path containing ninja.exe into the environment variable and have no idea why this problem keeps appearing.

I just tried manually creating the nvdiffrast_plugin folder under C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117\ and copied the ninja package into the folder directly and it gave me a new error module 'nvdiffrast_plugin' has no attribute 'RasterizeCRStateWrapper'. Did you mean: 'RasterizeGLStateWrapper'?: Guess that nvdiffrast_plugin was not successfully built by doing so. But after running this, it generates a build folder with files under nvdiffrast_plugin. So maybe it's not the permission issue?

Using C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117 as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file C:\Users\Voruin\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu117\nvdiffrast_plugin\build.ninja...
Building extension module nvdiffrast_plugin...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\debug_flags.cc /Fobuild\debug_flags.obj /Fdbuild\ninja.pdb
[2/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\edit_distance.cc /Fobuild\edit_distance.obj /Fdbuild\ninja.pdb
[3/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\depfile_parser.cc /Fobuild\depfile_parser.obj /Fdbuild\ninja.pdb
[4/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\eval_env.cc /Fobuild\eval_env.obj /Fdbuild\ninja.pdb
[5/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\graphviz.cc /Fobuild\graphviz.obj /Fdbuild\ninja.pdb
[6/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\clparser.cc /Fobuild\clparser.obj /Fdbuild\ninja.pdb
[7/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\deps_log.cc /Fobuild\deps_log.obj /Fdbuild\ninja.pdb
[8/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\dyndep.cc /Fobuild\dyndep.obj /Fdbuild\ninja.pdb
[9/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\build_log.cc /Fobuild\build_log.obj /Fdbuild\ninja.pdb
[10/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\graph.cc /Fobuild\graph.obj /Fdbuild\ninja.pdb
[11/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\dyndep_parser.cc /Fobuild\dyndep_parser.obj /Fdbuild\ninja.pdb
[12/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\json.cc /Fobuild\json.obj /Fdbuild\ninja.pdb
[13/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\clean.cc /Fobuild\clean.obj /Fdbuild\ninja.pdb
[14/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\lexer.cc /Fobuild\lexer.obj /Fdbuild\ninja.pdb
[15/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\parser.cc /Fobuild\parser.obj /Fdbuild\ninja.pdb
[16/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\version.cc /Fobuild\version.obj /Fdbuild\ninja.pdb
[17/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\string_piece_util.cc /Fobuild\string_piece_util.obj /Fdbuild\ninja.pdb
[18/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\manifest_parser.cc /Fobuild\manifest_parser.obj /Fdbuild\ninja.pdb
[19/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\status.cc /Fobuild\status.obj /Fdbuild\ninja.pdb
[20/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\state.cc /Fobuild\state.obj /Fdbuild\ninja.pdb
[21/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\getopt.c /Fobuild\getopt.obj /Fdbuild\
[22/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\missing_deps.cc /Fobuild\missing_deps.obj /Fdbuild\ninja.pdb
[23/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\msvc_helper-win32.cc /Fobuild\msvc_helper-win32.obj /Fdbuild\ninja.pdb
[24/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\metrics.cc /Fobuild\metrics.obj /Fdbuild\ninja.pdb
[25/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\line_printer.cc /Fobuild\line_printer.obj /Fdbuild\ninja.pdb
[26/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\msvc_helper_main-win32.cc /Fobuild\msvc_helper_main-win32.obj /Fdbuild\ninja.pdb
[27/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\includes_normalize-win32.cc /Fobuild\includes_normalize-win32.obj /Fdbuild\ninja.pdb
[28/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\subprocess-win32.cc /Fobuild\subprocess-win32.obj /Fdbuild\ninja.pdb
[29/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\util.cc /Fobuild\util.obj /Fdbuild\ninja.pdb
[30/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\disk_interface.cc /Fobuild\disk_interface.obj /Fdbuild\ninja.pdb
[31/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\minidump-win32.cc /Fobuild\minidump-win32.obj /Fdbuild\ninja.pdb
[32/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\build.cc /Fobuild\build.obj /Fdbuild\ninja.pdb
[33/35] cl /showIncludes /nologo /Zi /W4 /WX /wd4530 /wd4100 /wd4706 /wd4244 /wd4512 /wd4800 /wd4702 /wd4819 /wd4127 /wd4355 /wd4091 /GR- /wd4267 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_HAS_EXCEPTIONS=0 /DNINJA_PYTHON="python.exe" /FS /Ox /DNDEBUG /GL -I. -c src\ninja.cc /Fobuild\ninja.obj /Fdbuild\ninja.pdb
[34/35] lib /nologo /ltcg /out:build\ninja.lib build\build.obj build\build_log.obj build\clean.obj build\clparser.obj build\debug_flags.obj build\depfile_parser.obj build\deps_log.obj build\disk_interface.obj build\dyndep.obj build\dyndep_parser.obj build\edit_distance.obj build\eval_env.obj build\graph.obj build\graphviz.obj build\json.obj build\lexer.obj build\line_printer.obj build\manifest_parser.obj build\metrics.obj build\missing_deps.obj build\parser.obj build\state.obj build\status.obj build\string_piece_util.obj build\util.obj build\version.obj build\subprocess-win32.obj build\includes_normalize-win32.obj build\msvc_helper-win32.obj build\msvc_helper_main-win32.obj build\minidump-win32.obj build\getopt.obj
[35/35] cl build\ninja.obj ninja.lib /nologo /link /DEBUG /libpath:build /LTCG /OPT:REF /OPT:ICF /out:ninja.exe
Generating code
Finished generating code
Loading extension module nvdiffrast_plugin...
Traceback (most recent call last):
  File "C:\Users\Voruin\testagain\main.py", line 149, in <module>
    trainer.save_mesh()
  File "C:\Users\Voruin\testagain\nerf\utils.py", line 506, in save_mesh
    self.model.export_mesh(save_path, resolution=self.opt.mcubes_resolution, decimate_target=self.opt.decimate_target)
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\Voruin\testagain\nerf\renderer.py", line 362, in export_mesh
    _export(v, f)
  File "C:\Users\Voruin\testagain\nerf\renderer.py", line 270, in _export
    glctx = dr.RasterizeCudaContext()
  File "C:\Users\Voruin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nvdiffrast\torch\ops.py", line 177, in __init__
    self.cpp_wrapper = _get_plugin().RasterizeCRStateWrapper(cuda_device_idx)
AttributeError: module 'nvdiffrast_plugin' has no attribute 'RasterizeCRStateWrapper'. Did you mean: 'RasterizeGLStateWrapper'?

What I am doing is trying to run Stable Dreamfusion, when call python main.py --workspace trial -O --test --save_mesh it will import nvdiffrast.torch in the process. There is no code calling ninja directly in the source code, so I am not sure where the log line about emitting the ninja build file is printed. I can only find the part using nvdiffrast, which is located at ./nerf/renderer.py. Is this the part that cause the error? How to further find out what the problem is? Sorry, I'm new to it. I really appreciate your help.

## stable-dreamfusion/nerf/renderer.py: 241-276

# unwrap uvs
            import xatlas
            import nvdiffrast.torch as dr
            from sklearn.neighbors import NearestNeighbors
            from scipy.ndimage import binary_dilation, binary_erosion

            atlas = xatlas.Atlas()
            atlas.add_mesh(v_np, f_np)
            chart_options = xatlas.ChartOptions()
            chart_options.max_iterations = 4 # for faster unwrap...
            atlas.generate(chart_options=chart_options)
            vmapping, ft_np, vt_np = atlas[0] # [N], [M, 3], [N, 2]

            # vmapping, ft_np, vt_np = xatlas.parametrize(v_np, f_np) # [N], [M, 3], [N, 2]

            vt = torch.from_numpy(vt_np.astype(np.float32)).float().to(device)
            ft = torch.from_numpy(ft_np.astype(np.int64)).int().to(device)

            # render uv maps
            uv = vt * 2.0 - 1.0 # uvs to range [-1, 1]
            uv = torch.cat((uv, torch.zeros_like(uv[..., :1]), torch.ones_like(uv[..., :1])), dim=-1) # [N, 4]

            if ssaa > 1:
                h = int(h0 * ssaa)
                w = int(w0 * ssaa)
            else:
                h, w = h0, w0

            if h <= 2048 and w <= 2048:
                glctx = dr.RasterizeCudaContext()
            else:
                glctx = dr.RasterizeGLContext()

            rast, _ = dr.rasterize(glctx, uv.unsqueeze(0), ft, (h, w)) # [1, h, w, 4]
            xyzs, _ = dr.interpolate(v.unsqueeze(0), rast, f) # [1, h, w, 3]
            mask, _ = dr.interpolate(torch.ones_like(v[:, :1]).unsqueeze(0), rast, f) # [1, h, w, 1]
s-laine commented 1 year ago

This error: module 'nvdiffrast_plugin' has no attribute 'RasterizeCRStateWrapper'. Did you mean: 'RasterizeGLStateWrapper'? is interesting. The RasterizeCRStateWrapper class was added in the C++ extension in nvdiffrast v0.3.0, and the older RasterizeGLStateWrapper was moved into a separate C++ extension named nvdiffrast_plugin_gl.

So in short, the error message suggests that the python side is from nvdiffrast v0.3.0, whereas the C++ extension is from nvdiffrast v0.2.8 or older. I don't know how this could happen.

What do you mean by "copied the ninja package into the folder directly"? Does the dreamfusion codebase come with a pre-compiled version of the nvdiffrast extension plugin? The compilation log looks like it's compiling ninja itself, not the nvdiffrast extension plugin, yet it somehow finds the RasterizeGLStateWrapper somewhere in there. I'm thoroughly confused by all of this.

I haven't personally used virtual environments, and I don't know if the extension compilation mechanism could somehow be confused by it. On the other hand, nvdiffrast uses PyTorch's standard torch.utils.cpp_extension.load() to compile and load the extension, and if using a virtual environment broke that, it would break a lot of other projects too.

voruin commented 1 year ago

I reinstalled many packages including cuda toolkit. I also ran Visual C++ Redistributable, installed MinGW, rebuild a virtual environment and installed all requirements again. It finally works. Don't know which step changed this. I think it should not be the nvdiffrast's problem, because it gave similar error when runing other projects which wants to build a plugin at the same place. Thank you very much for your patient reply!

s-laine commented 1 year ago

Glad to hear you got it working!