Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vshampor committed May 8, 2023
1 parent f8e0d57 commit b7b94b6
Show file tree
Hide file tree
Showing 34 changed files with 77 additions and 71 deletions.
25 changes: 9 additions & 16 deletions docs/api/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import sys
from dataclasses import dataclass
from dataclasses import field
from typing import Any
from typing import Dict, List
from typing import Any, Dict, List

from sphinx.ext.autodoc import mock

Expand All @@ -17,9 +16,7 @@
author = "Intel Corporation"
release = "v2.4.0"

extensions = ["autoapi.extension",
"sphinx.ext.autodoc",
"sphinx.ext.linkcode"]
extensions = ["autoapi.extension", "sphinx.ext.autodoc", "sphinx.ext.linkcode"]

# The below line in conjunction with specifying the 'sphinx.ext.autodoc' as extension
# makes the type hints from the function signature disappear from the signature in the HTML and instead
Expand All @@ -30,11 +27,7 @@
autodoc_typehints = "description"

autoapi_dirs = ["../../../nncf"]
autoapi_options = ["members",
"show-inheritance",
"show-module-summary",
"special-members",
"imported-members"]
autoapi_options = ["members", "show-inheritance", "show-module-summary", "special-members", "imported-members"]

autoapi_template_dir = "_autoapi_templates"
autoapi_keep_files = True
Expand Down Expand Up @@ -161,21 +154,21 @@ def linkcode_resolve(domain, info):
# sphinx.ext.linkcode interface; will link to Github here.
target_ref = "develop"
base_url = f"https://github.com/openvinotoolkit/nncf/blob/{target_ref}/"
if not info['module']:
if not info["module"]:
return None
fullname = info["module"] + '.' + info["fullname"]
fullname = info["module"] + "." + info["fullname"]

if fullname not in api_info.api_names_vs_obj_dict:
# Got a method/property description, info["fullname"] contained class.method_name
fullname = fullname.rpartition('.')[0]
fullname = fullname.rpartition(".")[0]

if fullname in api_info.canonical_name_vs_fqn:
fullname = api_info.canonical_name_vs_fqn[fullname]
module_name = fullname.rpartition('.')[0]
module_name = fullname.rpartition(".")[0]
else:
module_name = info["module"]
filename = module_name.replace('.', '/')
complete_url = base_url + filename + '.py'
filename = module_name.replace(".", "/")
complete_url = base_url + filename + ".py"
return complete_url


Expand Down
5 changes: 3 additions & 2 deletions docs/styleguide/PyGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,11 @@ if __name__ == "__main__":
<a id="5-api-doc-rules"></a>
<a id="api-doc-rules"></a>
## 5 API documentation rules
All functions and classes that belong to NNCF API should be documented.
All functions and classes that belong to NNCF API should be documented.
The documentation should utilize the reStructuredText (.rst) format for specifying parameters, return types and otherwise formatting the docstring, since the docstring is used as a source for generating the HTML API documentation with Sphinx.

Argument descriptions for `__init__(...)` methods of API classes should be located in the docstring of the class itself, not the docstring of the `__init__(...)` method.
This is required so that the autogenerated API documentation is rendered properly.

