Skip to content

Commit

Permalink
Add deprecation decorator in experimental fold (#1402)
Browse files Browse the repository at this point in the history
Signed-off-by: Cheng, Penghui <penghui.cheng@intel.com>
  • Loading branch information
PenghuiCheng authored Nov 22, 2023
1 parent db0fef7 commit aeb3ed2
Show file tree
Hide file tree
Showing 66 changed files with 299 additions and 46 deletions.
10 changes: 10 additions & 0 deletions neural_compressor/experimental/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import numpy as np
import psutil
from deprecated import deprecated

from ..adaptor import FRAMEWORKS
from ..conf.config import BenchmarkConf
Expand All @@ -43,6 +44,7 @@
from .metric import METRICS


@deprecated(version="2.0")
def set_env_var(env_var, value, overwrite_existing=False):
"""Set the specified environment variable.
Expand All @@ -54,6 +56,7 @@ def set_env_var(env_var, value, overwrite_existing=False):
os.environ[env_var] = str(value)


@deprecated(version="2.0")
def set_all_env_var(conf, overwrite_existing=False):
"""Set all the environment variables with the configuration dict.
Expand All @@ -76,6 +79,7 @@ def set_all_env_var(conf, overwrite_existing=False):
set_env_var(var.upper(), value, overwrite_existing)


@deprecated(version="2.0")
def get_architecture():
"""Get the architecture name of the system."""
p1 = subprocess.Popen("lscpu", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -87,6 +91,7 @@ def get_architecture():
return res


@deprecated(version="2.0")
def get_threads_per_core():
"""Get the threads per core."""
p1 = subprocess.Popen("lscpu", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -98,6 +103,7 @@ def get_threads_per_core():
return res


@deprecated(version="2.0")
def get_threads():
"""Get the list of threads."""
p1 = subprocess.Popen(["cat", "/proc/cpuinfo"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -109,6 +115,7 @@ def get_threads():
return res


@deprecated(version="2.0")
def get_physical_ids():
"""Get the list of sockets."""
p1 = subprocess.Popen(["cat", "/proc/cpuinfo"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -120,6 +127,7 @@ def get_physical_ids():
return res


@deprecated(version="2.0")
def get_core_ids():
"""Get the ids list of the cores."""
p1 = subprocess.Popen(["cat", "/proc/cpuinfo"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -131,6 +139,7 @@ def get_core_ids():
return res


@deprecated(version="2.0")
def get_bounded_threads(core_ids, threads, sockets):
"""Return the threads id list that we will bind instances to."""
res = []
Expand All @@ -143,6 +152,7 @@ def get_bounded_threads(core_ids, threads, sockets):
return res


@deprecated(version="2.0")
class Benchmark(object):
"""Benchmark class is used to evaluate the model performance with the objective settings.
Expand Down
14 changes: 14 additions & 0 deletions neural_compressor/experimental/common/criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from collections import Counter

import numpy as np
from deprecated import deprecated

from neural_compressor.adaptor.pytorch import pytorch_forward_wrapper
from neural_compressor.utils import logger
Expand All @@ -34,6 +35,7 @@
tf = LazyImport("tensorflow")


@deprecated(version="2.0")
@singleton
class TensorflowCriterions(object):
"""Record criterions in TensorflowCriterions class."""
Expand All @@ -44,6 +46,7 @@ def __init__(self):
self.criterions.update(TENSORFLOW_CRITERIONS)


@deprecated(version="2.0")
@singleton
class PyTorchCriterions(object):
"""Record criterions in PyTorchCriterions class."""
Expand Down Expand Up @@ -71,6 +74,7 @@ def __init__(self):
}


@deprecated(version="2.0")
class Criterions(object):
"""Integrate criterions of different framework."""

Expand Down Expand Up @@ -107,6 +111,7 @@ def register(self, name, criterion_cls):
self.criterions.update({name: criterion_cls})


@deprecated(version="2.0")
def criterion_registry(criterion_type, framework):
"""Use to register criterion classes in registry_criterions.
Expand All @@ -131,6 +136,7 @@ def decorator_criterion(cls):
return decorator_criterion


@deprecated(version="2.0")
class KnowledgeDistillationFramework(object):
"""Knowledge Distillation Framework."""

Expand Down Expand Up @@ -165,6 +171,7 @@ def teacher_model(self, model):
self._teacher_model = model


@deprecated(version="2.0")
class KnowledgeDistillationLoss(KnowledgeDistillationFramework):
"""Initialize the KnowledgeDistillationLoss class."""

Expand Down Expand Up @@ -280,6 +287,7 @@ def __call__(self, student_outputs, targets):
return self.loss_cal(student_outputs, targets)


@deprecated(version="2.0")
class PyTorchKnowledgeDistillationLoss(KnowledgeDistillationLoss):
"""The PyTorchKnowledgeDistillationLoss class inherits from KnowledgeDistillationLoss."""

Expand Down Expand Up @@ -418,6 +426,7 @@ def student_targets_loss_cal(self, student_outputs, targets):
return self.student_targets_loss(student_outputs, targets)


@deprecated(version="2.0")
@criterion_registry("KnowledgeDistillationLoss", "pytorch")
class PyTorchKnowledgeDistillationLossWrapper(object):
"""PyTorchKnowledgeDistillationLossWrapper wraps PyTorchKnowledgeDistillationLoss."""
Expand Down Expand Up @@ -463,6 +472,7 @@ def __call__(self, **kwargs):
return PyTorchKnowledgeDistillationLoss, self._param_check()


@deprecated(version="2.0")
class TensorflowKnowledgeDistillationLossExternal(KnowledgeDistillationLoss):
"""TensorflowKnowledgeDistillationLossExternal inherits from KnowledgeDistillationLoss."""

Expand Down Expand Up @@ -560,6 +570,7 @@ def student_targets_loss_cal(self, student_outputs, targets):
return self.student_targets_loss(targets, student_outputs)


@deprecated(version="2.0")
class IntermediateLayersKnowledgeDistillationLoss(KnowledgeDistillationFramework):
"""The IntermediateLayersKnowledgeDistillationLoss class inherits from KnowledgeDistillationLoss."""

Expand Down Expand Up @@ -704,6 +715,7 @@ def __call__(self, student_outputs, targets):
return 0


@deprecated(version="2.0")
class PyTorchIntermediateLayersKnowledgeDistillationLoss(IntermediateLayersKnowledgeDistillationLoss):
"""PyTorch Intermediate Layers Knowledge Distillation Loss."""

Expand Down Expand Up @@ -947,6 +959,7 @@ def device2feature_gen(features):
return self.loss


@deprecated(version="2.0")
@criterion_registry("IntermediateLayersKnowledgeDistillationLoss", "pytorch")
class PyTorchIntermediateLayersKnowledgeDistillationLossWrapper(object):
"""PyTorch Intermediate Layers Knowledge Distillation Loss Wrapper."""
Expand Down Expand Up @@ -1020,6 +1033,7 @@ def __call__(self, **kwargs):
return PyTorchIntermediateLayersKnowledgeDistillationLoss, self._param_check()


@deprecated(version="2.0")
class SelfKnowledgeDistillationLoss(KnowledgeDistillationFramework):
"""SelfKnowledge Distillation Loss."""

Expand Down
3 changes: 3 additions & 0 deletions neural_compressor/experimental/common/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common DataLoader just collects the information to construct a dataloader."""
from deprecated import deprecated

from ..data import DATALOADERS


@deprecated(version="2.0")
class DataLoader(object):
"""A wrapper of the information needed to construct a dataloader.
Expand Down Expand Up @@ -81,6 +83,7 @@ def __init__(
self.distributed = distributed


@deprecated(version="2.0")
def _generate_common_dataloader(dataloader, framework, distributed=False):
"""Generate common dataloader.
Expand Down
2 changes: 2 additions & 0 deletions neural_compressor/experimental/common/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common Metric just collects the information to construct a Metric."""
from deprecated import deprecated


@deprecated(version="2.0")
class Metric(object):
"""A wrapper of the information needed to construct a Metric.
Expand Down
3 changes: 3 additions & 0 deletions neural_compressor/experimental/common/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common Model just collects the information to construct a Model."""
from deprecated import deprecated

from neural_compressor.model.model import MODELS, get_model_fwk_name
from neural_compressor.model.tensorflow_model import get_model_type
Expand All @@ -23,6 +24,7 @@
BACKEND = "default"


@deprecated(version="2.0")
class Model(object):
"""A wrapper of the information needed to construct a Model."""

Expand Down Expand Up @@ -63,6 +65,7 @@ def __new__(cls, root, **kwargs):
return model


@deprecated(version="2.0")
def set_backend(backend: str):
"""Set backed from configure file."""
global BACKEND
Expand Down
9 changes: 8 additions & 1 deletion neural_compressor/experimental/common/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# ==============================================================================
"""Intel Neural Compressor built-in Optimizers on multiple framework backends."""

from abc import abstractmethod
from deprecated import deprecated

from neural_compressor.utils.utility import LazyImport, singleton

Expand All @@ -26,6 +26,7 @@
tfa = LazyImport("tensorflow_addons")


@deprecated(version="2.0")
@singleton
class TensorflowOptimizers(object):
"""Class to get all registered TensorFlow Optimizers once only."""
Expand All @@ -36,6 +37,7 @@ def __init__(self):
self.optimizers.update(TENSORFLOW_OPTIMIZERS)


@deprecated(version="2.0")
@singleton
class PyTorchOptimizers(object):
"""Class to get all registered PyTorch Optimizers once only."""
Expand Down Expand Up @@ -63,6 +65,7 @@ def __init__(self):
}


@deprecated(version="2.0")
class Optimizers(object):
"""Main entry to get the specific type of optimizer."""

Expand All @@ -83,6 +86,7 @@ def register(self, name, optimizer_cls):
self.optimizers.update({name: optimizer_cls})


@deprecated(version="2.0")
def optimizer_registry(optimizer_type, framework):
"""Class decorator used to register all Optimizer subclasses.
Expand All @@ -108,6 +112,7 @@ def decorator_optimizer(cls):
return decorator_optimizer


@deprecated(version="2.0")
@optimizer_registry("SGD", "tensorflow")
class TensorFlowSGD(object):
"""TensorFlow keras SGD optimizer.
Expand All @@ -134,6 +139,7 @@ def __call__(self, **kwargs):
return tf.keras.optimizers.SGD, self._mapping(**kwargs)


@deprecated(version="2.0")
@optimizer_registry("AdamW", "tensorflow")
class TensorFlowAdamW(object):
"""tensorflow_addons AdamW optimizer.
Expand Down Expand Up @@ -167,6 +173,7 @@ def __call__(self, **kwargs):
return tfa.optimizers.AdamW, self._mapping(**kwargs)


@deprecated(version="2.0")
@optimizer_registry("SGD", "pytorch")
class PyTorchSGD(object):
"""PyTorch SGD optimizer.
Expand Down
2 changes: 2 additions & 0 deletions neural_compressor/experimental/common/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common Postprocess."""
from deprecated import deprecated


@deprecated(version="2.0")
class Postprocess(object):
# class Transform(object):
"""Just collect the infos to construct a Postprocess."""
Expand Down
3 changes: 3 additions & 0 deletions neural_compressor/experimental/common/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""This is an utility file for PyTorch distillation."""
from deprecated import deprecated

from neural_compressor.utils.utility import LazyImport

Expand All @@ -25,6 +26,7 @@


# for adapting fx model
@deprecated(version="2.0")
@torch.fx.wrap
def record_output(output, name, output_process, student=False):
"""Record layers output.
Expand Down Expand Up @@ -53,6 +55,7 @@ def record_output(output, name, output_process, student=False):
return output


@deprecated(version="2.0")
def get_activation(name, output_process="", student=False):
"""Get a hook for getting activation."""

Expand Down
1 change: 1 addition & 0 deletions neural_compressor/experimental/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from .common import Model


@deprecated(version="2.0")
class Component(object):
"""This is base class of Neural Compressor Component.
Expand Down
3 changes: 3 additions & 0 deletions neural_compressor/experimental/contrib/strategy/sigopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import copy
from collections import OrderedDict

from deprecated import deprecated

from neural_compressor.experimental.strategy.strategy import TuneStrategy, strategy_registry
from neural_compressor.experimental.strategy.utils.tuning_sampler import OpWiseTuningSampler
from neural_compressor.experimental.strategy.utils.tuning_structs import OpTuningConfig
Expand All @@ -27,6 +29,7 @@
sigopt = LazyImport("sigopt")


@deprecated(version="2.0")
@strategy_registry
class SigOptTuneStrategy(TuneStrategy):
"""The tuning strategy using SigOpt HPO search in tuning space.
Expand Down
2 changes: 2 additions & 0 deletions neural_compressor/experimental/contrib/strategy/tpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pathlib import Path

import numpy as np
from deprecated import deprecated

from neural_compressor.experimental.strategy.strategy import TuneStrategy, strategy_registry
from neural_compressor.experimental.strategy.utils.tuning_sampler import OpWiseTuningSampler
Expand All @@ -38,6 +39,7 @@
logger.info("Pandas package is required for best result and CSV files generation.")


@deprecated(version="2.0")
@strategy_registry
class TpeTuneStrategy(TuneStrategy):
"""The tuning strategy using tpe search in tuning space.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

from abc import abstractmethod

from deprecated import deprecated


@deprecated(version="2.0")
class BaseDataLoader:
"""Base class for all DataLoaders.
Expand Down
Loading

0 comments on commit aeb3ed2

Please sign in to comment.