You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by mo...@apache.org on 2022/04/06 08:25:26 UTC
[tvm] branch main updated: [ci] Don't diff Python files when checking formatting (#10895)
This is an automated email from the ASF dual-hosted git repository.
mousius pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 96f701fd66 [ci] Don't diff Python files when checking formatting (#10895)
96f701fd66 is described below
commit 96f701fd668baa58e2bc09b60c7fa376578c8dac
Author: driazati <94...@users.noreply.github.com>
AuthorDate: Wed Apr 6 01:25:22 2022 -0700
[ci] Don't diff Python files when checking formatting (#10895)
---
python/tvm/contrib/cutlass/conv2d_operation.py | 6 +-
python/tvm/contrib/cutlass/gemm_operation.py | 8 +--
python/tvm/meta_schedule/cost_model/xgb_model.py | 2 +-
python/tvm/micro/contrib/stm32/emitter.py | 32 +++++------
python/tvm/relay/frontend/caffe.py | 2 +-
tests/lint/git-black.sh | 71 ++++++++++++++----------
tests/lint/python_format.sh | 22 --------
tests/python/frontend/caffe/test_forward.py | 4 +-
tests/scripts/task_lint.sh | 2 +-
9 files changed, 69 insertions(+), 80 deletions(-)
diff --git a/python/tvm/contrib/cutlass/conv2d_operation.py b/python/tvm/contrib/cutlass/conv2d_operation.py
index 7b78c5a375..162e8f6678 100644
--- a/python/tvm/contrib/cutlass/conv2d_operation.py
+++ b/python/tvm/contrib/cutlass/conv2d_operation.py
@@ -55,7 +55,7 @@ class Conv2dOperation:
return self.tile_description.math_instruction.element_accumulator
def core_name(self):
- """ The basic operation kind is prefixed with a letter indicating the accumulation type. """
+ """The basic operation kind is prefixed with a letter indicating the accumulation type."""
intermediate_type = ""
if self.tile_description.math_instruction.opcode_class == OpcodeClass.TensorOp:
@@ -77,7 +77,7 @@ class Conv2dOperation:
)
def extended_name(self):
- """ Append data types if they differ from compute type. """
+ """Append data types if they differ from compute type."""
if (
self.C.element != self.tile_description.math_instruction.element_accumulator
and self.A.element != self.tile_description.math_instruction.element_accumulator
@@ -145,7 +145,7 @@ class Conv2dOperation:
class EmitConv2dInstance:
- """ Responsible for emitting a CUTLASS template definition."""
+ """Responsible for emitting a CUTLASS template definition."""
def __init__(self):
self.epilogue_default = """
diff --git a/python/tvm/contrib/cutlass/gemm_operation.py b/python/tvm/contrib/cutlass/gemm_operation.py
index 4673b4bdea..1a5e945222 100644
--- a/python/tvm/contrib/cutlass/gemm_operation.py
+++ b/python/tvm/contrib/cutlass/gemm_operation.py
@@ -50,7 +50,7 @@ class GemmOperation:
return ShortDataTypeNames[self.accumulator_type()]
def core_name(self):
- """ The basic operation kind is prefixed with a letter indicating the accumulation type. """
+ """The basic operation kind is prefixed with a letter indicating the accumulation type."""
inst_shape = ""
intermediate_type = ""
@@ -74,7 +74,7 @@ class GemmOperation:
)
def extended_name(self):
- """ Append data types if they differ from compute type. """
+ """Append data types if they differ from compute type."""
if (
self.C.element != self.tile_description.math_instruction.element_accumulator
and self.A.element != self.tile_description.math_instruction.element_accumulator
@@ -121,7 +121,7 @@ class GemmOperation:
)
def leading_dim(self):
- """ lda, ldb, ldc, according to the leading dimension. """
+ """lda, ldb, ldc, according to the leading dimension."""
if self.A.layout == LayoutType.RowMajor:
lda = "K"
elif self.A.layout == LayoutType.ColumnMajor:
@@ -154,7 +154,7 @@ class GemmOperation:
class EmitGemmInstance:
- """ Responsible for emitting a CUTLASS template definition."""
+ """Responsible for emitting a CUTLASS template definition."""
def __init__(self):
self.epilogue_default = """
diff --git a/python/tvm/meta_schedule/cost_model/xgb_model.py b/python/tvm/meta_schedule/cost_model/xgb_model.py
index 9d95623c2b..9665dd1f79 100644
--- a/python/tvm/meta_schedule/cost_model/xgb_model.py
+++ b/python/tvm/meta_schedule/cost_model/xgb_model.py
@@ -45,7 +45,7 @@ logger = logging.getLogger(__name__) # pylint: disable=invalid-name
def make_metric_sorter(focused_metric):
- """ Make sure the focused metric is the first one. """
+ """Make sure the focused metric is the first one."""
def metric_name_for_sort(name):
if focused_metric == name:
diff --git a/python/tvm/micro/contrib/stm32/emitter.py b/python/tvm/micro/contrib/stm32/emitter.py
index 8453ea78e0..aec5912871 100644
--- a/python/tvm/micro/contrib/stm32/emitter.py
+++ b/python/tvm/micro/contrib/stm32/emitter.py
@@ -44,7 +44,7 @@ DBAR = "=" * 60
def _fix_name(node_name):
- """ Replace ':' with '_' in names like 'InputImg:0' """
+ """Replace ':' with '_' in names like 'InputImg:0'"""
return node_name.replace(":", "_")
@@ -116,7 +116,7 @@ def _get_tensor_size_bytes(dims, dltype):
def _preprocess_code(src):
- """ Hack the C code implementing the model. """
+ """Hack the C code implementing the model."""
dst = "#include <stdio.h>\n" "#include <math.h>\n\n"
dst = dst + src
return dst
@@ -193,7 +193,7 @@ class CodeEmitter(object):
self._quantization = {}
def _extract_quantization_info(self, quantization):
- """ Build dictionary with quantization infos."""
+ """Build dictionary with quantization infos."""
for dl_tensor_name in self._input_data:
if dl_tensor_name in quantization:
@@ -258,7 +258,7 @@ class CodeEmitter(object):
return tensor
def _compute_data_placement(self):
- """ Compute inputs, outputs, weight, activation sizes"""
+ """Compute inputs, outputs, weight, activation sizes"""
self._inputs = self._arg_nodes.copy()
@@ -548,7 +548,7 @@ class CodeEmitter(object):
self._parse_model(quantization)
def _emit_params_data(self, name, out_h, out_c):
- """ Emits the network_data[c,h] files with parameters."""
+ """Emits the network_data[c,h] files with parameters."""
name_upper = name.upper()
@@ -674,7 +674,7 @@ class CodeEmitter(object):
)
def _emit_close(self, name, out_h, out_c):
- """ Emits the ai_model_info structure. """
+ """Emits the ai_model_info structure."""
name_upper = name.upper()
@@ -794,7 +794,7 @@ class CodeEmitter(object):
return None
def _emit_tensor_init(self, dl_tensor_name, tensor, out_c):
- """ Emits the tensor instantiation code. """
+ """Emits the tensor instantiation code."""
dltype = tensor["dltype"]
dims = tensor["dims"]
@@ -838,7 +838,7 @@ class CodeEmitter(object):
def _emit_activation_buffers(self, name, out_c):
# pylint: disable=unused-argument
- """ Emits activation tensors, including inputs/outputs."""
+ """Emits activation tensors, including inputs/outputs."""
out_c.write(
textwrap.dedent(
@@ -905,7 +905,7 @@ class CodeEmitter(object):
out_c.write(f"\n")
def _emit_params_buffers(self, name, out_c):
- """ Emits all parameter tensors."""
+ """Emits all parameter tensors."""
out_c.write(
textwrap.dedent(
@@ -922,7 +922,7 @@ class CodeEmitter(object):
out_c.write(f"\n")
def _emit_network(self, name, out_c):
- """ Emits prototypes for the network operator functions."""
+ """Emits prototypes for the network operator functions."""
out_c.write(
textwrap.dedent(
@@ -967,7 +967,7 @@ class CodeEmitter(object):
)
def _emit_activation_init(self, name, out_c):
- """ Emits buffer initialization code for activation tensors."""
+ """Emits buffer initialization code for activation tensors."""
out_c.write(
textwrap.dedent(
@@ -1015,7 +1015,7 @@ class CodeEmitter(object):
)
def _emit_params_init(self, name, out_c):
- """ Emits buffer initialization code for params tensors."""
+ """Emits buffer initialization code for params tensors."""
out_c.write(
textwrap.dedent(
@@ -1063,13 +1063,13 @@ class CodeEmitter(object):
)
def _emit_init(self, name, out_c):
- """ Emits buffer initialization code."""
+ """Emits buffer initialization code."""
self._emit_activation_init(name, out_c)
self._emit_params_init(name, out_c)
def _emit_run(self, name, out_h, out_c):
- """ Emits the run function code."""
+ """Emits the run function code."""
out_h.write(
textwrap.dedent(
@@ -1230,7 +1230,7 @@ class CodeEmitter(object):
out_c.write(f"\n")
def _emit_create_destroy(self, name, out_h, out_c):
- """ Emits the create/destroy functions."""
+ """Emits the create/destroy functions."""
out_h.write(
textwrap.dedent(
@@ -1296,7 +1296,7 @@ class CodeEmitter(object):
)
def emit_code(self, dest_dir, model_name):
- """ Emits the C code implementing the model. """
+ """Emits the C code implementing the model."""
# Build the directory structure
if os.path.exists(dest_dir):
diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py
index c87ad9f8fb..2d9f44e284 100644
--- a/python/tvm/relay/frontend/caffe.py
+++ b/python/tvm/relay/frontend/caffe.py
@@ -640,7 +640,7 @@ class OperatorConverter(object):
return out
def convert_reduction(self, op):
- """ Convert Reduction layer """
+ """Convert Reduction layer"""
reduction_dic = ["NOP", "SUM", "ASUM", "SUMSQ", "MEAN"]
inputs = op.bottom
diff --git a/tests/lint/git-black.sh b/tests/lint/git-black.sh
index 6d9eafb613..48029a43a5 100755
--- a/tests/lint/git-black.sh
+++ b/tests/lint/git-black.sh
@@ -15,27 +15,35 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-set -e
-set -u
-set -o pipefail
+set -euo pipefail
-if [[ "$1" == "-i" ]]; then
- INPLACE_FORMAT=1
- shift 1
-else
- INPLACE_FORMAT=0
-fi
+INPLACE_FORMAT=false
+LINT_ALL_FILES=true
+REVISION=
-if [[ "$#" -lt 1 ]]; then
- echo "Usage: tests/lint/git-black.sh [-i] <commit>"
- echo ""
- echo "Run black on Python files that changed since <commit>"
- echo "Examples:"
- echo "- Compare last one commit: tests/lint/git-black.sh HEAD~1"
- echo "- Compare against upstream/main: tests/lint/git-black.sh upstream/main"
- echo "The -i will use black to format files in-place instead of checking them."
- exit 1
-fi
+while (( $# )); do
+ case "$1" in
+ -i)
+ INPLACE_FORMAT=true
+ shift 1
+ ;;
+ --rev)
+ LINT_ALL_FILES=false
+ REVISION=$2
+ shift 2
+ ;;
+ *)
+ echo "Usage: tests/lint/git-black.sh [-i] [--rev <commit>]"
+ echo ""
+ echo "Run black on Python files that changed since <commit> or on all files in the repo"
+ echo "Examples:"
+ echo "- Compare last one commit: tests/lint/git-black.sh --rev HEAD~1"
+ echo "- Compare against upstream/main: tests/lint/git-black.sh --rev upstream/main"
+ echo "The -i will use black to format files in-place instead of checking them."
+ exit 1
+ ;;
+ esac
+done
# required to make black's dep click to work
export LC_ALL=C.UTF-8
@@ -51,19 +59,22 @@ VERSION=$(black --version)
echo "black version: $VERSION"
# Compute Python files which changed to compare.
-IFS=$'\n' read -a FILES -d'\n' < <(git diff --name-only --diff-filter=ACMRTUX $1 -- "*.py" "*.pyi") || true
-echo "Read returned $?"
-if [ -z ${FILES+x} ]; then
- echo "No changes in Python files"
- exit 0
+if [[ "$LINT_ALL_FILES" == "true" ]]; then
+ FILES=$(git ls-files | grep -E '\.py$')
+ echo "checking all files"
+else
+ IFS=$'\n' read -a FILES -d'\n' < <(git diff --name-only --diff-filter=ACMRTUX $REVISION -- "*.py" "*.pyi") || true
+ echo "Read returned $?"
+ if [ -z ${FILES+x} ]; then
+ echo "No changes in Python files"
+ exit 0
+ fi
+ echo "Files: $FILES"
fi
-echo "Files: $FILES"
-if [[ ${INPLACE_FORMAT} -eq 1 ]]; then
- echo "Running black on Python files against revision" $1:
- CMD=( "black" "${FILES[@]}" )
- echo "${CMD[@]}"
- "${CMD[@]}"
+if [[ "$INPLACE_FORMAT" == "true" ]]; then
+ echo "Running black on Python files against revision" $REVISION:
+ python3 -m black ${FILES[@]}
else
echo "Running black in checking mode"
python3 -m black --diff --check ${FILES[@]}
diff --git a/tests/lint/python_format.sh b/tests/lint/python_format.sh
deleted file mode 100755
index 4098d0ec5e..0000000000
--- a/tests/lint/python_format.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env bash
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, 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.
-
-set -eux
-
-./tests/lint/git-black.sh HEAD~1
-./tests/lint/git-black.sh origin/main
diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py
index 9229c8eca3..4f492540c9 100644
--- a/tests/python/frontend/caffe/test_forward.py
+++ b/tests/python/frontend/caffe/test_forward.py
@@ -877,12 +877,12 @@ def test_forward_TanH():
def _test_reduction(data, **kwargs):
- """ One iteration of Reduction """
+ """One iteration of Reduction"""
_test_op(data, L.Reduction, "Reduction", **kwargs)
def test_forward_Reduction():
- """ Reduction """
+ """Reduction"""
reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4}
_test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0)
_test_reduction(
diff --git a/tests/scripts/task_lint.sh b/tests/scripts/task_lint.sh
index e1e0b65896..efadad8ecb 100755
--- a/tests/scripts/task_lint.sh
+++ b/tests/scripts/task_lint.sh
@@ -50,7 +50,7 @@ echo "Rust check..."
tests/lint/rust_format.sh
echo "black check..."
-tests/lint/python_format.sh
+tests/lint/git-black.sh -i
echo "Linting the Python code..."
tests/lint/pylint.sh