Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
replenish docstring
Signed-off-by: xin3he <[email protected]>
  • Loading branch information
xin3he committed Jul 26, 2024
commit efe50eb7bb9ee58e991852fba601a1218fd8d720
12 changes: 7 additions & 5 deletions .azure-pipelines/scripts/codeScan/pydocstyle/scan_path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
/neural-compressor/neural_compressor/strategy
/neural-compressor/neural_compressor/training.py
/neural-compressor/neural_compressor/utils
/neural_compressor/torch/algorithms/layer_wise
/neural_compressor/torch/algorithms/mixed_precision
/neural_compressor/torch/algorithms/mx_quant
/neural-compressor/neural_compressor/torch/algorithms/static_quant
/neural-compressor/neural_compressor/torch/algorithms/smooth_quant
/neural_compressor/torch/algorithms/pt2e_quant
/neural-compressor/neural_compressor/torch/algorithms/smooth_quant
/neural-compressor/neural_compressor/torch/algorithms/static_quant
/neural_compressor/torch/algorithms/weight_only
/neural_compressor/torch/export
/neural_compressor/torch/quantization
/neural_compressor/torch/utils
/neural_compressor/common
/neural_compressor/torch/algorithms/weight_only
/neural_compressor/torch/algorithms/layer_wise
/neural_compressor/torch/algorithms/mixed_precision
/neural_compressor/tensorflow
2 changes: 1 addition & 1 deletion neural_compressor/torch/quantization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
"""Intel Neural Compressor Pytorch quantization API."""
"""Intel Neural Compressor PyTorch quantization API."""

from neural_compressor.torch.quantization.quantize import quantize, prepare, convert
from neural_compressor.torch.quantization.config import (
Expand Down
1 change: 1 addition & 0 deletions neural_compressor/torch/quantization/algorithm_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 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.
"""Intel Neural Compressor PyTorch supported algorithm entries."""

from copy import deepcopy
from types import MethodType
Expand Down
138 changes: 128 additions & 10 deletions neural_compressor/torch/quantization/config.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion neural_compressor/torch/quantization/load_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 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.
"""Intel Neural Compressor PyTorch load entry for all algorithms."""

import json
import os
Expand Down Expand Up @@ -54,7 +55,6 @@ def load(model_name_or_path, original_model=None, format="default", device="cpu"
from neural_compressor.torch.quantization import load
load(model_name_or_path=model_name_or_path)


Args:
model_name_or_path (str): torch checkpoint directory or hugginface model_name_or_path.
If 'format' is set to 'huggingface', it means the huggingface model_name_or_path.
Expand All @@ -70,6 +70,7 @@ def load(model_name_or_path, original_model=None, format="default", device="cpu"
kwargs (remaining dictionary of keyword arguments, optional):
remaining dictionary of keyword arguments for loading huggingface models.
Will be passed to the huggingface model's `__init__` method, such as 'trust_remote_code', 'revision'.

Returns:
The quantized model
"""
Expand Down
9 changes: 9 additions & 0 deletions neural_compressor/torch/quantization/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@


def need_apply(configs_mapping: Dict[Tuple[str, callable], BaseConfig], algo_name):
"""Check whether to apply this algorithm according to configs_mapping.

Args:
configs_mapping (Dict[Tuple[str, callable], BaseConfig]): configs mapping
algo_name (str): algo name

Returns:
Bool: True or False.
"""
return any(config.name == algo_name for config in configs_mapping.values())


Expand Down
1 change: 1 addition & 0 deletions neural_compressor/torch/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 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.
"""Intel Neural Compressor PyTorch related utility modules."""

from .environ import *
from .constants import *
Expand Down
5 changes: 3 additions & 2 deletions neural_compressor/torch/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,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.

"""Intel Neural Compressor PyTorch constants."""

# double quant params

DOUBLE_QUANT_CONFIGS = {
"BNB_NF4": {
"dtype": "nf4",
Expand Down Expand Up @@ -60,6 +59,8 @@


class LoadFormat(Enum):
"""Load API formats for different usages."""

DEFAULT = "default"
HUGGINGFACE = "huggingface"

Expand Down
1 change: 1 addition & 0 deletions neural_compressor/torch/utils/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# 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.
"""Intel Neural Compressor PyTorch environment check."""

import importlib
import sys
Expand Down
7 changes: 3 additions & 4 deletions neural_compressor/torch/utils/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 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.
"""Intel Neural Compressor PyTorch utilities."""


import enum
Expand Down Expand Up @@ -185,13 +186,11 @@ def postprocess_model(model, mode, quantizer):


def dump_model_op_stats(mode, tune_cfg):
"""This is a function to dump quantizable ops of model to user.
"""Dump quantizable ops stats of model to user.

Args:
model (object): input model
mode (object): quantization mode.
tune_cfg (dict): quantization config
Returns:
None
"""
if mode == Mode.PREPARE:
return
Expand Down