angelolab / Nimbus-Inference

MIT License
3 stars 3 forks source link

Cuda not compiled #12

Open smith6jt-cop opened 3 weeks ago

smith6jt-cop commented 3 weeks ago

Report

Running the example notebook 1_Nimbus_predict and trying to use GPU gives the following error. I followed the instructions exactly as described in the ReadMe. Does the pip install Nimbus-inference install torch=2.2.0-cpu by default?


AssertionError Traceback (most recent call last) Cell In[11], line 1 ----> 1 cell_table = nimbus.predict_fovs()

File ~\Nimbus-Inference\src\nimbus_inference\nimbus.py:191, in Nimbus.predict_fovs(self) 189 print("Predictions will be saved in {}".format(self.output_dir)) 190 print("Iterating through fovs will take a while...") --> 191 self.cell_table = predict_fovs( 192 nimbus=self, dataset=self.dataset, output_dir=self.output_dir, 193 normalization_dict=self.normalization_dict, save_predictions=self.save_predictions, 194 half_resolution=self.half_resolution, batch_size=self.batch_size, 195 test_time_augmentation=self.test_time_aug, suffix=self.dataset.suffix, 196 ) 197 self.cell_table.to_csv(os.path.join(self.output_dir, "nimbus_cell_table.csv"), index=False) 198 return self.cell_table

File ~\Nimbus-Inference\src\nimbus_inference\utils.py:383, in predict_fovs(nimbus, dataset, normalization_dict, output_dir, suffix, save_predictions, half_resolution, batch_size, test_time_augmentation) 379 prediction = test_time_aug( 380 input_data, channel_name, nimbus, normalization_dict, batch_size=batch_size 381 ) 382 else: --> 383 prediction = nimbus.predict_segmentation( 384 input_data, 385 preprocess_kwargs={ 386 "normalize": True, "marker": channel_name, 387 "normalization_dict": normalization_dict 388 }, 389 ) 390 prediction = np.squeeze(prediction) 391 if half_resolution:

File ~\Nimbus-Inference\src\nimbus_inference\nimbus.py:221, in Nimbus.predict_segmentation(self, input_data, preprocess_kwargs) 219 else: 220 if not hasattr(self, "model") or self.model.padding != "valid": --> 221 self.initialize_model(padding="valid") 222 prediction = self._tile_and_stitch(input_data) 223 return prediction

File ~\Nimbus-Inference\src\nimbus_inference\nimbus.py:153, in Nimbus.initialize_model(self, padding) 151 model.load_state_dict(torch.load(self.checkpoint_path)) 152 print("Loaded weights from {}".format(self.checkpoint_path)) --> 153 self.model = model.to(self.device).eval()

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\nn\modules\module.py:1152, in Module.to(self, *args, **kwargs) 1148 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, 1149 non_blocking, memory_format=convert_to_format) 1150 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking) -> 1152 return self._apply(convert)

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\nn\modules\module.py:802, in Module._apply(self, fn, recurse) 800 if recurse: 801 for module in self.children(): --> 802 module._apply(fn) 804 def compute_should_use_set_data(tensor, tensor_applied): 805 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied): 806 # If the new tensor has compatible tensor type as the existing tensor, 807 # the current behavior is to change the tensor in-place using .data =, (...) 812 # global flag to let the user control whether they want the future 813 # behavior of overwriting the existing tensor or not.

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\nn\modules\module.py:802, in Module._apply(self, fn, recurse) 800 if recurse: 801 for module in self.children(): --> 802 module._apply(fn) 804 def compute_should_use_set_data(tensor, tensor_applied): 805 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied): 806 # If the new tensor has compatible tensor type as the existing tensor, 807 # the current behavior is to change the tensor in-place using .data =, (...) 812 # global flag to let the user control whether they want the future 813 # behavior of overwriting the existing tensor or not.

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\nn\modules\module.py:802, in Module._apply(self, fn, recurse) 800 if recurse: 801 for module in self.children(): --> 802 module._apply(fn) 804 def compute_should_use_set_data(tensor, tensor_applied): 805 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied): 806 # If the new tensor has compatible tensor type as the existing tensor, 807 # the current behavior is to change the tensor in-place using .data =, (...) 812 # global flag to let the user control whether they want the future 813 # behavior of overwriting the existing tensor or not.

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\nn\modules\module.py:825, in Module._apply(self, fn, recurse) 821 # Tensors stored in modules are graph leaves, and we don't want to 822 # track autograd history of param_applied, so we have to use 823 # with torch.no_grad(): 824 with torch.no_grad(): --> 825 param_applied = fn(param) 826 should_use_set_data = compute_should_use_set_data(param, param_applied) 827 if should_use_set_data:

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\nn\modules\module.py:1150, in Module.to..convert(t) 1147 if convert_to_format is not None and t.dim() in (4, 5): 1148 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, 1149 non_blocking, memory_format=convert_to_format) -> 1150 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)

