Skip to content

Commit 348f6d8

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent d9bc957 commit 348f6d8

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

neural_compressor/common/utils/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
# limitations under the License.
1414

1515
from neural_compressor.common.utils.constants import *
16-
from neural_compressor.common.utils.logger import
16+
from neural_compressor.common.utils.logger import
1717
from neural_compressor.common.utils.save_load import save_qconfig, load_qconfig
1818

1919
# ! Put the following `utility` import after the `logger` import as `utility` used `logger`
2020
from neural_compressor.common.utils.utility import *
21-

neural_compressor/common/utils/save_load.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
import os
1918
import json
19+
import os
2020

2121

2222
def save_qconfig(config_mapping, qconfig_file_path):
@@ -35,8 +35,9 @@ def save_qconfig(config_mapping, qconfig_file_path):
3535
with open(qconfig_file_path, "w") as f:
3636
json.dump(per_op_qconfig, f, indent=4)
3737

38+
3839
def load_qconfig(qconfig_file_path, config_name_mapping):
39-
"""reload config mapping from json file.
40+
"""Reload config mapping from json file.
4041
4142
Args:
4243
qconfig_file_path (str): path to saved json file.

neural_compressor/torch/algorithms/habana_fp8/modules.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ def __init__(self, org_module, dtype) -> None:
301301
if org_module.bias is not None:
302302
self.bias.data.copy_(org_module.bias.data.type(self.out_dtype))
303303

304-
305304
def forward(self, inp):
306305
assert inp.shape[-1] == self.in_features, "GEMM not possible"
307306
org_middle_shape = inp.shape[1:-1]
@@ -638,6 +637,7 @@ def forward(self, inp):
638637
False,
639638
)
640639
from deepspeed import comm as dist
640+
641641
if self.mp_group is not None:
642642
dist.inference_all_reduce(out, group=self.mp_group)
643643
if self.bias is not None:
@@ -762,6 +762,7 @@ def forward(self, inp):
762762
False,
763763
)
764764
from deepspeed import comm as dist
765+
765766
if self.mp_group is not None:
766767
dist.inference_all_reduce(out, group=self.mp_group)
767768
if self.bias is not None:

neural_compressor/torch/algorithms/habana_fp8/save_load.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import habana_frameworks.torch.core as htcore
1919
import torch
2020

21-
from neural_compressor.torch.utils import logger, WEIGHT_NAME, QCONFIG_NAME
22-
from neural_compressor.common.utils import save_qconfig, load_qconfig
21+
from neural_compressor.common.utils import load_qconfig, save_qconfig
22+
from neural_compressor.torch.utils import QCONFIG_NAME, WEIGHT_NAME, logger
2323

2424
from .fp8_quant import FP8_DTYPE, dtype_mapping
2525
from .modules import ( # fp32; dynamic modules
@@ -62,7 +62,7 @@ def load(model, output_dir="./saved_results"):
6262
qmodel_file_path = os.path.join(os.path.abspath(os.path.expanduser(output_dir)), WEIGHT_NAME)
6363
stat_dict = torch.load(qmodel_file_path)
6464
import fp8_convert
65-
65+
6666
for (op_name, op_type), op_qconfig in model.qconfig.items():
6767
dtype = op_qconfig.w_dtype
6868
choice = 1 if dtype == "fp8_e4m3" else 0
@@ -90,7 +90,7 @@ def load(model, output_dir="./saved_results"):
9090
set_module(model, op_name, module)
9191
htcore.mark_step()
9292
model.load_state_dict(stat_dict, assign=True)
93-
model.to('hpu')
93+
model.to("hpu")
9494
htcore.mark_step()
9595
logger.info("Quantized model loading successful.")
9696
return model

neural_compressor/torch/quantization/algorithm_entry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
from neural_compressor.common.utils import AWQ, FP8_QUANT, GPTQ, HQQ, RTN, STATIC_QUANT, TEQ
2222
from neural_compressor.torch.quantization import (
2323
AWQConfig,
24+
FP8Config,
2425
GPTQConfig,
2526
HQQConfig,
2627
RTNConfig,
27-
TEQConfig,
2828
StaticQuantConfig,
29-
FP8Config,
29+
TEQConfig,
3030
)
3131
from neural_compressor.torch.utils import logger, register_algo
3232

neural_compressor/torch/quantization/load_entry.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
import json
1616
import os
1717

18-
from neural_compressor.common.utils import load_qconfig # unified namespace
1918
from neural_compressor.common.utils import FP8_QUANT # unified namespace
19+
from neural_compressor.common.utils import load_qconfig # unified namespace
2020
from neural_compressor.torch.quantization.config import FP8Config
21+
2122
config_name_mapping = {
2223
FP8_QUANT: FP8Config,
2324
}
2425

26+
2527
def load(model, output_dir="./saved_results"):
2628
qconfig_file_path = os.path.join(os.path.abspath(os.path.expanduser(output_dir)), "qconfig.json")
2729
config_mapping = load_qconfig(qconfig_file_path, config_name_mapping)

0 commit comments

Comments
 (0)