Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit f4cb593

Browse files
authored
Adding quality check action (#165)
1 parent cf441a7 commit f4cb593

File tree

22 files changed

+70
-48
lines changed

22 files changed

+70
-48
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Quality Checks
2+
on: [push]
3+
jobs:
4+
quality-check:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- name: "⚙️ Install dependencies"
9+
run: pip3 install .[dev]
10+
- name: "🧹 Running quality checks"
11+
run: make quality

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ limitations under the License.
1616

1717
# ![icon for SparseMl](https://raw.githubusercontent.com/neuralmagic/sparseml/main/docs/source/icon-sparseml.png) SparseML
1818

19+
20+
[![quality-check Actions Status](https://github.com/neuralmagic/sparseml/actions/workflows/quality-check.yaml/badge.svg)](https://github.com/neuralmagic/sparseml/actions)
21+
1922
### Libraries for applying sparsification recipes to neural networks with a few lines of code, enabling faster and smaller models
2023

2124
<p>

integrations/transformers/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<!--
22
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
3+
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.
56
You may obtain a copy of the License at
7+
68
http://www.apache.org/licenses/LICENSE-2.0
9+
710
Unless required by applicable law or agreed to in writing,
811
software distributed under the License is distributed on an "AS IS" BASIS,
912
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1013
See the License for the specific language governing permissions and
11-
lim itations under the License.
14+
limitations under the License.
1215
-->
1316
# Transformers-SparseML Integration
1417
This folder contains an example on how to use sparseml with transformers.

integrations/transformers/trainer_qa.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
16+
# neuralmagic: no copyright
17+
# isort: skip_file
18+
# flake8: noqa
19+
# fmt: off
20+
1521
"""
1622
A subclass of `Trainer` specific to Question-Answering tasks
1723
"""

integrations/transformers/utils_qa.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
16+
# neuralmagic: no copyright
17+
# isort: skip_file
18+
# flake8: noqa
19+
# fmt: off
20+
1521
"""
1622
Post-processing utilities for question answering.
1723
"""
@@ -421,4 +427,4 @@ def postprocess_qa_predictions_with_beam_search(
421427
with open(null_odds_file, "w") as writer:
422428
writer.write(json.dumps(scores_diff_json, indent=4) + "\n")
423429

424-
return all_predictions, scores_diff_json
430+
return all_predictions, scores_diff_json

integrations/ultralytics/deepsparse/benchmark.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@
102102
103103
#########
104104
Full list of SparseZoo stubs for benchmarking
105-
* Baseline dense YOLOv3 - "zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/base-none"
106-
* Pruned YOLOv3 (87% sparse) - "zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/pruned-aggressive-97"
105+
* Baseline dense YOLOv3 -
106+
"zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/base-none"
107+
* Pruned YOLOv3 (87% sparse) -
108+
"zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/pruned-aggressive-97"
107109
* Pruned-Quantized YOLOv3 (83% sparse, CPU must support VNNI) -
108110
"zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/pruned_quant-aggressive-94"
109111
"""
@@ -116,14 +118,13 @@
116118
from pathlib import Path
117119
from typing import Any, Iterable, List, Optional, Tuple, Union
118120

119-
import cv2
120121
import numpy
121122
import onnx
122123
import onnxruntime
123124
import torch
124125
from tqdm.auto import tqdm
125126

126-
from deepsparse import compile_model, cpu
127+
from deepsparse import compile_model
127128
from deepsparse.benchmark import BenchmarkResults
128129
from deepsparse_utils import (
129130
YoloPostprocessor,
@@ -172,10 +173,10 @@ def parse_args():
172173
type=Optional[str],
173174
default=None,
174175
help=(
175-
"Optional filepath to image examples to run the benchmark on. Can be path to "
176-
"directory, single image jpg file, or a glob path. All files should be "
177-
"in jpg format. If not provided, sample COCO images will be downloaded from "
178-
"the SparseZoo"
176+
"Optional filepath to image examples to run the benchmark on. Can be path "
177+
"to directory, single image jpg file, or a glob path. All files should be "
178+
"in jpg format. If not provided, sample COCO images will be downloaded "
179+
"from the SparseZoo"
179180
),
180181
)
181182

@@ -201,8 +202,8 @@ def parse_args():
201202
default=None,
202203
help=(
203204
"The number of physical cores to run the benchmark on, "
204-
"defaults to None where it uses all physical cores available on the system. "
205-
"For DeepSparse benchmarks, this value is the number of cores per socket"
205+
"defaults to None where it uses all physical cores available on the system."
206+
" For DeepSparse benchmarks, this value is the number of cores per socket"
206207
),
207208
)
208209
parser.add_argument(
@@ -266,7 +267,7 @@ def parse_args():
266267
def _parse_device(device: Union[str, int]) -> Union[str, int]:
267268
try:
268269
return int(device)
269-
except:
270+
except Exception:
270271
return device
271272

272273

integrations/ultralytics/deepsparse/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def detect(
4444
"""
4545
:param images: list of or singular file paths or numpy arrays of images to
4646
run the detection model on. Number of images should equal model batch size
47-
:return: list of post-processed object detection results for each image including
48-
class label, likelihood, and bounding box coordinates
47+
:return: list of post-processed object detection results for each image
48+
including class label, likelihood, and bounding box coordinates
4949
"""
5050
if not isinstance(images, List):
5151
images = [images]

integrations/ultralytics/deepsparse/deepsparse_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
__all__ = [
3939
"load_image",
40-
"pre_nms_postprocess",
40+
"YoloPostprocessor",
4141
"postprocess_nms",
4242
]
4343

@@ -98,7 +98,8 @@ def pre_nms_postprocess(self, outputs: List[numpy.ndarray]) -> torch.Tensor:
9898
# decode xywh box values
9999
pred[..., 0:2] = (pred[..., 0:2] * 2.0 - 0.5 + grid) * stride
100100
pred[..., 2:4] = (pred[..., 2:4] * 2) ** 2 * anchor_grid
101-
# flatten anchor and grid dimensions -> (bs, num_predictions, num_classes + 5)
101+
# flatten anchor and grid dimensions ->
102+
# (bs, num_predictions, num_classes + 5)
102103
processed_outputs.append(pred.view(pred.size(0), -1, pred.size(-1)))
103104
return torch.cat(processed_outputs, 1)
104105

scripts/keras_classification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@
265265
--dataset imagenette \
266266
--dataset-path <DATASET_DIR> \
267267
--train-batch-size 64 \
268-
--recipe-path zoo:cv/classification/resnet_v1-50/keras/keras.applications/imagenette/pruned-moderate?recipe_type=original
268+
--recipe-path zoo:cv/classification/resnet_v1-50/keras/\
269+
keras.applications/imagenette/pruned-moderate?recipe_type=original
269270
############
270271
Example command for loading a ResNet50 model from a checkpoint, then
271272
evaluate it on the validation of the Imagenette dataset.

src/sparseml/keras/datasets/dataset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def build(
7979
@abstractmethod
8080
def creator(self) -> tensorflow.data.Dataset:
8181
"""
82-
Implemented by sub classes to create a tensorflow.data dataset for the given impl.
82+
Implemented by sub classes to create a tensorflow.data dataset for the given
83+
impl.
84+
8385
:return: a created tensorflow.data dataset
8486
"""
8587
raise NotImplementedError()

0 commit comments

Comments
 (0)