TencentARC / InstantMesh

InstantMesh: Efficient 3D Mesh Generation from a Single Image with Sparse-view Large Reconstruction Models
Apache License 2.0
3.17k stars 332 forks source link

ImportError: DLL load failed while importing nvdiffrast_plugin: the specified module cannot be found #51

Open k1ckmefroml1f3 opened 5 months ago

k1ckmefroml1f3 commented 5 months ago

I keep getting this error but couldnt find any solutions, everything is in the place, maybe i should add something to env variables? Or install something so it will work

(instantmesh) C:\Users\k1ckm3\InstantMesh>python run.py configs/instant-mesh-large.yaml examples/ver.png --save_video --export_texmap Seed set to 42 Loading diffusion model ... Loading pipeline components...: 0%| | 0/8 [00:00<?, ?it/s]The config attributes {'dropout': 0.0, 'reverse_transformer_layers_per_block': None} were passed to UNet2DConditionModel, but are not expected and will be ignored. Please verify your config.json configuration file. Loading pipeline components...: 100%|█████████████████████████| 8/8 [00:06<00:00, 1.25it/s] Loading custom white-background unet ... Loading reconstruction model ... Some weights of ViTModel were not initialized from the model checkpoint at facebook/dino-vitb16 and are newly initialized: ['encoder.layer.11.adaLN_modulation.1.bias', 'encoder.layer.0.adaLN_modulation.1.bias', 'encoder.layer.4.adaLN_modulation.1.weight', 'encoder.layer.5.adaLN_modulation.1.bias', 'encoder.layer.2.adaLN_modulation.1.bias', 'encoder.layer.6.adaLN_modulation.1.bias', 'encoder.layer.9.adaLN_modulation.1.weight', 'encoder.layer.10.adaLN_modulation.1.weight', 'encoder.layer.3.adaLN_modulation.1.weight', 'encoder.layer.2.adaLN_modulation.1.weight', 'encoder.layer.1.adaLN_modulation.1.bias', 'encoder.layer.4.adaLN_modulation.1.bias', 'encoder.layer.1.adaLN_modulation.1.weight', 'encoder.layer.8.adaLN_modulation.1.bias', 'encoder.layer.5.adaLN_modulation.1.weight', 'encoder.layer.10.adaLN_modulation.1.bias', 'encoder.layer.9.adaLN_modulation.1.bias', 'encoder.layer.11.adaLN_modulation.1.weight', 'encoder.layer.8.adaLN_modulation.1.weight', 'encoder.layer.3.adaLN_modulation.1.bias', 'encoder.layer.7.adaLN_modulation.1.weight', 'encoder.layer.0.adaLN_modulation.1.weight', 'encoder.layer.7.adaLN_modulation.1.bias', 'encoder.layer.6.adaLN_modulation.1.weight'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. Using C:\Users\k1ckm3\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu121 as PyTorch extensions root... Detected CUDA files, patching ldflags Emitting ninja build file C:\Users\k1ckm3\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu121\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: no work to do. Loading extension module nvdiffrast_plugin... Traceback (most recent call last): File "C:\Users\k1ckm3\InstantMesh\run.py", line 132, in model.init_flexicubes_geometry(device, fovy=30.0) File "C:\Users\k1ckm3\InstantMesh\src\models\lrm_mesh.py", line 79, in init_flexicubes_geometry renderer = NeuralRender(device, camera_model=camera) File "C:\Users\k1ckm3\InstantMesh\src\models\geometry\render\neural_render.py", line 73, in init self.ctx = dr.RasterizeCudaContext(device=device) File "C:\Users\k1ckm3\anaconda3\envs\instantmesh\lib\site-packages\nvdiffrast\torch\ops.py", line 177, in init self.cpp_wrapper = _get_plugin().RasterizeCRStateWrapper(cuda_device_idx) File "C:\Users\k1ckm3\anaconda3\envs\instantmesh\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\k1ckm3\anaconda3\envs\instantmesh\lib\site-packages\torch\utils\cpp_extension.py", line 1308, in load return _jit_compile( File "C:\Users\k1ckm3\anaconda3\envs\instantmesh\lib\site-packages\torch\utils\cpp_extension.py", line 1736, in _jit_compile return _import_module_from_library(name, build_directory, is_python_module) File "C:\Users\k1ckm3\anaconda3\envs\instantmesh\lib\site-packages\torch\utils\cpp_extension.py", line 2136, in _import_module_from_library module = importlib.util.module_from_spec(spec) File "", line 571, in module_from_spec File "", line 1176, in create_module File "", line 241, in _call_with_frames_removed ImportError: DLL load failed while importing nvdiffrast_plugin: The specified module cannot be found.

mlfetsch75 commented 5 months ago

Similar error running app.py alone. Confirmed nvdiffrast installed with pip. confirmed able to import with conda env python.

Downloading (…)rocessor_config.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 244/244 [00:00<?, ?B/s] Traceback (most recent call last): File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\InstantMesh\app.py", line 101, in model.init_flexicubes_geometry(device, fovy=30.0) File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\InstantMesh\src\models\lrm_mesh.py", line 79, in init_flexicubes_geometry renderer = NeuralRender(device, camera_model=camera) File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\InstantMesh\src\models\geometry\render\neural_render.py", line 73, in init self.ctx = dr.RasterizeCudaContext(device=device) File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\lib\site-packages\nvdiffrast\torch\ops.py", line 177, in init self.cpp_wrapper = _get_plugin().RasterizeCRStateWrapper(cuda_device_idx) File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\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 "F:\tmp\Diffuser\miniconda3\envs\instantmesh\lib\site-packages\torch\utils\cpp_extension.py", line 1308, in load return _jit_compile( File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\lib\site-packages\torch\utils\cpp_extension.py", line 1736, in _jit_compile return _import_module_from_library(name, build_directory, is_python_module) File "F:\tmp\Diffuser\miniconda3\envs\instantmesh\lib\site-packages\torch\utils\cpp_extension.py", line 2136, in _import_module_from_library module = importlib.util.module_from_spec(spec) File "", line 571, in module_from_spec File "", line 1176, in create_module File "", line 241, in _call_with_frames_removed ImportError: DLL load failed while importing nvdiffrast_plugin: The specified module could not be found.

sumanttyagi commented 5 months ago

https://github.com/TencentARC/InstantMesh/issues/34

sumanttyagi commented 5 months ago

@mlfetsch75 @k1ckmefroml1f3 i found the solution for this not sure whether this is right way to fix it !) Uninstall previous cuda version from the system 2) install latest cuda toolkit from 12.1 and drivers 3) set the env path for this - should happen by itself but sometimes overwrite issue 4) restart you env .

