Skip to content

Commit 954d59a

Browse files
authored
fix coverity issues (#1263)
1 parent 05540e6 commit 954d59a

File tree

8 files changed

+7
-21
lines changed

8 files changed

+7
-21
lines changed

csrc/cpu/aten/Matmul.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,11 @@ at::Tensor matmul_impl(
373373
// We are multiplying b1 x n x m1 by x2 x m2 x p (where b1 can be a list);
374374
// we track m1 vs m2 separately even though they must match for nicer error
375375
// messages
376-
int64_t n = dim_tensor1 > 1 ? tensor1.size(-2) : 1;
376+
int64_t n = tensor1.size(-2);
377377
int64_t m1 = tensor1.size(-1);
378378
c10::IntArrayRef batch_tensor1(
379379
tensor1.sizes().data(), std::max<int64_t>(dim_tensor1 - 2, 0));
380-
int64_t m2 = dim_tensor2 > 1 ? tensor2.size(-2) : 1;
380+
int64_t m2 = tensor2.size(-2);
381381
int64_t p = tensor2.size(-1);
382382
c10::IntArrayRef batch_tensor2(
383383
tensor2.sizes().data(), std::max<int64_t>(dim_tensor2 - 2, 0));

csrc/cpu/utils/fpmath_mode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dnnl_fpmath_mode_t fpmath_mode = []() {
2121
}();
2222

2323
void setFP32MathModeCpu(FP32MathMode m) {
24-
dnnl_fpmath_mode_t mode;
24+
dnnl_fpmath_mode_t mode = dnnl_fpmath_mode_strict;
2525
if (m == FP32MathMode::FP32) {
2626
mode = dnnl_fpmath_mode_strict;
2727
} else if (m == FP32MathMode::BF32) {

csrc/jit/cpu/kernels/Einsum.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ static Tensor sumproduct_pair(
293293
auto min_size = std::min(lo_count, ro_count);
294294
auto max_size = std::max(lo_count, ro_count);
295295
for (int i = dim - 1; i >= dim - max_size; i--) {
296-
if (left_shape[i] == 1 && left_shape[i] == right_shape[i] &&
297-
min_size >= 0) {
296+
if (left_shape[i] == 1 && left_shape[i] == right_shape[i]) {
298297
right_shape.pop_back();
299298
left_shape.pop_back();
300299
min_size--;

intel_extension_for_pytorch/quantization/_quantization_state_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import dataclasses
22
from typing import Callable, Tuple, Any, List, Optional, Dict
33
import torch
4-
import torch.nn as nn
54
import torch.nn.functional as F
65
import torch.nn.quantized.dynamic as nnqd
76
from intel_extension_for_pytorch.nn.functional import interaction
@@ -344,7 +343,7 @@ def iterate_and_apply_convert(
344343
args = args.to(torch.float32)
345344
args = torch.quantize_per_channel(args, scale, zp, ch_axis, dtype)
346345
args = args.dequantize()
347-
args = arg.to(torch.bfloat16)
346+
args = args.to(torch.bfloat16)
348347
else:
349348
args = torch.quantize_per_channel(args, scale, zp, ch_axis, dtype)
350349
args = args.dequantize()

setup.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@
6666
import subprocess
6767
import sys
6868
from pathlib import Path
69-
import warnings
70-
import urllib.request
7169
import re
7270

7371
try:
@@ -132,7 +130,6 @@
132130
mkl_header = glob.glob(f'{mkl_install_dir}/include/**/mkl_version.h', recursive = True)
133131
if len(mkl_header) == 0:
134132
raise RuntimeError(f'{mkl_install_dir} doesn\'t seem to be a valid MKL library directory.\n{" ":14}mkl_version.h not found.')
135-
mkl_install_dir = ''
136133
else:
137134
mkl_header = mkl_header[0]
138135
mkl_major = 0
@@ -152,11 +149,9 @@
152149
mkl_version = f'{mkl_major}.{mkl_minor}.{mkl_patch}'
153150
if pkg_ver.parse(mkl_version) < pkg_ver.parse('2021.0.0'):
154151
raise RuntimeError(f'MKL version({mkl_version}) is not supported. Please use MKL later than 2021.0.0.')
155-
mkl_install_dir = ''
156152
mkl_library = glob.glob(f'{mkl_install_dir}/lib/**/libmkl_core.a', recursive = True)
157153
if len(mkl_library) == 0:
158154
raise RuntimeError(f'libmkl_core.a not found in {mkl_install_dir}/lib/intel64.')
159-
mkl_install_dir = ''
160155
if not mkl_install_dir:
161156
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'mkl-include>=2021.0.0'])
162157
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--no-deps', 'mkl-static>=2021.0.0'])

tests/cpu/test_autocast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _test_lstm_pack_padded_sequence(self):
557557
batch_size = 24
558558
num_layers = 1
559559
bidirectional = True
560-
num_direc = 2 if bidirectional else 1
560+
num_direc = 2
561561
max_lens = 96
562562

563563
sent = torch.randn(batch_size, max_lens, embedding_dim)

tests/cpu/test_softmax.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import torch
22
import torch.nn as nn
33
import intel_extension_for_pytorch as ipex
4-
from common_utils import TestCase
54
from torch.testing._internal.jit_utils import JitTestCase
65
import intel_extension_for_pytorch as ipex
76
from intel_extension_for_pytorch.quantization import prepare, convert
@@ -40,10 +39,7 @@ def __init__(self):
4039
super().__init__()
4140
def forward(self, x, flag):
4241
if flag:
43-
if flag:
4442
x1 = x + 1
45-
else:
46-
x1 = x + 2
4743
else:
4844
x1 = x + 3
4945
x2 = torch.softmax(x1, dim=-1)

tests/cpu/test_weight_prepack.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,10 +1110,7 @@ def forward(self, x, h=None):
11101110

11111111
num_directions = 2 if bidirectional else 1
11121112

1113-
if batch_first:
1114-
input = torch.randn(batch_size, seq_len, input_size)
1115-
else:
1116-
input = torch.randn(seq_len, batch_size, input_size)
1113+
input = torch.randn(batch_size, seq_len, input_size)
11171114
h = torch.randn(num_layers * num_directions, batch_size, hidden_size)
11181115
c = torch.randn(num_layers * num_directions, batch_size, hidden_size)
11191116

0 commit comments

Comments
 (0)