File ~\AppData\Local\miniconda3\envs\Nimbus\lib\site-packages\torch\cuda__init__.py:293, in _lazy_init() 288 raise RuntimeError( 289 "Cannot re-initialize CUDA in forked subprocess. To use CUDA with " 290 "multiprocessing, you must use the 'spawn' start method" 291 ) 292 if not hasattr(torch._C, "_cuda_getDeviceCount"): --> 293 raise AssertionError("Torch not compiled with CUDA enabled") 294 if _cudart is None: 295 raise AssertionError( 296 "libcudart functions unavailable. It looks like you have a broken build?" 297 )

AssertionError: Torch not compiled with CUDA enabled

Version information


alpineer NA ark NA nimbus_inference 0.0.1 numpy 1.23.5 session_info 1.0.0 tifffile 2024.5.22

PIL 9.5.0 aiohttp 3.9.5 aiosignal 1.3.1 anyio NA arrow 1.3.0 asciitree NA asttokens NA async_timeout 4.0.3 attr 23.2.0 attrs 23.2.0 babel 2.15.0 certifi 2024.06.02 cffi 1.16.0 charset_normalizer 2.1.1 colorama 0.4.6 comm 0.2.2 cv2 4.10.0 cycler 0.12.1 cython_runtime NA datasets 2.19.2 dateutil 2.9.0.post0 debugpy 1.8.1 decorator 5.1.1 defusedxml 0.7.1 dill 0.3.8 entrypoints 0.4 exceptiongroup 1.2.1 executing 2.0.1 fastjsonschema NA filelock 3.14.0 fqdn NA frozenlist 1.4.1 fsspec 2024.3.1 huggingface_hub 0.23.3 idna 3.7 imagecodecs 2024.6.1 imageio 2.34.1 ipykernel 6.29.4 ipython_genutils 0.2.0 ipywidgets 8.1.3 isoduration NA jedi 0.19.1 jinja2 3.1.4 joblib 1.4.2 json5 0.9.25 jsonpointer 2.4 jsonschema 4.22.0 jsonschema_specifications NA jupyter_events 0.10.0 jupyter_server 2.14.1 jupyterlab_server 2.27.2 kiwisolver 1.4.5 lxml 5.2.2 markupsafe 2.1.5 matplotlib 3.9.0 mpl_toolkits NA multidict 6.0.5 multiprocess 0.70.16 natsort 8.4.0 nbformat 5.10.4 nt NA numcodecs 0.12.1 overrides NA packaging 24.0 pandas 2.2.2 parso 0.8.4 platformdirs 4.2.2 prometheus_client NA prompt_toolkit 3.0.46 psutil 5.9.8 pure_eval 0.2.2 pyarrow 16.1.0 pyarrow_hotfix NA pydev_ipython NA pydevconsole NA pydevd 2.9.5 pydevd_file_utils NA pydevd_plugins NA pydevd_tracing NA pygments 2.18.0 pyometiff 1.0.0 pyparsing 3.1.1 pythoncom NA pythonjsonlogger NA pytz 2024.1 pywin32_bootstrap NA pywin32_system32 NA pywintypes NA pywt 1.6.0 referencing NA requests 2.32.3 rfc3339_validator 0.1.4 rfc3986_validator 0.1.1 rpds NA scipy 1.13.1 send2trash NA six 1.16.0 skimage 0.19.3 sniffio 1.3.1 stack_data 0.6.3 torch 2.2.0+cpu torchgen NA tornado 6.4.1 tqdm 4.66.4 traitlets 5.14.3 typing_extensions NA uri_template NA urllib3 2.2.1 wcwidth 0.2.13 webcolors 24.6.0 websocket 1.8.0 win32api NA win32com NA win32con NA win32trace NA winerror NA xxhash NA yaml 6.0.1 yarl 1.9.4 zarr 2.18.2 zmq 26.0.3 zoneinfo NA zstandard 0.22.0

IPython 8.25.0 jupyter_client 7.4.9 jupyter_core 5.7.2 jupyterlab 3.6.7 notebook 6.5.7

Python 3.10.14 | packaged by Anaconda, Inc. | (main, May 6 2024, 19:44:50) [MSC v.1916 64 bit (AMD64)] Windows-10-10.0.19045-SP0

Session information updated at 2024-06-06 17:26

JLrumberger commented 3 weeks ago

Hi Justin,

thanks for opening the issue. Could you tell me the OS and hardware where you experienced this error? It seems that only torch2.2.0+cpu is installed, so the cuda version of torch is missing. After activating the environment, could you install pytorch via pip python -m pip install torch==2.2.0 --index-url https://download.pytorch.org/whl/cu118, re-run the code and see if this fixes it? Best, Lorenz

JLrumberger commented 1 week ago

This should be fixed now. Could you try it @smith6jt-cop ?