Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/tvm/contrib/cutlass/conv2d_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def accumulator_type(self):
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:
Expand All @@ -77,7 +77,7 @@ def core_name(self):
)

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
Expand Down Expand Up @@ -145,7 +145,7 @@ def procedural_name(self):


class EmitConv2dInstance:
""" Responsible for emitting a CUTLASS template definition."""
"""Responsible for emitting a CUTLASS template definition."""

def __init__(self):
self.epilogue_default = """
Expand Down
8 changes: 4 additions & 4 deletions python/tvm/contrib/cutlass/gemm_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def short_math_name(self):
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 = ""

Expand All @@ -74,7 +74,7 @@ def core_name(self):
)

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
Expand Down Expand Up @@ -121,7 +121,7 @@ def procedural_name(self):
)

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:
Expand Down Expand Up @@ -154,7 +154,7 @@ def leading_dim(self):


class EmitGemmInstance:
""" Responsible for emitting a CUTLASS template definition."""
"""Responsible for emitting a CUTLASS template definition."""

def __init__(self):
self.epilogue_default = """
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/meta_schedule/cost_model/xgb_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


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:
Expand Down
32 changes: 16 additions & 16 deletions python/tvm/micro/contrib/stm32/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


def _fix_name(node_name):
""" Replace ':' with '_' in names like 'InputImg:0' """
"""Replace ':' with '_' in names like 'InputImg:0'"""
return node_name.replace(":", "_")


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -193,7 +193,7 @@ def __init__(self, include_activations=True, include_inputs=True, include_output
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:
Expand Down Expand Up @@ -258,7 +258,7 @@ def _get_tensor_from_node(self, nid, idx):
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()

Expand Down Expand Up @@ -548,7 +548,7 @@ def parse_module(self, module, quantization=None):
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()

Expand Down Expand Up @@ -674,7 +674,7 @@ def _emit_open(self, name, out_h, out_c):
)

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()

Expand Down Expand Up @@ -794,7 +794,7 @@ def _emit_tensor_quant(self, dl_tensor_name, out_c):
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"]
Expand Down Expand Up @@ -838,7 +838,7 @@ def _emit_tensor_init(self, dl_tensor_name, tensor, out_c):

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(
Expand Down Expand Up @@ -905,7 +905,7 @@ def _emit_activation_buffers(self, name, out_c):
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(
Expand All @@ -922,7 +922,7 @@ def _emit_params_buffers(self, name, out_c):
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(
Expand Down Expand Up @@ -967,7 +967,7 @@ def _emit_tensor_activation(self, dl_tensor_name, tensor, out_c):
)

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(
Expand Down Expand Up @@ -1015,7 +1015,7 @@ def _emit_activation_init(self, name, out_c):
)

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(
Expand Down Expand Up @@ -1063,13 +1063,13 @@ def _emit_params_init(self, name, out_c):
)

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(
Expand Down Expand Up @@ -1230,7 +1230,7 @@ def _emit_run(self, name, out_h, out_c):
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(
Expand Down Expand Up @@ -1296,7 +1296,7 @@ def _emit_create_destroy(self, name, out_h, out_c):
)

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):
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/relay/frontend/caffe.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def convert_tanh(self, op):
return out

def convert_reduction(self, op):
""" Convert Reduction layer """
"""Convert Reduction layer"""
reduction_dic = ["NOP", "SUM", "ASUM", "SUMSQ", "MEAN"]

inputs = op.bottom
Expand Down
71 changes: 41 additions & 30 deletions tests/lint/git-black.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[@]}
Expand Down
22 changes: 0 additions & 22 deletions tests/lint/python_format.sh

This file was deleted.

4 changes: 2 additions & 2 deletions tests/python/frontend/caffe/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/task_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down