Switch to ruff (#1939)

* `isort` -> `ruff`

* `pylint` -> `ruff`

* Remove line

* More minor cleanup

* Better documentation for rules we are enabling

* Fix gitignore, run black

* vscode settings

---------

Co-authored-by: Matt Tancik <mattt4001@gmail.com>
This commit is contained in:
Brent YiandMatt Tancik authored and GitHub committed 2023-05-17 10:08:14 -07:00
1 parent 814db32ec4
commit d542646c72
79 files changed
+158 -237

No files matched your search

+1 -1
View File
@@ -71,7 +71,7 @@ def get_masked_dict(d, mask):
return masked_dict
class IterableWrapper: # pylint: disable=too-few-public-methods
class IterableWrapper:
"""A helper that will allow an instance of a class to return multiple kinds of iterables bound
to different functions of that class.
+1 -1
View File
@@ -46,7 +46,7 @@ def inverse(pose: Float[Tensor, "*batch 3 4"]) -> Float[Tensor, "*batch 3 4"]:
"""
R = pose[..., :3, :3]
t = pose[..., :3, 3:]
R_inverse = R.transpose(-2, -1) # pylint: disable=invalid-name
R_inverse = R.transpose(-2, -1)
t_inverse = -R_inverse.matmul(t)
return torch.cat([R_inverse, t_inverse], dim=-1)
+4 -4
View File
@@ -77,7 +77,7 @@ def time_function(name_or_func: Union[CallableT, str]) -> Union[CallableT, Conte
return _TimeFunction(name_or_func)
class _TimeFunction(ContextDecorator): # pylint: disable=invalid-name
class _TimeFunction(ContextDecorator):
"""Decorator/Context manager: time a function call or a block of code"""
def __init__(self, name: Union[str, Callable]):
@@ -105,7 +105,7 @@ class _TimeFunction(ContextDecorator): # pylint: disable=invalid-name
if self._function_call_args is not None:
args, kwargs = self._function_call_args
ctx = PYTORCH_PROFILER.record_function(self.name, *args, **kwargs)
ctx.__enter__() # pylint: disable=no-member
ctx.__enter__()
self._profiler_contexts.append(ctx)
if self._function_call_args is None:
ctx = record_function(self.name)
@@ -139,14 +139,14 @@ def flush_profiler(config: cfg.LoggingConfig):
def setup_profiler(config: cfg.LoggingConfig, log_dir: Path):
"""Initialization of profilers"""
global PYTORCH_PROFILER # pylint: disable=global-statement
global PYTORCH_PROFILER
if comms.is_main_process():
PROFILER.append(Profiler(config))
if config.profiler == "pytorch":
PYTORCH_PROFILER = PytorchProfiler(log_dir)
class PytorchProfiler: # pylint: disable=too-few-public-methods
class PytorchProfiler:
"""
Wrapper for Pytorch Profiler
"""
+3 -5
View File
@@ -107,7 +107,6 @@ class TensorDataclass:
for k, v in dict_.items():
if isinstance(v, torch.Tensor):
if isinstance(self._field_custom_dimensions, dict) and k in self._field_custom_dimensions:
# pylint: disable=unsubscriptable-object
batch_shapes.append(v.shape[: -self._field_custom_dimensions[k]])
else:
batch_shapes.append(v.shape[:-1])
@@ -131,7 +130,6 @@ class TensorDataclass:
if isinstance(v, torch.Tensor):
# If custom dimension key, then we need to
if isinstance(self._field_custom_dimensions, dict) and k in self._field_custom_dimensions:
# pylint: disable=unsubscriptable-object
new_dict[k] = v.broadcast_to(
(
*batch_shape,
@@ -160,7 +158,7 @@ class TensorDataclass:
return x[indices]
def custom_tensor_dims_fn(k, v):
custom_dims = self._field_custom_dimensions[k] # pylint: disable=unsubscriptable-object
custom_dims = self._field_custom_dimensions[k]
return v[indices + ((slice(None),) * custom_dims)]
return self._apply_fn_to_fields(tensor_fn, dataclass_fn, custom_tensor_dims_fn=custom_tensor_dims_fn)
@@ -219,7 +217,7 @@ class TensorDataclass:
return x.reshape(shape)
def custom_tensor_dims_fn(k, v):
custom_dims = self._field_custom_dimensions[k] # pylint: disable=unsubscriptable-object
custom_dims = self._field_custom_dimensions[k]
return v.reshape((*shape, *v.shape[-custom_dims:]))
return self._apply_fn_to_fields(tensor_fn, dataclass_fn, custom_tensor_dims_fn=custom_tensor_dims_fn)
@@ -246,7 +244,7 @@ class TensorDataclass:
"""
def custom_tensor_dims_fn(k, v):
custom_dims = self._field_custom_dimensions[k] # pylint: disable=unsubscriptable-object
custom_dims = self._field_custom_dimensions[k]
return v.broadcast_to((*shape, *v.shape[-custom_dims:]))
return self._apply_fn_to_fields(
+1 -3
View File
@@ -315,8 +315,6 @@ class WandbWriter(Writer):
wandb.log({name: scalar}, step=step)
def write_config(self, name: str, config_dict: Dict[str, Any], step: int):
# pylint: disable=unused-argument
# pylint: disable=no-self-use
"""Function that writes out the config to wandb
Args:
@@ -339,7 +337,7 @@ class TensorboardWriter(Writer):
def write_scalar(self, name: str, scalar: Union[float, torch.Tensor], step: int) -> None:
self.tb_writer.add_scalar(name, scalar, step)
def write_config(self, name: str, config_dict: Dict[str, Any], step: int): # pylint: disable=unused-argument
def write_config(self, name: str, config_dict: Dict[str, Any], step: int):
"""Function that writes out the config to tensorboard
Args: