nerfstudio-project / nerfstudio

A collaboration friendly studio for NeRFs
https://docs.nerf.studio
Apache License 2.0
9.55k stars 1.3k forks source link

Using instant-ngp with nerfstudio 0.1.19 (torch 1.13.1, cu117, VS2022, Windows) leads to ImportError (cannot import name 'csrc' from 'nerfacc') #1592

Open RaiaN opened 1 year ago

RaiaN commented 1 year ago

Full log

`(nerfstudio) E:\>ns-train instant-ngp --data ./data/nerfstudio/poster
[12:27:22] Using --data alias for --data.pipeline.datamanager.data                                          train.py:222
──────────────────────────────────────────────────────── Config ────────────────────────────────────────────────────────
TrainerConfig(
    _target=<class 'nerfstudio.engine.trainer.Trainer'>,
    output_dir=WindowsPath('outputs'),
    method_name='instant-ngp',
    experiment_name=None,
    timestamp='2023-03-12_122722',
    machine=MachineConfig(seed=42, num_gpus=1, num_machines=1, machine_rank=0, dist_url='auto'),
    logging=LoggingConfig(
        relative_log_dir=WindowsPath('.'),
        steps_per_log=10,
        max_buffer_size=20,
        local_writer=LocalWriterConfig(
            _target=<class 'nerfstudio.utils.writer.LocalWriter'>,
            enable=True,
            stats_to_track=(
                <EventName.ITER_TRAIN_TIME: 'Train Iter (time)'>,
                <EventName.TRAIN_RAYS_PER_SEC: 'Train Rays / Sec'>,
                <EventName.CURR_TEST_PSNR: 'Test PSNR'>,
                <EventName.VIS_RAYS_PER_SEC: 'Vis Rays / Sec'>,
                <EventName.TEST_RAYS_PER_SEC: 'Test Rays / Sec'>,
                <EventName.ETA: 'ETA (time)'>
            ),
            max_log_size=10
        ),
        enable_profiler=True
    ),
    viewer=ViewerConfig(
        relative_log_filename='viewer_log_filename.txt',
        start_train=True,
        zmq_port=None,
        launch_bridge_server=True,
        websocket_port=7007,
        ip_address='127.0.0.1',
        num_rays_per_chunk=64000,
        max_num_display_images=512,
        quit_on_train_completion=False
    ),
    pipeline=DynamicBatchPipelineConfig(
        _target=<class 'nerfstudio.pipelines.dynamic_batch.DynamicBatchPipeline'>,
        datamanager=VanillaDataManagerConfig(
            _target=<class 'nerfstudio.data.datamanagers.base_datamanager.VanillaDataManager'>,
            data=WindowsPath('data/nerfstudio/poster'),
            camera_optimizer=CameraOptimizerConfig(
                _target=<class 'nerfstudio.cameras.camera_optimizers.CameraOptimizer'>,
                mode='off',
                position_noise_std=0.0,
                orientation_noise_std=0.0,
                optimizer=AdamOptimizerConfig(
                    _target=<class 'torch.optim.adam.Adam'>,
                    lr=0.0006,
                    eps=1e-15,
                    max_norm=None,
                    weight_decay=0
                ),
                scheduler=ExponentialDecaySchedulerConfig(
                    _target=<class 'nerfstudio.engine.schedulers.ExponentialDecayScheduler'>,
                    lr_pre_warmup=1e-08,
                    lr_final=None,
                    warmup_steps=0,
                    max_steps=10000,
                    ramp='cosine'
                ),
                param_group='camera_opt'
            ),
            dataparser=NerfstudioDataParserConfig(
                _target=<class 'nerfstudio.data.dataparsers.nerfstudio_dataparser.Nerfstudio'>,
                data=WindowsPath('data/nerfstudio/poster'),
                scale_factor=1.0,
                downscale_factor=None,
                scene_scale=1.0,
                orientation_method='up',
                center_method='poses',
                auto_scale_poses=True,
                train_split_fraction=0.9,
                depth_unit_scale_factor=0.001
            ),
            train_num_rays_per_batch=8192,
            train_num_images_to_sample_from=-1,
            train_num_times_to_repeat_images=-1,
            eval_num_rays_per_batch=1024,
            eval_num_images_to_sample_from=-1,
            eval_num_times_to_repeat_images=-1,
            eval_image_indices=(0,),
            camera_res_scale_factor=1.0,
            patch_size=1
        ),
        model=InstantNGPModelConfig(
            _target=<class 'nerfstudio.models.instant_ngp.NGPModel'>,
            enable_collider=False,
            collider_params=None,
            loss_coefficients={'rgb_loss_coarse': 1.0, 'rgb_loss_fine': 1.0},
            eval_num_rays_per_chunk=8192,
            max_num_samples_per_ray=24,
            grid_resolution=128,
            max_res=2048,
            log2_hashmap_size=19,
            contraction_type=<ContractionType.UN_BOUNDED_SPHERE: 2>,
            cone_angle=0.004,
            render_step_size=0.01,
            near_plane=0.05,
            far_plane=1000.0,
            use_appearance_embedding=False,
            background_color='random'
        ),
        target_num_samples=262144,
        max_num_samples_per_ray=1024
    ),
    optimizers={
        'fields': {
            'optimizer': AdamOptimizerConfig(
                _target=<class 'torch.optim.adam.Adam'>,
                lr=0.01,
                eps=1e-15,
                max_norm=None,
                weight_decay=0
            ),
            'scheduler': None
        }
    },
    vis='viewer',
    data=WindowsPath('data/nerfstudio/poster'),
    relative_model_dir=WindowsPath('nerfstudio_models'),
    steps_per_save=2000,
    steps_per_eval_batch=500,
    steps_per_eval_image=500,
    steps_per_eval_all_images=25000,
    max_num_iterations=30000,
    mixed_precision=True,
    save_only_latest_checkpoint=True,
    load_dir=None,
    load_step=None,
    load_config=None,
    log_gradients=False
)
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[12:27:22] Saving config to: outputs\poster\instant-ngp\2023-03-12_122722\config.yml            experiment_config.py:129
[12:27:22] Saving checkpoints to: outputs\poster\instant-ngp\2023-03-12_122722\nerfstudio_models          trainer.py:128
[12:27:22] Auto image downscale factor of 2                                                 nerfstudio_dataparser.py:314
           Skipping 0 files in dataset split train.                                         nerfstudio_dataparser.py:165
           Skipping 0 files in dataset split val.                                           nerfstudio_dataparser.py:165
Setting up training dataset...
Caching all 204 images.
Setting up evaluation dataset...
Caching all 22 images.
No checkpoints to load, training from scratch
Using ZMQ port: 52479

========================================================================================================================
[Public] Open the viewer at https://viewer.nerf.studio/versions/23-03-9-0/?websocket_url=ws://localhost:7007
========================================================================================================================

Sending ping to the viewer Bridge Server...
Successfully connected.
[NOTE] Not running eval iterations since only viewer is enabled.
Use --vis {wandb, tensorboard, viewer+wandb, viewer+tensorboard} to run with eval.
Disabled tensorboard/wandb event writers
E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\utils\cpp_extension.py:358: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
  warnings.warn(f'Error checking compiler version for {compiler}: {error}')
(  ●   ) NerfAcc: Setting up CUDA (This may take a few minutes the first time)INFO: Could not find files for the given pattern(s).
Printing profiling stats, from longest to shortest duration in seconds
Traceback (most recent call last):
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\cuda\_backend.py", line 50, in <module>
    from nerfacc import csrc as _C
ImportError: cannot import name 'csrc' from 'nerfacc' (E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\Scripts\ns-train.exe\__main__.py", line 7, in <module>
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\scripts\train.py", line 247, in entrypoint
    main(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\scripts\train.py", line 233, in main
    launch(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\scripts\train.py", line 172, in launch
    main_func(local_rank=0, world_size=world_size, config=config)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\scripts\train.py", line 87, in train_loop
    trainer.train()
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfstudio\engine\trainer.py", line 213, in train
    callback.run_callback_at_location(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfstudio\engine\callbacks.py", line 103, in run_callback_at_location
    self.run_callback(step=step)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfstudio\engine\callbacks.py", line 90, in run_callback
    self.func(*self.args, **self.kwargs, step=step)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfstudio\models\instant_ngp.py", line 150, in update_occupancy_grid
    self.occupancy_grid.every_n_step(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\grid.py", line 271, in every_n_step
    self._update(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\grid.py", line 224, in _update
    x = contract_inv(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\contraction.py", line 101, in contract_inv
    ctype = type.to_cpp_version()
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\contraction.py", line 62, in to_cpp_version
    return _C.ContractionTypeGetter(self.value)
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\cuda\__init__.py", line 11, in call_cuda
    from ._backend import _C
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\nerfacc\cuda\_backend.py", line 73, in <module>
    _C = load(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\utils\cpp_extension.py", line 1284, in load
    return _jit_compile(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\utils\cpp_extension.py", line 1508, in _jit_compile
    _write_ninja_file_and_build_library(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\utils\cpp_extension.py", line 1610, in _write_ninja_file_and_build_library
    _write_ninja_file_to_build_library(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\utils\cpp_extension.py", line 2055, in _write_ninja_file_to_build_library
    _write_ninja_file(
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\site-packages\torch\utils\cpp_extension.py", line 2195, in _write_ninja_file
    cl_paths = subprocess.check_output(['where',
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "E:\ProgramData\miniconda3\envs\nerfstudio\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['where', 'cl']' returned non-zero exit status 1`

To Reproduce

  1. Try to use ns-train instant-ngp --data ./data/nerfstudio/poster and you will get above crash.

Expected behavior instant-ngp works by default after installing all dependencies according to official documentation

Additional context There is a way to resolve this issue:

tancik commented 1 year ago

Note that the wheel you need will depend on your version of torch and cuda - https://github.com/KAIR-BAIR/nerfacc#installation

RaiaN commented 1 year ago

So my version of torch and cuda are 1.13.1 and cu117 but the built-in wheel for nerfacc simply does not work that is why I posted a workaround above..

RaiaN commented 1 year ago

To clarify, the point of this bug report is that whatever is set in nerfstudio requirements.txt for nerfacc leads to non working instant-ngp when using torch 1.13.1 (supported by nerfstudio) and cuda 117 (also supported).

gajorro commented 1 year ago

To clarify, the point of this bug report is that whatever is set in nerfstudio requirements.txt for nerfacc leads to non working instant-ngp when using torch 1.13.1 (supported by nerfstudio) and cuda 117 (also supported).

Had same problem and your solution worked :)