mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-27 19:40:17 +08:00
Fix pickling of VanillaDataManager (#2129)
* Fix pickling of VanillaDataManager * Fix vanilladatamanager init
This commit is contained in:
1 parent
004d8ca9d2
commit
ac6a83cc53
3 files changed
+96
-13
No files matched your search
@@ -17,6 +17,8 @@ Miscellaneous helper code.
|
||||
"""
|
||||
|
||||
|
||||
from inspect import currentframe
|
||||
import typing
|
||||
import platform
|
||||
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union
|
||||
import warnings
|
||||
@@ -182,3 +184,32 @@ def torch_compile(*args, **kwargs):
|
||||
return lambda x: x
|
||||
else:
|
||||
return torch.compile(*args, **kwargs)
|
||||
|
||||
|
||||
def get_orig_class(obj, default=None):
|
||||
"""Returns the __orig_class__ class of `obj` even when it is not initialized in __init__ (Python>=3.8).
|
||||
|
||||
Workaround for https://github.com/python/typing/issues/658.
|
||||
Inspired by https://github.com/Stewori/pytypes/pull/53.
|
||||
"""
|
||||
try:
|
||||
return object.__getattribute__(obj, "__orig_class__")
|
||||
except AttributeError:
|
||||
cls = object.__getattribute__(obj, "__class__")
|
||||
try:
|
||||
is_type_generic = isinstance(cls, typing.GenericMeta) # type: ignore
|
||||
except AttributeError: # Python 3.8
|
||||
is_type_generic = issubclass(cls, typing.Generic)
|
||||
if is_type_generic:
|
||||
frame = currentframe().f_back.f_back # type: ignore
|
||||
try:
|
||||
while frame:
|
||||
try:
|
||||
res = frame.f_locals["self"]
|
||||
if res.__origin__ is cls:
|
||||
return res
|
||||
except (KeyError, AttributeError):
|
||||
frame = frame.f_back
|
||||
finally:
|
||||
del frame
|
||||
return default
|
||||
Reference in new issue
Block a user