If the autogenerated API documentation does not show type hints for certain arguments despite the fact that the type hints are present in the object's implementation code,
or if the type hints do not refer to the API symbol's canonical alias, then the type hint should be explicitly declared in the docstring using the `:type:` directive:
or if the type hints do not refer to the API symbol's canonical alias, then the type hint should be explicitly declared in the docstring using the `:type *param_name*:` directive (or `:rtype:` for return types).
1 change: 1 addition & 0 deletions nncf/api/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def maximal_compression_rate(self) -> float:
Returns the maximal model compression rate supported by the compression controller.
"""


@api()
class CompressionAlgorithmBuilder(ABC):
"""
Expand Down
2 changes: 1 addition & 1 deletion nncf/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-agnostic or backend-common NNCF functionality.
"""
"""
6 changes: 3 additions & 3 deletions nncf/common/accuracy_aware_training/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Accuracy Aware Training functionality.
"""

from nncf.common.accuracy_aware_training.training_loop import AccuracyAwareTrainingMode
from nncf.common.accuracy_aware_training.training_loop import create_accuracy_aware_training_loop
"""
Accuracy Aware Training functionality.
"""
52 changes: 25 additions & 27 deletions nncf/common/accuracy_aware_training/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
from abc import ABC
from abc import abstractmethod
from functools import partial
from typing import Callable
from typing import Optional
from typing import TypeVar
from typing import Union
from typing import Callable, Optional, TypeVar, Union

import numpy as np
from scipy.interpolate import interp1d
Expand Down Expand Up @@ -91,23 +88,24 @@ class BaseEarlyExitCompressionTrainingLoop(TrainingLoop, ABC):
"""
Base class to generalize functionality of derived training loop classes.
"""

def __init__(self, compression_controller: CompressionAlgorithmController):
self.runner = None # type: BaseAccuracyAwareTrainingRunner
self.compression_controller = compression_controller
self._current_compression_rate = None

def run(
self,
model: TModel,
train_epoch_fn: Callable,
validate_fn: Callable,
configure_optimizers_fn: Callable = None,
dump_checkpoint_fn: Callable = None,
load_checkpoint_fn: Callable = None,
early_stopping_fn: Callable = None,
tensorboard_writer: Optional[TensorboardWriterType] = None,
log_dir: Union[pathlib.Path, str] = None,
update_learning_rate_fn: Callable = None,
self,
model: TModel,
train_epoch_fn: Callable,
validate_fn: Callable,
configure_optimizers_fn: Callable = None,
dump_checkpoint_fn: Callable = None,
load_checkpoint_fn: Callable = None,
early_stopping_fn: Callable = None,
tensorboard_writer: Optional[TensorboardWriterType] = None,
log_dir: Union[pathlib.Path, str] = None,
update_learning_rate_fn: Callable = None,
):
self.runner.initialize_training_loop_fns(
train_epoch_fn,
Expand Down Expand Up @@ -275,7 +273,7 @@ def __init__(
verbose: bool = True,
minimal_compression_rate: float = 0.0,
maximal_compression_rate: float = 0.95,
dump_checkpoints: bool = True
dump_checkpoints: bool = True,
):
super().__init__(compression_controller)
self.adaptive_controller = self._get_adaptive_compression_ctrl(compression_controller)
Expand Down Expand Up @@ -334,17 +332,17 @@ def remove_registry_prefix(algo_name):
)

def run(
self,
model: TModel,
train_epoch_fn: Callable,
validate_fn: Callable,
configure_optimizers_fn: Callable = None,
dump_checkpoint_fn: Callable = None,
load_checkpoint_fn: Callable = None,
early_stopping_fn: Callable = None,
tensorboard_writer: Optional[TensorboardWriterType] = None,
log_dir: Union[pathlib.Path, str] = None,
update_learning_rate_fn: Callable = None,
self,
model: TModel,
train_epoch_fn: Callable,
validate_fn: Callable,
configure_optimizers_fn: Callable = None,
dump_checkpoint_fn: Callable = None,
load_checkpoint_fn: Callable = None,
early_stopping_fn: Callable = None,
tensorboard_writer: Optional[TensorboardWriterType] = None,
log_dir: Union[pathlib.Path, str] = None,
update_learning_rate_fn: Callable = None,
):
self.runner.initialize_training_loop_fns(
train_epoch_fn,
Expand Down
2 changes: 1 addition & 1 deletion nncf/common/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Functions and classes utilized during the user dataset-driven initialization of the compression algorithms.
"""
"""
2 changes: 2 additions & 0 deletions nncf/common/quantization/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class QuantizationMode:
:param SYMMETRIC:
:param ASYMMETRIC:
"""

SYMMETRIC = "symmetric"
ASYMMETRIC = "asymmetric"

Expand Down Expand Up @@ -321,6 +322,7 @@ class QuantizationPreset(Enum):
"""
An enum with values corresponding to the available quantization presets.
"""

PERFORMANCE = "performance"
MIXED = "mixed"

Expand Down
3 changes: 1 addition & 2 deletions nncf/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

from copy import deepcopy
from pathlib import Path
from typing import Dict
from typing import List, Optional, Type
from typing import Dict, List, Optional, Type

