mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 14:45:38 +08:00
Backward compatibility for torch 1.x and fix for windows (#1962)
* backward compatibility for torch 1.x and fix for windows * Update pyproject.toml * Update README.md * Update README.md (As per request) --------- Co-authored-by: machenmusik <machenmusik@users.noreply.github.com>
This commit is contained in:
1 parent
c86ae8a07f
commit
3bc160cc7d
6 files changed
+33
-6
No files matched your search
@@ -21,6 +21,8 @@ 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"]
|
||||
@@ -197,7 +199,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,
|
||||
|
||||
@@ -17,6 +17,7 @@ Miscellaneous helper code.
|
||||
"""
|
||||
|
||||
|
||||
import platform
|
||||
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union
|
||||
|
||||
import torch
|
||||
@@ -158,3 +159,19 @@ def strtobool(val) -> bool:
|
||||
FMI https://stackoverflow.com/a/715468
|
||||
"""
|
||||
return val.lower() in ("yes", "y", "true", "t", "on", "1")
|
||||
|
||||
|
||||
def torch_compile(*args, **kwargs):
|
||||
"""
|
||||
Safe torch.compile with backward compatibility for PyTorch 1.x
|
||||
"""
|
||||
if not hasattr(torch, "compile"):
|
||||
# Backward compatibility for PyTorch 1.x
|
||||
return torch.jit.script
|
||||
elif platform.system() == "Windows":
|
||||
# torch.compile is not supported on Windows
|
||||
# https://github.com/orgs/pytorch/projects/27
|
||||
# TODO: @jkulhanek, remove this once torch.compile is supported on Windows
|
||||
return lambda x: x
|
||||
else:
|
||||
return torch.compile(*args, **kwargs)
|
||||
Reference in new issue
Block a user