From 08e3a1f1a664e028121a567718ca8b10e00e5e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Kulh=C3=A1nek?= Date: Thu, 18 May 2023 09:12:51 +0200 Subject: [PATCH] Drop backward compatibility for Torch 1.13 (#1948) * Drop backward compatibility for Torch 1.13 * Fix lint errors --- nerfstudio/cameras/camera_utils.py | 4 +--- nerfstudio/model_components/scene_colliders.py | 3 +-- nerfstudio/utils/math.py | 4 +--- nerfstudio/utils/misc.py | 10 ---------- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/nerfstudio/cameras/camera_utils.py b/nerfstudio/cameras/camera_utils.py index 2c0b746d1..c6344c4e7 100644 --- a/nerfstudio/cameras/camera_utils.py +++ b/nerfstudio/cameras/camera_utils.py @@ -25,8 +25,6 @@ from jaxtyping import Float from numpy.typing import NDArray from torch import Tensor -from nerfstudio.utils.misc import torch_compile - _EPS = np.finfo(float).eps * 4.0 @@ -407,7 +405,7 @@ def _compute_residual_and_jacobian( return fx, fy, fx_x, fx_y, fy_x, fy_y -@torch_compile(dynamic=True, mode="reduce-overhead", backend="eager") +@torch.compile(dynamic=True, mode="reduce-overhead", backend="eager") def radial_and_tangential_undistort( coords: torch.Tensor, distortion_params: torch.Tensor, diff --git a/nerfstudio/model_components/scene_colliders.py b/nerfstudio/model_components/scene_colliders.py index 25011c740..dfff2dc6a 100644 --- a/nerfstudio/model_components/scene_colliders.py +++ b/nerfstudio/model_components/scene_colliders.py @@ -22,7 +22,6 @@ import torch from jaxtyping import Float from torch import Tensor, nn -from nerfstudio.utils.misc import torch_compile from nerfstudio.cameras.rays import RayBundle from nerfstudio.data.scene_box import SceneBox @@ -109,7 +108,7 @@ class AABBBoxCollider(SceneCollider): return ray_bundle -@torch_compile(dynamic=True, mode="reduce-overhead") +@torch.compile(dynamic=True, mode="reduce-overhead") def _intersect_with_sphere( rays_o: torch.Tensor, rays_d: torch.Tensor, center: torch.Tensor, radius: float = 1.0, near_plane: float = 0.0 ): diff --git a/nerfstudio/utils/math.py b/nerfstudio/utils/math.py index 866d280f8..980ce195b 100644 --- a/nerfstudio/utils/math.py +++ b/nerfstudio/utils/math.py @@ -21,8 +21,6 @@ import torch from jaxtyping import Bool, Float from torch import Tensor -from nerfstudio.utils.misc import torch_compile - def components_from_spherical_harmonics( levels: int, directions: Float[Tensor, "*batch 3"] @@ -199,7 +197,7 @@ def expected_sin(x_means: torch.Tensor, x_vars: torch.Tensor) -> torch.Tensor: return torch.exp(-0.5 * x_vars) * torch.sin(x_means) -@torch_compile(dynamic=True, mode="reduce-overhead", backend="eager") +@torch.compile(dynamic=True, mode="reduce-overhead", backend="eager") def intersect_aabb( origins: torch.Tensor, directions: torch.Tensor, diff --git a/nerfstudio/utils/misc.py b/nerfstudio/utils/misc.py index f05cd4d0c..e21aece48 100644 --- a/nerfstudio/utils/misc.py +++ b/nerfstudio/utils/misc.py @@ -158,13 +158,3 @@ def strtobool(val) -> bool: FMI https://stackoverflow.com/a/715468 """ return val.lower() in ("yes", "y", "true", "t", "on", "1") - - -if hasattr(torch, "compile"): - # PyTorch 2.0+ - torch_compile = torch.compile -else: - # PyTorch 1.x - def torch_compile(*args, **kwargs): - """Fall back to jit script if using pytorch 1.x, args ignored""" - return torch.jit.script