Skip to content

ns-viewer: Model checkpoint load fails when using PyTorch 2.6 #3683

@gemblerz

Description

@gemblerz

Describe the bug
The eval_load_checkpoint function in eval_utils.py is not compliant with the new policy in PyTorch 2.6, blocking the ns-viewer command from proceeding after downloading the model.

To Reproduce
Steps to reproduce the behavior:

  1. Download your data. Mine is called "process_output".
  2. Train a model and save a checkpoint. For example, ns-train nerfacto --data data/nerfstudio/process_output.
  3. Visualize the trained model using ns-viewer, like something similar to /usr/local/bin/ns-viewer --load-config /storage/outputs/process_output/nerfacto/2025-07-01_153057/config.yml
  4. Encounter the error, resulting in an error in the ns-viewer command execution.
  5. See the Screenshots section for the detailed error message.

Expected behavior
Load the model and checkpoint, and render the scene.

Screenshots
The entire terminal output is as follows,

/usr/local/bin/ns-viewer --load-config /storage/outputs/process_output/nerfacto/2025-07-01_153057/config.yml
/usr/local/lib/python3.10/dist-packages/nerfstudio/field_components/activations.py:32: FutureWarning: `torch.cuda.amp.custom_fwd(args...)` is deprecated. Please use `torch.amp.custom_fwd(args..., device_type='cuda')` instead.
  @custom_fwd(cast_inputs=torch.float32)
/usr/local/lib/python3.10/dist-packages/nerfstudio/field_components/activations.py:39: FutureWarning: `torch.cuda.amp.custom_bwd(args...)` is deprecated. Please use `torch.amp.custom_bwd(args..., device_type='cuda')` instead.
  def backward(ctx, g):
[21:56:14] Auto image downscale factor of 1                                                 nerfstudio_dataparser.py:484
            Dataset is overriding orientation method to none                                nerfstudio_dataparser.py:232
            Dataset is overriding orientation method to none                                nerfstudio_dataparser.py:232
            Dataset is overriding orientation method to none                                nerfstudio_dataparser.py:232
/usr/local/lib/python3.10/dist-packages/nerfstudio/field_components/activations.py:32: FutureWarning: `torch.cuda.amp.custom_fwd(args...)` is deprecated. Please use `torch.amp.custom_fwd(args..., device_type='cuda')` instead.
  @custom_fwd(cast_inputs=torch.float32)
/usr/local/lib/python3.10/dist-packages/nerfstudio/field_components/activations.py:39: FutureWarning: `torch.cuda.amp.custom_bwd(args...)` is deprecated. Please use `torch.amp.custom_bwd(args..., device_type='cuda')` instead.
  def backward(ctx, g):
Started threads
Setting up evaluation dataset...
Caching all 3 images.
Loading data batch ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Loading latest checkpoint from load_dir
Traceback (most recent call last):
  File "/usr/local/bin/ns-viewer", line 8, in <module>
    sys.exit(entrypoint())
  File "/usr/local/lib/python3.10/dist-packages/nerfstudio/scripts/viewer/run_viewer.py", line 135, in entrypoint
    tyro.cli(tyro.conf.FlagConversionOff[RunViewer]).main()
  File "/usr/local/lib/python3.10/dist-packages/nerfstudio/scripts/viewer/run_viewer.py", line 63, in main
    config, pipeline, _, step = eval_setup(
  File "/usr/local/lib/python3.10/dist-packages/nerfstudio/utils/eval_utils.py", line 111, in eval_setup
    checkpoint_path, step = eval_load_checkpoint(config, pipeline)
  File "/usr/local/lib/python3.10/dist-packages/nerfstudio/utils/eval_utils.py", line 62, in eval_load_checkpoint
    loaded_state = torch.load(load_path, map_location="cpu")
  File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 1470, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
        (1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
        (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
        WeightsUnpickler error: Unsupported global: GLOBAL numpy.core.multiarray.scalar was not an allowed global by default. Please use `torch.serialization.add_safe_globals([scalar])` or the `torch.serialization.safe_globals([scalar])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

Additional context
NerfStudio V1.1.5 is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions