From 1b366bc899c15b146f911e4f32d96eb7a3a998d1 Mon Sep 17 00:00:00 2001 From: Nicolas Gorlo Date: Fri, 9 May 2025 14:28:01 -0400 Subject: [PATCH 1/3] updated deprecated methods --- nerfstudio/engine/trainer.py | 4 ++-- nerfstudio/field_components/activations.py | 6 +++--- nerfstudio/scripts/downloads/download_data.py | 2 +- nerfstudio/utils/eval_utils.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nerfstudio/engine/trainer.py b/nerfstudio/engine/trainer.py index a653e1de8d..7f2f0d34d0 100644 --- a/nerfstudio/engine/trainer.py +++ b/nerfstudio/engine/trainer.py @@ -429,7 +429,7 @@ def _load_checkpoint(self) -> None: load_step = sorted(int(x[x.find("-") + 1 : x.find(".")]) for x in os.listdir(load_dir))[-1] load_path: Path = load_dir / f"step-{load_step:09d}.ckpt" assert load_path.exists(), f"Checkpoint {load_path} does not exist" - loaded_state = torch.load(load_path, map_location="cpu") + loaded_state = torch.load(load_path, map_location="cpu", weights_only=False) self._start_step = loaded_state["step"] + 1 # load the checkpoints for pipeline, optimizers, and gradient scalar self.pipeline.load_pipeline(loaded_state["pipeline"], loaded_state["step"]) @@ -440,7 +440,7 @@ def _load_checkpoint(self) -> None: CONSOLE.print(f"Done loading Nerfstudio checkpoint from {load_path}") elif load_checkpoint is not None: assert load_checkpoint.exists(), f"Checkpoint {load_checkpoint} does not exist" - loaded_state = torch.load(load_checkpoint, map_location="cpu") + loaded_state = torch.load(load_checkpoint, map_location="cpu", weights_only=False) self._start_step = loaded_state["step"] + 1 # load the checkpoints for pipeline, optimizers, and gradient scalar self.pipeline.load_pipeline(loaded_state["pipeline"], loaded_state["step"]) diff --git a/nerfstudio/field_components/activations.py b/nerfstudio/field_components/activations.py index e413965e24..7448194b9a 100644 --- a/nerfstudio/field_components/activations.py +++ b/nerfstudio/field_components/activations.py @@ -22,20 +22,20 @@ from jaxtyping import Float from torch import Tensor from torch.autograd import Function -from torch.cuda.amp import custom_bwd, custom_fwd +from torch.amp import custom_bwd, custom_fwd class _TruncExp(Function): # Implementation from torch-ngp: # https://github.com/ashawkey/torch-ngp/blob/93b08a0d4ec1cc6e69d85df7f0acdfb99603b628/activation.py @staticmethod - @custom_fwd(cast_inputs=torch.float32) + @custom_fwd(cast_inputs=torch.float32, device_type='cuda') def forward(ctx, x): ctx.save_for_backward(x) return torch.exp(x) @staticmethod - @custom_bwd + @custom_bwd(device_type='cuda') def backward(ctx, g): x = ctx.saved_tensors[0] return g * torch.exp(x.clamp(-15, 15)) diff --git a/nerfstudio/scripts/downloads/download_data.py b/nerfstudio/scripts/downloads/download_data.py index a2c9d27584..653fbf94d0 100644 --- a/nerfstudio/scripts/downloads/download_data.py +++ b/nerfstudio/scripts/downloads/download_data.py @@ -514,7 +514,7 @@ def download(self, save_dir: Path) -> None: split_filepaths = [] for image_path, new_image_path in copied_images.items(): metadata_path = image_path.parent.parent / "metadata" / f"{image_path.stem}.pt" - metadata = torch.load(metadata_path, map_location="cpu") + metadata = torch.load(metadata_path, map_location="cpu", weights_only=False) c2w = torch.eye(4) c2w[:3] = metadata["c2w"] file_path = str(Path("images") / f"{new_image_path.name}") diff --git a/nerfstudio/utils/eval_utils.py b/nerfstudio/utils/eval_utils.py index 11a8b23416..8d07fe842a 100644 --- a/nerfstudio/utils/eval_utils.py +++ b/nerfstudio/utils/eval_utils.py @@ -59,7 +59,7 @@ def eval_load_checkpoint(config: TrainerConfig, pipeline: Pipeline) -> Tuple[Pat load_step = config.load_step load_path = config.load_dir / f"step-{load_step:09d}.ckpt" assert load_path.exists(), f"Checkpoint {load_path} does not exist" - loaded_state = torch.load(load_path, map_location="cpu") + loaded_state = torch.load(load_path, map_location="cpu", weights_only=False) pipeline.load_pipeline(loaded_state["pipeline"], loaded_state["step"]) CONSOLE.print(f":white_check_mark: Done loading checkpoint from {load_path}") return load_path, load_step From f6d43ac606f3078ea1976ab72da11eefdca58b38 Mon Sep 17 00:00:00 2001 From: Nicolas Gorlo Date: Fri, 9 May 2025 14:40:00 -0400 Subject: [PATCH 2/3] fixed ruff formatting --- nerfstudio/field_components/activations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nerfstudio/field_components/activations.py b/nerfstudio/field_components/activations.py index 7448194b9a..5a483b3b9e 100644 --- a/nerfstudio/field_components/activations.py +++ b/nerfstudio/field_components/activations.py @@ -21,8 +21,8 @@ import torch from jaxtyping import Float from torch import Tensor -from torch.autograd import Function from torch.amp import custom_bwd, custom_fwd +from torch.autograd import Function class _TruncExp(Function): From 80003ca0ec2803e075fe6773586a1d5dc12507a4 Mon Sep 17 00:00:00 2001 From: Nicolas Gorlo Date: Fri, 9 May 2025 14:45:07 -0400 Subject: [PATCH 3/3] ran ruff formatter locally --- nerfstudio/field_components/activations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nerfstudio/field_components/activations.py b/nerfstudio/field_components/activations.py index 5a483b3b9e..3719990949 100644 --- a/nerfstudio/field_components/activations.py +++ b/nerfstudio/field_components/activations.py @@ -29,13 +29,13 @@ class _TruncExp(Function): # Implementation from torch-ngp: # https://github.com/ashawkey/torch-ngp/blob/93b08a0d4ec1cc6e69d85df7f0acdfb99603b628/activation.py @staticmethod - @custom_fwd(cast_inputs=torch.float32, device_type='cuda') + @custom_fwd(cast_inputs=torch.float32, device_type="cuda") def forward(ctx, x): ctx.save_for_backward(x) return torch.exp(x) @staticmethod - @custom_bwd(device_type='cuda') + @custom_bwd(device_type="cuda") def backward(ctx, g): x = ctx.saved_tensors[0] return g * torch.exp(x.clamp(-15, 15))