iiiCpu commented 4 months ago

Long story short, nvdiffrast_plugin is build against CUDA_PATH version, not first (or the only) in PATH. So, delete nvdiffrast_plugin and set correct CUDA_PATH before run.

rmdir /S %userprofile%\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu121\nvdiffrast_plugin
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\
python app.py

UPD: removed quotes from path, it leads to errors in some cases

wikeeyang commented 4 months ago

Thanks for the fix and reply.

mlfetsch75 commented 4 months ago

@iiiCpu @sumanttyagi Way simpler than how I was trying to resolve. Thanks very much.

DiamondGlassDrill commented 2 months ago

This does not work. I have Cuda 12.4 and deleted the folder rmdir /S %userprofile%\AppData\Local\torch_extensions\torch_extensions\Cache\py310_cu124\nvdiffrast_plugin but still had the issue it makes internally all to 12.1 but i removed all old CUDA and compiled some other environments already with 12.4 without any issue e.g,. in the nvdiffrast_plugin folder the file is called: build.ninja

in that file at the top it already starts with the madness it writes:

ninja_required_version = 1.3
cxx = cl
nvcc = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\nvcc

Changing it manually to 12.4 does not help as when I restart app.py it rebuilds --> any hint? where can I change the build.ninja instructions?

BTW: CUDA_PATH CUDA_HOME Are pointing towards C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4

Update: I found additionally that in older versions I compiled it with cu118, cu117, cu121 in those folders there are still the many files coming along with a successful compiled nvdiffrast. So somewhat it must be the 121 but I have no connection to it?

DiamondGlassDrill commented 2 months ago

I restarted everything and now build.ninja is 12.4 maybe an issue somewhere with caching but I end up at the same issue DLL load failed while importing nvdiffrast_plugin I tried the nvdiffrast example: nvdiffrast\samples\torch\triangle.py python triangle.py --cuda which throws the same error, and does not build the environment for nvdiffrast