mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-04 06:49:13 +08:00
Fix profiler for PyTorch 2.0 (#1812)
* Fix profiler for torch v2.0 * Add back type for time_function
This commit is contained in:
1 parent
d3fcca5215
commit
231573bd8e
1 file changed
+6
-4
@@ -20,13 +20,13 @@ from __future__ import annotations
|
|||||||
import functools
|
import functools
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import typing
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from contextlib import contextmanager
|
from contextlib import ContextDecorator, contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable, Dict, List, Optional, Tuple, Union
|
from typing import Callable, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from torch.autograd.profiler import ContextDecorator
|
|
||||||
from torch.profiler import ProfilerActivity, profile, record_function
|
from torch.profiler import ProfilerActivity, profile, record_function
|
||||||
|
|
||||||
from nerfstudio.configs import base_config as cfg
|
from nerfstudio.configs import base_config as cfg
|
||||||
@@ -46,8 +46,10 @@ PYTORCH_PROFILER = None
|
|||||||
class time_function(ContextDecorator): # pylint: disable=invalid-name
|
class time_function(ContextDecorator): # pylint: disable=invalid-name
|
||||||
"""Decorator/Context manager: time a function call or a block of code"""
|
"""Decorator/Context manager: time a function call or a block of code"""
|
||||||
|
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: Union[str, Callable]):
|
||||||
self.name = name
|
# NOTE: This is a workaround for the fact that the __new__ method of a ContextDecorator
|
||||||
|
# is not picked up by VSCode intellisense
|
||||||
|
self.name: str = typing.cast(str, name)
|
||||||
self.start = None
|
self.start = None
|
||||||
self._profiler_contexts = deque()
|
self._profiler_contexts = deque()
|
||||||
self._function_call_args: Optional[Tuple[Tuple, Dict]] = None
|
self._function_call_args: Optional[Tuple[Tuple, Dict]] = None
|
||||||
|
|||||||
Reference in new issue
Block a user