Skip to content

Commit e104c43

Browse files
authored
Merge pull request #30 from hickeyma/ci/add-ruff-tool
ci: Add Ruff for lint and code formatting
2 parents 9d7f152 + 7ff6b6c commit e104c43

32 files changed

+186
-151
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
fail-fast: false
4141
matrix:
4242
lint:
43-
- name: "fmt"
43+
- name: "ruff"
4444
commands: |
45-
tox -e fmt
45+
tox -e ruff
4646
- name: "pylint"
4747
commands: |
4848
echo "::add-matcher::.github/workflows/matchers/pylint.json"

.isort.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ import_heading_stdlib=Standard
66
import_heading_thirdparty=Third Party
77
import_heading_firstparty=First Party
88
import_heading_localfolder=Local
9-
known_firstparty=
109
known_localfolder=fms_mo,tests
1110
extend_skip=fms_mo/_version.py

.pre-commit-config.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 22.3.0
4-
hooks:
5-
- id: black
6-
exclude: imports
72
- repo: https://github.com/PyCQA/isort
83
rev: 5.11.5
94
hooks:
105
- id: isort
116
exclude: imports
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
# Ruff version.
9+
rev: v0.5.0
10+
hooks:
11+
# Run the linter (most fixers are disabled for now).
12+
- id: ruff
13+
# Run the formatter.
14+
- id: ruff-format
15+

examples/PTQ_INT8/run_qa_no_trainer_ptq.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,6 @@ def squad_eval(model, keep_model_in_eval_mode=True):
11261126
from fms_mo import qconfig_init, qmodel_prep
11271127

11281128
if args.do_qat:
1129-
11301129
# create a config dict, if same item exists in both recipe and args, args has the priority.
11311130
qcfg = qconfig_init(recipe="qat_int8", args=args)
11321131

@@ -1141,7 +1140,6 @@ def squad_eval(model, keep_model_in_eval_mode=True):
11411140
qmodel_prep(model, exam_inp, qcfg, optimizer, use_dynamo=True)
11421141

11431142
if args.do_ptq:
1144-
11451143
# Local
11461144
from fms_mo.quant.ptq import calib_PTQ_lm
11471145

@@ -1216,17 +1214,16 @@ def speedtest(model, exam_inp, Ntest=100):
12161214
("int8", "ind"),
12171215
("int8", "cugr"),
12181216
]:
1219-
12201217
logger.info(
12211218
f"\n {label} {'with' if comp_mode else 'without'} torch.compile"
12221219
)
12231220
model_copy = deepcopy(model)
12241221

12251222
if label == "int8":
12261223
qcfg = qconfig_init(recipe="ptq_int8", args=args)
1227-
qcfg[
1228-
"qmodel_calibration"
1229-
] = 0 # no need to run calibration or trained scales will be lost.
1224+
qcfg["qmodel_calibration"] = (
1225+
0 # no need to run calibration or trained scales will be lost.
1226+
)
12301227
qmodel_prep(
12311228
model_copy,
12321229
exam_inp,
@@ -1479,9 +1476,9 @@ def speedtest(model, exam_inp, Ntest=100):
14791476
"step": completed_steps,
14801477
}
14811478
if args.do_predict:
1482-
log[
1483-
"squad_v2_predict" if args.version_2_with_negative else "squad_predict"
1484-
] = predict_metric
1479+
log["squad_v2_predict" if args.version_2_with_negative else "squad_predict"] = (
1480+
predict_metric
1481+
)
14851482

14861483
accelerator.log(log, step=completed_steps)
14871484

examples/PTQ_INT8/utils_qa.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
Post-processing utilities for question answering.
1717
"""
18+
1819
# Standard
1920
from typing import Optional, Tuple
2021
import collections

examples/QAT_INT8/run_qa_no_trainer_qat.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,6 @@ def squad_eval(model, keep_model_in_eval_mode=True):
10721072
from fms_mo import qconfig_init, qmodel_prep
10731073

10741074
if args.do_qat:
1075-
10761075
# create a config dict, if same item exists in both recipe and args, args has the priority.
10771076
qcfg = qconfig_init(recipe="qat_int8", args=args)
10781077

@@ -1132,17 +1131,16 @@ def speedtest(model, exam_inp, Ntest=100):
11321131
("int8", "ind"),
11331132
("int8", "cugr"),
11341133
]:
1135-
11361134
logger.info(
11371135
f"\n {label} {'with' if comp_mode else 'without'} torch.compile"
11381136
)
11391137
model_copy = deepcopy(model)
11401138

11411139
if label == "int8":
11421140
qcfg = qconfig_init(recipe="qat_int8", args=args)
1143-
qcfg[
1144-
"qmodel_calibration"
1145-
] = 0 # no need to run calibration or trained scales will be lost.
1141+
qcfg["qmodel_calibration"] = (
1142+
0 # no need to run calibration or trained scales will be lost.
1143+
)
11461144
qmodel_prep(
11471145
model_copy,
11481146
exam_inp,
@@ -1395,9 +1393,9 @@ def speedtest(model, exam_inp, Ntest=100):
13951393
"step": completed_steps,
13961394
}
13971395
if args.do_predict:
1398-
log[
1399-
"squad_v2_predict" if args.version_2_with_negative else "squad_predict"
1400-
] = predict_metric
1396+
log["squad_v2_predict" if args.version_2_with_negative else "squad_predict"] = (
1397+
predict_metric
1398+
)
14011399

14021400
accelerator.log(log, step=completed_steps)
14031401

examples/QAT_INT8/utils_qa.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
Post-processing utilities for question answering.
1717
"""
18+
1819
# Standard
1920
from typing import Optional, Tuple
2021
import collections

fms_mo/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""FMS Model Optimizer init. Import most commonly used functions and classes here.
15-
"""
14+
"""FMS Model Optimizer init. Import most commonly used functions and classes here."""
1615

1716
# Standard
1817
from importlib.metadata import PackageNotFoundError, version

fms_mo/calib.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Main user interfacing functions, such as qmodel_prep()
15-
16-
"""
14+
"""Main user interfacing functions, such as qmodel_prep()"""
1715

1816
# Standard
1917
from copy import deepcopy
@@ -204,8 +202,9 @@ def __call__(self, module, inputs):
204202
for act, name in [(x, "input"), (hid[layer], "hidden")]:
205203
nelem = act.nelement()
206204
if self.a_init_method == "percentile":
207-
lower_k, upper_k = int(self.per[0] * nelem), int(
208-
self.per[1] * nelem
205+
lower_k, upper_k = (
206+
int(self.per[0] * nelem),
207+
int(self.per[1] * nelem),
209208
)
210209
lower_per_cur = (
211210
act.reshape(1, -1).kthvalue(lower_k).values.data[0]

fms_mo/custom_ext_kernels/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ def exllama_ops_load_and_reg(qcfg=None, run_unit_test=False):
514514
qcfg["AUTOGPTQ_AVAILABLE"] = True
515515
need_registration = False
516516
else:
517-
518517
need_registration = (
519518
available_packages["exllama_kernels"]
520519
and available_packages["exllamav2_kernels"]
@@ -597,8 +596,7 @@ def exv2_i4f16_fxinputs(
597596
q4: int,
598597
q4_width: int,
599598
force_cuda: bool,
600-
) -> torch.Tensor:
601-
...
599+
) -> torch.Tensor: ...
602600

603601
# Generic implementation
604602
@kernel_impl(f"{namespace}::exv2_i4f16_fxinputs", "cuda")

0 commit comments

Comments
 (0)