import jsonschema
import jstyleson as json
Expand Down
1 change: 1 addition & 0 deletions nncf/config/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ModelEvaluationArgs(NNCFExtraConfigStruct):
:param eval_fn: A function accepting a single argument - the model object - and returning the model's metric on
the evaluation split of the dataset corresponding to the model.
"""

def __init__(self, eval_fn: Callable):
self.eval_fn = eval_fn

Expand Down
2 changes: 1 addition & 1 deletion nncf/onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Base subpackage for NNCF ONNX functionality.
"""
"""
2 changes: 1 addition & 1 deletion nncf/openvino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Base subpackage for NNCF OpenVINO functionality.
"""
"""
10 changes: 6 additions & 4 deletions nncf/tensorflow/helpers/callback_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@


@api(canonical_alias="nncf.tensorflow.create_compression_callbacks")
def create_compression_callbacks(compression_ctrl: CompressionAlgorithmController,
log_tensorboard: bool = True,
log_text: bool = True,
log_dir: bool = None):
def create_compression_callbacks(
compression_ctrl: CompressionAlgorithmController,
log_tensorboard: bool = True,
log_text: bool = True,
log_dir: bool = None,
):
compression_controllers = (
compression_ctrl.child_ctrls
if isinstance(compression_ctrl, CompositeCompressionAlgorithmController)
Expand Down
2 changes: 1 addition & 1 deletion nncf/tensorflow/pruning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of pruning algorithms.
"""
"""
2 changes: 1 addition & 1 deletion nncf/tensorflow/pruning/filter_pruning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of filter-wise pruning.
"""
"""
1 change: 1 addition & 0 deletions nncf/tensorflow/quantization/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ class QuantizationController(BaseCompressionAlgorithmController):
"""
Controller for the quantization algorithm in TensorFlow.
"""

def __init__(self, target_model, config: NNCFConfig, op_names: List[str]):
super().__init__(target_model)
self._scheduler = BaseCompressionScheduler()
Expand Down
2 changes: 1 addition & 1 deletion nncf/tensorflow/sparsity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of sparsity algorithms.
"""
"""
2 changes: 1 addition & 1 deletion nncf/tensorflow/sparsity/magnitude/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of magnitude sparsity.
"""
"""
2 changes: 1 addition & 1 deletion nncf/tensorflow/sparsity/rb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of regularization-based (RB) sparsity.
"""
"""
1 change: 1 addition & 0 deletions nncf/tensorflow/sparsity/rb/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class RBSparsityController(BaseSparsityController):
"""
Controller class for regularization-based (RB) sparsity in TF.
"""

def __init__(self, target_model, config: NNCFConfig, op_names: List[str]):
super().__init__(target_model, op_names)
algo_config = extract_algo_specific_config(config, "rb_sparsity")
Expand Down
2 changes: 1 addition & 1 deletion nncf/torch/knowledge_distillation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of knowledge distillation algorithms.
"""
"""
1 change: 1 addition & 0 deletions nncf/torch/knowledge_distillation/algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class KnowledgeDistillationController(PTCompressionAlgorithmController):
"""
Controller for the knowledge distillation in PT.
"""

def __init__(
self, target_model: NNCFNetwork, original_model: nn.Module, kd_type: str, scale: float, temperature: float
):
Expand Down
2 changes: 1 addition & 1 deletion nncf/torch/pruning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of pruning algorithms.
"""
"""
2 changes: 1 addition & 1 deletion nncf/torch/pruning/filter_pruning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of filter-wise pruning.
"""
"""
2 changes: 2 additions & 0 deletions nncf/torch/quantization/algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ class QuantizationControllerBase(PTCompressionAlgorithmController):
"""
Base controller class for the quantization controllers in PT.
"""

def enable_activation_quantization(self):
raise NotImplementedError

Expand All @@ -1311,6 +1312,7 @@ class QuantizationController(QuantizationControllerBase):
"""
Controller for the quantization algorithm in PT.
"""

def __init__(
self,
target_model: NNCFNetwork,
Expand Down
2 changes: 1 addition & 1 deletion nncf/torch/sparsity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementations of sparsity algorithms.
"""
"""
1 change: 1 addition & 0 deletions nncf/torch/sparsity/base_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class BaseSparsityAlgoController(PTCompressionAlgorithmController, SparsityContr
"""
Base class for sparsity algorithm controllers in PT.
"""

def __init__(self, target_model: NNCFNetwork, sparsified_module_info: List[SparseModuleInfo]):
super().__init__(target_model)
self._loss = ZeroCompressionLoss(get_model_device(target_model))
Expand Down
2 changes: 1 addition & 1 deletion nncf/torch/sparsity/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementation of the auxiliary "constant" sparsity algorithm.
"""
"""
1 change: 1 addition & 0 deletions nncf/torch/sparsity/const/algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ConstSparsityController(BaseSparsityAlgoController):
"""
Controller for the auxiliary constant sparsity algorithm in PT.
"""

def freeze(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion nncf/torch/sparsity/magnitude/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.
"""
Backend-specific implementation of magnitude sparsity algorithm.
"""
"""
Loading

0 comments on commit b7b94b6

Please sign in to comment.