Fix typing errors (#229)

This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-07-29 14:17:38 -07:00
1 parent be001e8ebe
commit 58212543f5
30 files changed
+236 -147

No files matched your search

+1 -1
View File
@@ -122,7 +122,7 @@ class Config:
data: DataConfig = MISSING
graph: GraphConfig = MISSING
optimizers: Dict[str, Any] = MISSING
viewer: Dict[str, Any] = MISSING
viewer: ViewerConfig = MISSING
# additional optional parameters here
hydra: Optional[Dict[str, Any]] = None
+11 -7
View File
@@ -20,7 +20,7 @@ import hashlib
import json
from math import floor, log
from pydoc import locate
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, Union
import torch
from omegaconf import DictConfig
@@ -34,11 +34,11 @@ class DotDict(dict):
def __getattr__(self, attr):
return self[attr]
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
__setattr__ = dict.__setitem__ # type: ignore
__delattr__ = dict.__delitem__ # type: ignore
def get_dict_to_torch(stuff, device="cpu"):
def get_dict_to_torch(stuff, device: Union[torch.device, str] = "cpu"):
"""Set everything in the dict to the specified torch device."""
if isinstance(stuff, dict):
for k, v in stuff.items():
@@ -74,13 +74,17 @@ def get_masked_dict(d, mask):
return masked_dict
def instantiate_from_dict_config(dict_config: DictConfig, **kwargs):
"""Our version of hydra's instantiate function."""
def instantiate_from_dict_config(dict_config: Any, **kwargs):
"""Our version of hydra's instantiate function.
Args:
dict_config: DictConfig object to instantiate. It can be a dataclass or a dict but must have a `_target_` field.
"""
dict_config_kwargs = {k: v for k, v in dict_config.items() if k != "_target_"}
uninstantiated_class = locate(dict_config._target_) # pylint: disable=protected-access
all_kwargs = dict_config_kwargs
all_kwargs.update(kwargs)
instantiated_class = uninstantiated_class(**all_kwargs)
instantiated_class = uninstantiated_class(**all_kwargs) # type: ignore
return instantiated_class
+2 -2
View File
@@ -202,8 +202,8 @@ class TimeWriter:
self.step = step
self.write = write
self.start = None
self.duration = None
self.start: float = 0.0
self.duration: float = 0.0
def __enter__(self):
self.start = time()