You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2026/02/23 12:29:27 UTC
(tvm) branch main updated: [REFACTOR][LINT] Modernize ruff config (#18810)
This is an automated email from the ASF dual-hosted git repository.
tqchen 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 33dcea1686 [REFACTOR][LINT] Modernize ruff config (#18810)
33dcea1686 is described below
commit 33dcea168633e722907b523a7597ab77f5dd23f2
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Mon Feb 23 07:29:21 2026 -0500
[REFACTOR][LINT] Modernize ruff config (#18810)
This PR removes the extra lint violations from the codebase so lint
aligns with the latest style
---
.gitignore | 6 +
apps/android_rpc/tests/android_rpc_test.py | 3 +-
apps/ios_rpc/init_proj.py | 1 -
apps/ios_rpc/tests/ios_rpc_test.py | 5 +-
ci/jenkins/generated/lint_jenkinsfile.groovy | 524 ---------------------
ci/jenkins/templates/lint_jenkinsfile.groovy.j2 | 58 ---
ci/scripts/github/github_cc_reviewers.py | 3 +-
ci/scripts/github/github_commenter.py | 3 +-
ci/scripts/github/github_pr_comment.py | 1 +
ci/scripts/github/github_skipped_tests_comment.py | 2 +-
ci/scripts/github/github_tag_teams.py | 1 +
ci/scripts/github/github_tvmbot.py | 3 +-
ci/scripts/github/ping_reviewers.py | 5 +-
ci/scripts/github/update_branch.py | 5 +-
ci/scripts/jenkins/check_pr.py | 1 +
ci/scripts/jenkins/cmd_utils.py | 1 -
ci/scripts/jenkins/determine_docker_images.py | 1 +
ci/scripts/jenkins/git_skip_ci_globs.py | 1 +
ci/scripts/jenkins/git_utils.py | 3 +-
ci/scripts/jenkins/pytest_wrapper.py | 1 +
ci/scripts/jenkins/should_rebuild_docker.py | 1 +
conftest.py | 3 +-
docs/conf.py | 14 +-
docs/deep_dive/relax/tutorials/relax_creation.py | 1 +
.../relax/tutorials/relax_transformation.py | 1 +
docs/deep_dive/tensor_ir/tutorials/tir_creation.py | 1 +
.../tensor_ir/tutorials/tir_transformation.py | 1 +
docs/get_started/tutorials/ir_module.py | 1 +
docs/get_started/tutorials/quick_start.py | 1 +
docs/how_to/tutorials/cross_compilation_and_rpc.py | 3 +-
docs/how_to/tutorials/customize_opt.py | 1 +
docs/how_to/tutorials/e2e_opt_model.py | 1 +
.../how_to/tutorials/export_and_load_executable.py | 1 +
docs/how_to/tutorials/optimize_llm.py | 3 +-
jvm/core/src/test/scripts/prepare_test_libs.py | 2 +-
jvm/core/src/test/scripts/test_rpc_proxy_server.py | 1 -
pyproject.toml | 54 +--
python/tvm/base.py | 1 +
python/tvm/contrib/cudnn.py | 1 +
python/tvm/contrib/cutlass/attention_operation.py | 137 +++---
python/tvm/contrib/cutlass/build.py | 7 +-
python/tvm/contrib/cutlass/conv2d_operation.py | 18 +-
python/tvm/contrib/cutlass/conv2d_profiler.py | 37 +-
python/tvm/contrib/cutlass/gemm_operation.py | 3 +-
python/tvm/contrib/cutlass/gen_conv2d.py | 10 +-
python/tvm/contrib/cutlass/gen_tensor_op.py | 1 +
python/tvm/contrib/cutlass/layer_norm_operation.py | 1 +
python/tvm/contrib/cutlass/library.py | 8 +-
python/tvm/contrib/cutlass/rms_norm_operation.py | 1 +
python/tvm/contrib/hexagon/build.py | 17 +-
python/tvm/contrib/hexagon/hexagon_profiler.py | 1 +
.../contrib/hexagon/profiling/process_lwp_data.py | 1 +
python/tvm/contrib/hexagon/tools.py | 4 +-
python/tvm/contrib/mps.py | 1 +
python/tvm/contrib/msc/core/codegen/codegen.py | 1 +
python/tvm/contrib/msc/core/frontend/translate.py | 1 +
.../tvm/contrib/msc/core/gym/agent/base_agent.py | 6 +-
.../tvm/contrib/msc/core/gym/control/controller.py | 4 +-
python/tvm/contrib/msc/core/gym/control/service.py | 19 +-
.../contrib/msc/core/gym/environment/base_env.py | 8 +-
.../tvm/contrib/msc/core/gym/environment/method.py | 4 +-
.../contrib/msc/core/gym/environment/prune_env.py | 1 +
python/tvm/contrib/msc/core/ir/graph.py | 14 +-
python/tvm/contrib/msc/core/runtime/jit.py | 10 +-
python/tvm/contrib/msc/core/runtime/runner.py | 18 +-
python/tvm/contrib/msc/core/tools/configer.py | 4 +-
python/tvm/contrib/msc/core/tools/prune/pruner.py | 5 +-
.../tvm/contrib/msc/core/tools/quantize/method.py | 1 +
python/tvm/contrib/msc/core/tools/tool.py | 35 +-
python/tvm/contrib/msc/core/transform/pattern.py | 6 +-
python/tvm/contrib/msc/core/transform/transform.py | 4 +-
python/tvm/contrib/msc/core/utils/arguments.py | 1 +
python/tvm/contrib/msc/core/utils/dataset.py | 8 +-
python/tvm/contrib/msc/core/utils/expr.py | 4 +-
python/tvm/contrib/msc/core/utils/file.py | 20 +-
python/tvm/contrib/msc/core/utils/info.py | 5 +-
python/tvm/contrib/msc/core/utils/log.py | 10 +-
python/tvm/contrib/msc/core/utils/message.py | 5 +-
python/tvm/contrib/msc/core/utils/namespace.py | 1 +
python/tvm/contrib/msc/core/utils/register.py | 1 +
.../msc/framework/tensorflow/codegen/codegen.py | 1 +
.../msc/framework/tensorflow/runtime/runner.py | 1 +
.../msc/framework/tensorrt/runtime/runner.py | 1 +
.../framework/tensorrt/tools/quantize/quantizer.py | 1 +
.../msc/framework/tensorrt/transform/pattern.py | 6 +-
.../msc/framework/tensorrt/transform/transform.py | 4 +-
.../msc/framework/torch/frontend/translate.py | 2 +-
.../tvm/contrib/msc/framework/torch/runtime/jit.py | 7 +-
.../contrib/msc/framework/torch/runtime/runner.py | 5 +-
.../contrib/msc/framework/tvm/runtime/runner.py | 1 +
.../msc/framework/tvm/tools/quantize/quantizer.py | 1 +
.../msc/framework/tvm/tools/track/tracker.py | 1 +
python/tvm/contrib/msc/pipeline/dynamic.py | 12 +-
python/tvm/contrib/msc/pipeline/manager.py | 10 +-
python/tvm/contrib/msc/pipeline/pipeline.py | 22 +-
python/tvm/contrib/msc/pipeline/utils.py | 16 +-
python/tvm/contrib/msc/pipeline/worker.py | 19 +-
python/tvm/contrib/msc/pipeline/wrapper.py | 14 +-
python/tvm/contrib/msc/plugin/codegen/codegen.py | 9 +-
python/tvm/contrib/msc/plugin/codegen/sources.py | 1 +
python/tvm/contrib/nnpack.py | 1 +
python/tvm/contrib/nvcc.py | 4 +-
python/tvm/contrib/pickle_memoize.py | 1 +
python/tvm/contrib/popen_pool.py | 1 +
python/tvm/contrib/rpc.py | 1 +
python/tvm/contrib/tvmjs.py | 10 +-
python/tvm/contrib/utils.py | 1 +
python/tvm/contrib/xcode.py | 1 +
python/tvm/exec/disco_remote_socket_session.py | 1 +
python/tvm/exec/disco_worker.py | 1 +
python/tvm/exec/gpu_memory_bandwidth.py | 1 +
python/tvm/exec/popen_worker.py | 1 +
python/tvm/exec/query_rpc_tracker.py | 4 +-
python/tvm/exec/rpc_proxy.py | 4 +-
python/tvm/ffi.py | 1 +
python/tvm/libinfo.py | 2 +-
python/tvm/relax/analysis/analysis.py | 4 +-
python/tvm/relax/backend/cuda/cutlass.py | 1 +
python/tvm/relax/backend/patterns.py | 10 +-
python/tvm/relax/base_py_module.py | 1 +
python/tvm/relax/block_builder.py | 3 +-
python/tvm/relax/dpl/pattern.py | 3 +-
python/tvm/relax/exec_builder.py | 5 +-
python/tvm/relax/expr.py | 1 +
python/tvm/relax/expr_functor.py | 109 ++---
python/tvm/relax/frontend/nn/_tensor_op.py | 1 +
python/tvm/relax/frontend/nn/exporter.py | 4 +-
python/tvm/relax/frontend/nn/extern.py | 1 +
python/tvm/relax/frontend/nn/llm/kv_cache.py | 6 +-
python/tvm/relax/frontend/nn/llm/tree_attn.py | 5 +-
python/tvm/relax/frontend/nn/modules.py | 3 +-
python/tvm/relax/frontend/nn/op.py | 2 +-
python/tvm/relax/frontend/onnx/onnx_frontend.py | 14 +-
.../frontend/stablehlo/stablehlo_translator.py | 4 +-
.../frontend/torch/base_fx_graph_translator.py | 3 +-
.../frontend/torch/exported_program_translator.py | 1 +
python/tvm/relax/frontend/torch/fx_translator.py | 8 +-
python/tvm/relax/op/base.py | 5 +-
python/tvm/relax/op/manipulate.py | 10 +-
python/tvm/relax/op/nn/nn.py | 2 +-
python/tvm/relax/relax_to_pyfunc_converter.py | 5 +-
python/tvm/relax/struct_info.py | 1 +
python/tvm/relax/testing/matmul.py | 1 +
python/tvm/relax/testing/nn.py | 1 +
python/tvm/relax/training/loss.py | 1 +
python/tvm/relax/training/optimizer.py | 1 +
python/tvm/relax/training/utils.py | 2 +-
.../tvm/relax/transform/lazy_transform_params.py | 1 +
python/tvm/relax/transform/legalize_ops/ccl.py | 1 +
python/tvm/relax/transform/legalize_ops/create.py | 1 +
.../tvm/relax/transform/legalize_ops/manipulate.py | 1 +
python/tvm/relax/transform/legalize_ops/nn.py | 2 +-
python/tvm/relax/transform/transform.py | 3 +-
python/tvm/relax/ty.py | 1 +
python/tvm/relax/utils.py | 1 +
python/tvm/relax/vm_build.py | 2 +-
python/tvm/rpc/client.py | 3 +-
python/tvm/rpc/proxy.py | 1 +
python/tvm/rpc/server.py | 1 +
python/tvm/rpc/server_ios_launcher.py | 1 +
python/tvm/rpc/tornado_util.py | 1 +
python/tvm/runtime/_tensor.py | 1 +
python/tvm/runtime/disco/session.py | 1 +
python/tvm/runtime/module.py | 1 +
python/tvm/runtime/object_generic.py | 1 +
python/tvm/runtime/vm.py | 3 +-
python/tvm/s_tir/dlight/adreno/layout_transform.py | 1 +
python/tvm/s_tir/dlight/adreno/pool.py | 1 +
python/tvm/s_tir/dlight/adreno/utils.py | 8 +-
.../tvm/s_tir/dlight/analysis/common_analysis.py | 1 +
python/tvm/s_tir/dlight/base/common_schedules.py | 1 +
python/tvm/s_tir/dlight/gpu/gemv.py | 1 +
python/tvm/s_tir/dlight/gpu/low_batch_gemv.py | 5 +-
python/tvm/s_tir/dlight/gpu/matmul.py | 1 +
python/tvm/s_tir/meta_schedule/builder/builder.py | 3 +-
.../s_tir/meta_schedule/builder/local_builder.py | 1 +
.../s_tir/meta_schedule/cost_model/cost_model.py | 13 +-
.../s_tir/meta_schedule/cost_model/mlp_model.py | 2 +-
.../s_tir/meta_schedule/cost_model/xgb_model.py | 4 +-
.../tvm/s_tir/meta_schedule/database/database.py | 19 +-
.../feature_extractor/feature_extractor.py | 5 +-
.../measure_callback/measure_callback.py | 5 +-
python/tvm/s_tir/meta_schedule/mutator/mutator.py | 9 +-
.../tvm/s_tir/meta_schedule/postproc/postproc.py | 11 +-
python/tvm/s_tir/meta_schedule/runner/runner.py | 5 +-
.../schedule/cuda/layout_transform.py | 1 +
.../meta_schedule/schedule_rule/schedule_rule.py | 11 +-
.../search_strategy/search_strategy.py | 13 +-
.../space_generator/space_generator.py | 1 +
.../meta_schedule/task_scheduler/task_scheduler.py | 1 +
.../tvm/s_tir/meta_schedule/testing/te_workload.py | 1 +
python/tvm/s_tir/meta_schedule/testing/tune_te.py | 1 +
.../meta_schedule/testing/validate_database.py | 17 +-
python/tvm/s_tir/meta_schedule/tune_context.py | 1 +
python/tvm/s_tir/tensor_intrin/arm_cpu.py | 1 +
python/tvm/s_tir/tensor_intrin/cuda.py | 1 +
python/tvm/s_tir/tensor_intrin/riscv_cpu.py | 1 +
python/tvm/script/highlight.py | 1 +
python/tvm/script/ir_builder/ir/ir.py | 2 +-
.../tvm/script/ir_builder/relax/distributed/ir.py | 1 +
.../tvm/script/ir_builder/tir/external_kernel.py | 1 +
python/tvm/script/ir_builder/tir/ir.py | 27 +-
python/tvm/script/ir_builder/tir/triton.py | 1 +
python/tvm/script/parser/_core.py | 1 +
python/tvm/script/parser/core/diagnostics.py | 1 +
python/tvm/script/parser/core/doc.py | 1 +
python/tvm/script/parser/core/doc_core.py | 1 +
python/tvm/script/parser/core/entry.py | 6 +-
python/tvm/script/parser/relax/__init__.py | 1 +
python/tvm/script/parser/relax/dist.py | 1 +
python/tvm/script/parser/tir/__init__.py | 1 +
python/tvm/script/parser/tir/parser.py | 2 +-
python/tvm/script/relax.py | 1 +
python/tvm/script/tir.py | 1 +
python/tvm/target/datatype.py | 1 +
python/tvm/target/intrin.py | 2 +-
python/tvm/target/virtual_device.py | 1 +
python/tvm/te/operation.py | 6 +-
python/tvm/testing/popen_pool.py | 1 +
python/tvm/testing/utils.py | 5 +-
python/tvm/tir/functor.py | 195 ++++----
python/tvm/tir/pipeline.py | 4 +-
python/tvm/tir/transform/function_pass.py | 2 +-
python/tvm/topi/einsum.py | 2 +-
python/tvm/topi/gpu/sort.py | 1 +
python/tvm/topi/image/resize.py | 1 +
python/tvm/topi/nn/batch_matmul.py | 1 +
python/tvm/topi/nn/conv2d.py | 1 +
python/tvm/topi/nn/conv2d_transpose.py | 1 +
python/tvm/topi/nn/correlation.py | 1 +
python/tvm/topi/nn/dense.py | 1 +
python/tvm/topi/nn/depthwise_conv2d.py | 1 +
python/tvm/topi/nn/fifo_buffer.py | 1 +
python/tvm/topi/nn/lstm.py | 1 +
python/tvm/topi/nn/pixel_shuffle.py | 1 +
python/tvm/topi/nn/softmax.py | 1 +
python/tvm/topi/nn/winograd_util.py | 1 +
python/tvm/topi/scatter.py | 1 +
python/tvm/topi/testing/adaptive_pool_python.py | 1 +
python/tvm/topi/testing/conv2d_nchw_python.py | 1 +
.../topi/testing/conv3d_transpose_ncdhw_python.py | 1 +
python/tvm/topi/testing/correlation_nchw_python.py | 1 +
.../tvm/topi/testing/deformable_conv2d_python.py | 4 +-
python/tvm/topi/testing/gather_nd_python.py | 1 +
python/tvm/topi/testing/grid_sample_python.py | 14 +-
python/tvm/topi/testing/lrn_python.py | 1 +
python/tvm/topi/testing/lstm_python.py | 1 +
python/tvm/topi/testing/nll_loss.py | 1 +
python/tvm/topi/testing/poolnd_python.py | 1 +
python/tvm/topi/testing/resize_python.py | 17 +-
python/tvm/topi/testing/roi_align_python.py | 8 +-
python/tvm/topi/testing/roi_pool_python.py | 16 +-
python/tvm/topi/transform.py | 8 +-
python/tvm/topi/utils.py | 1 +
python/tvm/topi/vision/nms_util.py | 1 +
tests/lint/check_asf_header.py | 1 +
tests/lint/check_cmake_options.py | 1 +
tests/lint/check_file_type.py | 1 +
.../test_minimal_target_codegen_llvm.py | 1 +
.../test_runtime_packed_func.py | 1 +
.../python/arith/test_arith_canonical_simplify.py | 1 +
tests/python/arith/test_arith_const_int_bound.py | 1 +
tests/python/arith/test_arith_deduce_bound.py | 1 +
.../arith/test_arith_detect_linear_equation.py | 2 +-
tests/python/arith/test_arith_intset.py | 1 +
tests/python/arith/test_arith_iter_affine_map.py | 1 +
tests/python/arith/test_arith_modular_set.py | 1 +
.../test_arith_narrow_predicate_expression.py | 1 +
tests/python/arith/test_arith_rewrite_simplify.py | 1 +
.../arith/test_arith_solve_linear_equations.py | 1 +
tests/python/ci/test_ci.py | 1 +
tests/python/ci/test_tvmbot.py | 1 +
tests/python/ci/test_utils.py | 1 +
tests/python/codegen/test_gpu_codegen_allreduce.py | 1 +
tests/python/codegen/test_target_codegen.py | 1 +
tests/python/codegen/test_target_codegen_blob.py | 3 +-
.../codegen/test_target_codegen_cross_llvm.py | 3 +-
tests/python/codegen/test_target_codegen_cuda.py | 9 +-
.../python/codegen/test_target_codegen_cuda_fp8.py | 1 +
tests/python/codegen/test_target_codegen_extern.py | 1 +
tests/python/codegen/test_target_codegen_llvm.py | 1 +
tests/python/codegen/test_target_codegen_opencl.py | 1 +
tests/python/codegen/test_target_codegen_riscv.py | 1 +
tests/python/codegen/test_target_codegen_rocm.py | 3 +-
tests/python/codegen/test_target_codegen_vulkan.py | 1 +
tests/python/codegen/test_target_codegen_x86.py | 1 +
.../contrib/test_android/test_meta_schedule.py | 1 +
tests/python/contrib/test_cblas.py | 6 +-
tests/python/contrib/test_coreml_runtime.py | 1 +
tests/python/contrib/test_edgetpu_runtime.py | 1 +
.../python/contrib/test_hexagon/benchmark_util.py | 1 +
tests/python/contrib/test_hexagon/pytest_util.py | 2 +-
.../test_hexagon/test_async_dma_pipeline.py | 1 +
.../test_hexagon/test_benchmark_maxpool2d.py | 1 +
.../test_hexagon/test_fixed_point_conversion.py | 1 +
.../contrib/test_hexagon/test_meta_schedule.py | 2 +-
.../contrib/test_hexagon/test_relax_integration.py | 1 +
tests/python/contrib/test_hexagon/test_sigmoid.py | 1 +
.../test_hexagon/test_software_pipeline_async.py | 1 +
tests/python/contrib/test_hexagon/test_vtcm.py | 1 +
tests/python/contrib/test_hipblas.py | 1 +
tests/python/contrib/test_mps.py | 1 +
tests/python/contrib/test_msc/test_pipeline.py | 1 +
tests/python/contrib/test_msc/test_runner.py | 1 +
tests/python/contrib/test_msc/test_tools.py | 1 +
tests/python/contrib/test_msc/test_transform.py | 1 +
tests/python/contrib/test_popen_pool.py | 1 +
tests/python/contrib/test_random.py | 7 +-
tests/python/contrib/test_rocblas.py | 3 +-
tests/python/contrib/test_rpc_proxy.py | 2 +-
tests/python/contrib/test_sort.py | 1 +
.../python/contrib/test_tir_triton_integration.py | 1 +
tests/python/contrib/test_util.py | 2 +-
tests/python/disco/test_loader.py | 1 +
tests/python/disco/test_nvshmem.py | 3 +-
tests/python/disco/test_session.py | 3 +-
tests/python/ir/test_datatype_nv_fp4.py | 1 +
tests/python/ir/test_datatype_nv_fp8.py | 1 +
tests/python/ir/test_dtype.py | 1 +
tests/python/ir/test_ir_attrs.py | 1 +
tests/python/ir/test_ir_container.py | 1 +
tests/python/ir/test_ir_type.py | 1 +
tests/python/ir/test_node_reflection.py | 1 +
tests/python/ir/test_pass_instrument.py | 1 +
tests/python/ir/test_roundtrip_runtime_module.py | 1 +
tests/python/nightly/test_nnapi/conftest.py | 1 +
tests/python/nightly/test_nnapi/infrastructure.py | 1 +
.../test_nnapi/test_from_exported_to_cuda.py | 1 +
tests/python/nightly/test_nnapi/test_ops.py | 1 +
.../adreno/test_transform_annotate_custom_scope.py | 1 +
.../test_transform_fold_vdevice_scope_change.py | 1 +
tests/python/relax/backend/clml/conftest.py | 1 +
tests/python/relax/backend/clml/mod_utils.py | 1 +
.../python/relax/backend/clml/test_clml_codegen.py | 1 +
.../backend/clml/test_op_exec_clml_codegen.py | 1 +
tests/python/relax/backend/clml/utils.py | 1 +
.../distributed/test_distributed_dtensor_sinfo.py | 1 +
.../test_distributed_transform_lower_distir.py | 1 +
...ributed_transform_lower_global_to_local_view.py | 1 +
...est_distributed_transform_propagate_sharding.py | 1 +
.../test_distributed_tvmscript_parser.py | 1 +
.../test_distributed_tvmscript_printer.py | 1 +
.../test_runtime_builtin_kv_cache_transfer.py | 1 +
...est_runtime_builtin_kv_cache_transfer_kernel.py | 1 +
tests/python/relax/test_analysis.py | 1 +
.../test_analysis_computable_at_compile_time.py | 1 +
.../relax/test_analysis_contains_impure_call.py | 1 +
.../relax/test_analysis_estimate_memory_usage.py | 1 +
.../relax/test_analysis_struct_info_analysis.py | 3 +-
.../test_analysis_suggest_layout_transforms.py | 1 +
tests/python/relax/test_analysis_well_formed.py | 1 +
tests/python/relax/test_ast_printer.py | 1 +
.../python/relax/test_backend_dispatch_sampling.py | 1 +
.../relax/test_backend_dispatch_sort_scan.py | 1 +
.../relax/test_backend_transform_shape_lower.py | 1 +
tests/python/relax/test_base_py_module.py | 1 +
tests/python/relax/test_base_py_module_printer.py | 1 +
.../relax/test_base_py_module_symbolic_shape.py | 1 +
tests/python/relax/test_bind_symbolic_vars.py | 1 +
tests/python/relax/test_binding_rewrite.py | 1 +
tests/python/relax/test_blockbuilder_core.py | 1 +
tests/python/relax/test_codegen_cublas.py | 1 +
tests/python/relax/test_codegen_cudnn.py | 1 +
tests/python/relax/test_codegen_cutlass.py | 1 +
tests/python/relax/test_codegen_tensorrt.py | 1 +
tests/python/relax/test_contrib_vllm.py | 1 +
tests/python/relax/test_dataflow_inplace.py | 1 +
tests/python/relax/test_dataflow_pattern.py | 1 +
tests/python/relax/test_dataflow_rewriter.py | 1 +
tests/python/relax/test_dlpack_integration.py | 1 +
tests/python/relax/test_e2e_op_dynamic.py | 1 +
...eliminate_pad_branch_using_buffer_assumption.py | 1 +
tests/python/relax/test_expr.py | 1 +
tests/python/relax/test_expr_args_converter.py | 1 +
tests/python/relax/test_expr_functor.py | 1 +
tests/python/relax/test_fast_math_transform.py | 1 +
tests/python/relax/test_frontend_dynamo.py | 1 +
.../relax/test_frontend_from_exported_program.py | 1 +
tests/python/relax/test_frontend_from_fx.py | 1 +
.../python/relax/test_frontend_nn_extern_module.py | 1 +
tests/python/relax/test_frontend_nn_modules.py | 1 +
tests/python/relax/test_frontend_nn_op.py | 1 +
tests/python/relax/test_frontend_nn_tensor.py | 1 +
tests/python/relax/test_frontend_onnx.py | 1 +
tests/python/relax/test_frontend_stablehlo.py | 1 +
tests/python/relax/test_group_gemm_flashinfer.py | 1 +
tests/python/relax/test_inline_functions.py | 5 +-
.../relax/test_meta_schedule_relax_integration.py | 1 +
tests/python/relax/test_op_binary.py | 1 +
tests/python/relax/test_op_ccl.py | 1 +
tests/python/relax/test_op_gradient_numeric.py | 1 +
tests/python/relax/test_op_index.py | 1 +
tests/python/relax/test_op_inspect.py | 1 +
tests/python/relax/test_op_linear_algebra.py | 1 +
tests/python/relax/test_op_manipulate.py | 1 +
tests/python/relax/test_op_misc.py | 3 +-
tests/python/relax/test_op_nn.py | 1 +
tests/python/relax/test_op_nn_pooling.py | 1 +
.../python/relax/test_optimize_layout_transform.py | 1 +
tests/python/relax/test_pytorch_integration.py | 1 +
tests/python/relax/test_relax_operators.py | 1 +
.../python/relax/test_relax_to_pyfunc_converter.py | 1 +
.../python/relax/test_remove_redundant_reshape.py | 1 +
tests/python/relax/test_runtime_builtin.py | 1 +
...runtime_builtin_paged_attention_kv_cache_cpu.py | 1 +
..._builtin_paged_attention_kv_cache_flashinfer.py | 1 +
...runtime_builtin_paged_attention_kv_cache_tir.py | 1 +
.../relax/test_runtime_sampling_flashinfer.py | 1 +
tests/python/relax/test_testing_nn.py | 1 +
tests/python/relax/test_training_append_loss.py | 1 +
tests/python/relax/test_training_setup_trainer.py | 1 +
tests/python/relax/test_transform.py | 1 +
tests/python/relax/test_transform_alter_op_impl.py | 1 +
...st_transform_attach_attr_layout_free_buffers.py | 1 +
.../relax/test_transform_attach_global_symbol.py | 1 +
tests/python/relax/test_transform_bind_params.py | 1 +
.../relax/test_transform_bundle_model_params.py | 1 +
.../relax/test_transform_canonicalize_bindings.py | 1 +
tests/python/relax/test_transform_codegen_pass.py | 1 +
.../test_transform_combine_parallel_matmul.py | 1 +
.../relax/test_transform_convert_dataflow.py | 1 +
.../python/relax/test_transform_convert_layout.py | 1 +
tests/python/relax/test_transform_cse.py | 1 +
.../relax/test_transform_dead_code_elimination.py | 1 +
tests/python/relax/test_transform_decompose_ops.py | 1 +
.../relax/test_transform_expand_tuple_args.py | 1 +
.../python/relax/test_transform_few_shot_tuning.py | 1 +
.../test_transform_fold_batch_norm_to_conv2d.py | 1 +
tests/python/relax/test_transform_fold_constant.py | 1 +
tests/python/relax/test_transform_fuse_ops.py | 1 +
.../relax/test_transform_fuse_ops_by_pattern.py | 1 +
tests/python/relax/test_transform_gradient.py | 1 +
.../relax/test_transform_gradient_checkpoint.py | 1 +
.../relax/test_transform_gradient_numeric.py | 1 +
.../relax/test_transform_gradient_te_register.py | 1 +
.../test_transform_inline_private_functions.py | 1 +
tests/python/relax/test_transform_lambda_lift.py | 1 +
.../relax/test_transform_lazy_transform_params.py | 1 +
tests/python/relax/test_transform_legalize_ops.py | 1 +
.../relax/test_transform_legalize_ops_binary.py | 1 +
.../relax/test_transform_legalize_ops_ccl.py | 1 +
.../test_transform_legalize_ops_create_datatype.py | 1 +
.../test_transform_legalize_ops_distributed.py | 1 +
.../relax/test_transform_legalize_ops_grad.py | 1 +
.../relax/test_transform_legalize_ops_image.py | 1 +
..._transform_legalize_ops_index_linear_algebra.py | 1 +
.../test_transform_legalize_ops_manipulate.py | 1 +
.../python/relax/test_transform_legalize_ops_nn.py | 1 +
...st_transform_legalize_ops_search_statistical.py | 1 +
.../relax/test_transform_legalize_ops_unary.py | 1 +
.../relax/test_transform_lift_transform_params.py | 1 +
.../test_transform_meta_schedule_apply_database.py | 1 +
.../relax/test_transform_meta_schedule_tuning.py | 1 +
tests/python/relax/test_transform_normalize.py | 1 +
.../relax/test_transform_normalize_global_var.py | 1 +
...st_transform_operator_specific_normalization.py | 1 +
.../python/relax/test_transform_realize_vdevice.py | 1 +
.../relax/test_transform_remove_unused_outputs.py | 1 +
.../test_transform_reorder_take_after_matmul.py | 1 +
.../relax/test_transform_rewrite_cuda_graph.py | 1 +
.../test_transform_rewrite_dataflow_reshape.py | 1 +
...nsform_specialize_primfunc_based_on_callsite.py | 1 +
.../test_transform_static_plan_block_memory.py | 1 +
.../relax/test_transform_topological_sort.py | 1 +
.../python/relax/test_transform_update_vdevice.py | 1 +
tests/python/relax/test_tvmscript_ir_builder.py | 1 +
tests/python/relax/test_tvmscript_parser.py | 1 +
.../relax/test_tvmscript_parser_op_manipulate.py | 1 +
tests/python/relax/test_tvmscript_printer_relax.py | 1 +
tests/python/relax/test_tvmscript_pyfunc.py | 1 +
tests/python/relax/test_utils.py | 1 +
tests/python/relax/test_vm_build.py | 1 +
tests/python/relax/test_vm_callback_function.py | 1 +
tests/python/relax/test_vm_codegen_only.py | 1 +
tests/python/relax/test_vm_cuda_graph.py | 1 +
tests/python/relax/test_vm_instrument.py | 1 +
tests/python/relax/test_vm_profiler.py | 1 +
tests/python/relax/texture/adreno_utils.py | 1 +
tests/python/relax/texture/test_network.py | 1 +
tests/python/relax/texture/test_ops.py | 1 +
tests/python/relax/texture/test_texture_nd.py | 1 +
tests/python/runtime/test_rpc_base.py | 1 +
tests/python/runtime/test_runtime_container.py | 1 +
tests/python/runtime/test_runtime_error.py | 1 +
tests/python/runtime/test_runtime_measure.py | 1 +
tests/python/runtime/test_runtime_module_load.py | 4 +-
tests/python/runtime/test_runtime_nd_array.py | 1 +
tests/python/runtime/test_runtime_rpc.py | 5 +-
tests/python/runtime/test_runtime_trace.py | 1 +
...st_s_tir_analysis_calculate_allocated_memory.py | 1 +
.../test_s_tir_analysis_estimate_tir_flops.py | 1 +
.../test_s_tir_analysis_identify_memcpy.py | 1 +
.../analysis/test_sblock_buffer_access_lca.py | 1 +
.../s_tir/base/test_sblock_dependence_info.py | 1 +
.../s_tir/base/test_tir_te_extern_primfunc.py | 1 +
tests/python/s_tir/dlight/test_benchmark.py | 1 +
tests/python/s_tir/dlight/test_cpu_gemv.py | 1 +
tests/python/s_tir/dlight/test_gpu_conv.py | 1 +
tests/python/s_tir/dlight/test_gpu_fallback.py | 1 +
tests/python/s_tir/dlight/test_gpu_gemv.py | 1 +
.../s_tir/dlight/test_gpu_general_reduction.py | 3 +-
.../python/s_tir/dlight/test_gpu_low_batch_gemv.py | 1 +
tests/python/s_tir/dlight/test_gpu_matmul.py | 1 +
.../s_tir/dlight/test_gpu_matmul_tensorize.py | 1 +
tests/python/s_tir/dlight/test_gpu_reduction.py | 1 +
tests/python/s_tir/dlight/test_gpu_rmsnorm.py | 1 +
tests/python/s_tir/dlight/test_gpu_transpose.py | 1 +
tests/python/s_tir/dlight/test_primitives.py | 1 +
.../meta_schedule/test_meta_schedule_builder.py | 1 +
.../meta_schedule/test_meta_schedule_cost_model.py | 1 +
.../meta_schedule/test_meta_schedule_database.py | 1 +
...schedule_feature_extractor_per_store_feature.py | 7 +-
.../test_meta_schedule_mma_tensorize.py | 1 +
...eta_schedule_mutator_mutate_compute_location.py | 2 +-
.../test_meta_schedule_mutator_mutate_parallel.py | 2 +-
..._meta_schedule_mutator_mutate_thread_binding.py | 2 +-
.../test_meta_schedule_mutator_mutate_tile_size.py | 2 +-
.../test_meta_schedule_mutator_mutate_unroll.py | 2 +-
.../test_meta_schedule_post_order_apply.py | 1 +
...ule_postproc_disallow_async_strided_mem_copy.py | 1 +
...meta_schedule_postproc_disallow_dynamic_loop.py | 1 +
..._schedule_postproc_rewrite_cooperative_fetch.py | 1 +
.../test_meta_schedule_postproc_rewrite_layout.py | 1 +
...e_postproc_rewrite_parallel_vectorize_unroll.py | 1 +
...ta_schedule_postproc_rewrite_reduction_block.py | 1 +
...est_meta_schedule_postproc_rewrite_tensorize.py | 1 +
...meta_schedule_postproc_rewrite_unbound_block.py | 1 +
.../test_meta_schedule_postproc_verify_gpu_code.py | 9 +-
...est_meta_schedule_postproc_verify_vtcm_limit.py | 1 +
.../meta_schedule/test_meta_schedule_runner.py | 1 +
.../test_meta_schedule_schedule_rule_auto_bind.py | 1 +
...test_meta_schedule_schedule_rule_auto_inline.py | 1 +
.../test_meta_schedule_schedule_rule_mlt.py | 1 +
.../test_meta_schedule_schedule_rule_mlt_intrin.py | 1 +
.../test_meta_schedule_schedule_rule_mlt_tc.py | 1 +
...dule_schedule_rule_parallel_vectorize_unroll.py | 1 +
.../test_meta_schedule_search_strategy.py | 1 +
.../meta_schedule/test_meta_schedule_space_cpu.py | 1 +
.../meta_schedule/test_meta_schedule_space_cuda.py | 1 +
.../test_meta_schedule_space_cuda_async.py | 1 +
.../test_meta_schedule_space_post_opt.py | 1 +
.../test_meta_schedule_task_scheduler.py | 1 +
.../test_meta_schedule_trace_apply.py | 1 +
.../test_meta_schedule_tune_context.py | 1 +
.../s_tir/schedule/test_tir_schedule_analysis.py | 1 +
.../test_tir_schedule_annotate_buffer_access.py | 1 +
.../schedule/test_tir_schedule_block_scope.py | 1 +
.../s_tir/schedule/test_tir_schedule_blockize.py | 1 +
.../schedule/test_tir_schedule_cache_index.py | 1 +
.../schedule/test_tir_schedule_cache_read_write.py | 1 +
.../s_tir/schedule/test_tir_schedule_compute_at.py | 1 +
.../schedule/test_tir_schedule_compute_inline.py | 1 +
.../test_tir_schedule_decompose_padding.py | 1 +
.../s_tir/schedule/test_tir_schedule_error.py | 1 +
.../s_tir/schedule/test_tir_schedule_for_kind.py | 1 +
.../test_tir_schedule_fuse_reduction_epilogue.py | 1 +
...ir_schedule_fuse_reduction_epilogue_clipping.py | 1 +
...st_tir_schedule_fuse_reduction_epilogue_relu.py | 1 +
.../schedule/test_tir_schedule_instruction.py | 1 +
.../s_tir/schedule/test_tir_schedule_merge.py | 1 +
.../s_tir/schedule/test_tir_schedule_pad_einsum.py | 1 +
.../s_tir/schedule/test_tir_schedule_partition.py | 1 +
.../schedule/test_tir_schedule_read_write_at.py | 1 +
.../s_tir/schedule/test_tir_schedule_reduction.py | 1 +
.../s_tir/schedule/test_tir_schedule_reindex.py | 1 +
.../s_tir/schedule/test_tir_schedule_reorder.py | 1 +
.../test_tir_schedule_reorder_block_iter_var.py | 1 +
.../s_tir/schedule/test_tir_schedule_rfactor.py | 1 +
.../s_tir/schedule/test_tir_schedule_sampling.py | 1 +
.../test_tir_schedule_set_axis_separator.py | 1 +
.../s_tir/schedule/test_tir_schedule_set_dtype.py | 1 +
.../s_tir/schedule/test_tir_schedule_set_scope.py | 1 +
.../s_tir/schedule/test_tir_schedule_split_fuse.py | 1 +
.../s_tir/schedule/test_tir_schedule_state.py | 1 +
.../test_tir_schedule_state_cached_flags.py | 1 +
.../schedule/test_tir_schedule_storage_align.py | 1 +
.../s_tir/schedule/test_tir_schedule_tensorize.py | 1 +
..._tir_schedule_tensorize_ldmatrix_mma_numeric.py | 1 +
.../test_tir_schedule_tensorize_mfma_numeric.py | 1 +
.../s_tir/schedule/test_tir_schedule_trace.py | 1 +
.../schedule/test_tir_schedule_transform_layout.py | 1 +
.../s_tir/schedule/test_tir_schedule_utilities.py | 1 +
...test_s_tir_transform_annotate_irregular_loop.py | 1 +
.../test_s_tir_transform_canonicalize_loop.py | 1 +
.../test_s_tir_transform_compact_buffer_region.py | 1 +
...est_s_tir_transform_convert_blocks_to_opaque.py | 1 +
.../test_s_tir_transform_default_gpu_schedule.py | 1 +
.../test_s_tir_transform_hoist_expression.py | 1 +
.../transform/test_s_tir_transform_hoist_if.py | 6 +-
.../test_s_tir_transform_inject_double_buffer.py | 1 +
.../test_s_tir_transform_inject_permuted_layout.py | 1 +
.../test_s_tir_transform_inject_ptx_async_copy.py | 1 +
.../test_s_tir_transform_inject_ptx_ldg32.py | 1 +
...est_s_tir_transform_inject_software_pipeline.py | 1 +
.../test_s_tir_transform_inject_virtual_thread.py | 1 +
.../test_s_tir_transform_lift_thread_binding.py | 1 +
.../test_s_tir_transform_loop_partition.py | 1 +
...s_tir_transform_lower_cross_thread_reduction.py | 1 +
.../test_s_tir_transform_lower_init_block.py | 1 +
...test_s_tir_transform_lower_thread_all_reduce.py | 1 +
...transform_manifest_shared_memory_local_stage.py | 1 +
...st_s_tir_transform_memhammer_lower_auto_copy.py | 1 +
...form_merge_dynamic_shared_memory_allocations.py | 1 +
...sform_plan_update_buffer_allocation_location.py | 1 +
.../test_s_tir_transform_profiling_instr.py | 1 +
...transform_remove_weight_layout_rewrite_block.py | 1 +
...st_s_tir_transform_renormalize_split_pattern.py | 1 +
.../test_s_tir_transform_rewrite_unsafe_select.py | 1 +
.../transform/test_s_tir_transform_thread_sync.py | 1 +
.../test_s_tir_transform_unify_thread_binding.py | 1 +
tests/python/target/test_arm_target.py | 1 +
tests/python/target/test_llvm_features_info.py | 1 +
tests/python/target/test_riscv_features.py | 3 +-
tests/python/target/test_target_parser_mprofile.py | 1 +
tests/python/target/test_target_target.py | 2 +-
tests/python/target/test_virtual_device.py | 1 +
tests/python/target/test_x86_features.py | 1 +
tests/python/te/test_te_create_primfunc.py | 1 +
tests/python/te/test_te_tag.py | 1 +
tests/python/te/test_te_tensor.py | 1 +
tests/python/te/test_te_verify_compute.py | 1 +
tests/python/testing/test_testing.py | 1 +
tests/python/testing/test_tvm_testing_features.py | 1 +
.../python/testing/test_type_annotation_checker.py | 1 +
.../test_tir_analysis_verify_well_formed.py | 1 +
tests/python/tir-base/test_tir_base.py | 1 +
tests/python/tir-base/test_tir_buffer.py | 3 +-
tests/python/tir-base/test_tir_constructor.py | 1 +
tests/python/tir-base/test_tir_imm_values.py | 1 +
tests/python/tir-base/test_tir_index_map.py | 1 +
tests/python/tir-base/test_tir_intrin.py | 3 +-
tests/python/tir-base/test_tir_nodes.py | 45 +-
tests/python/tir-base/test_tir_ops.py | 3 +-
tests/python/tir-base/test_tir_ptx_cp_async.py | 1 +
tests/python/tir-base/test_tir_specialize.py | 1 +
tests/python/tir-base/test_tir_texture_scope.py | 1 +
.../tir-base/test_tir_unsafe_hide_buffer_access.py | 1 +
tests/python/tir-transform/test_tir_functor.py | 1 +
.../test_tir_inline_private_functions.py | 1 +
.../test_tir_transform_common_subexpr_elim.py | 1 +
.../test_tir_transform_convert_ssa.py | 1 +
...test_tir_transform_force_narrow_index_to_i32.py | 1 +
.../tir-transform/test_tir_transform_helpers.py | 1 +
.../test_tir_transform_lower_intrin.py | 1 +
.../test_tir_transform_narrow_datatype.py | 6 +-
.../test_tir_transform_remove_no_op.py | 1 +
.../tir-transform/test_tir_transform_simplify.py | 1 +
.../test_tir_transform_storage_rewrite.py | 1 +
.../tir-transform/test_tir_transform_vectorize.py | 1 +
.../tvmscript/test_tvmscript_error_report.py | 1 +
.../test_tvmscript_ir_builder_irmodule.py | 1 +
.../tvmscript/test_tvmscript_ir_builder_tir.py | 1 +
.../tvmscript/test_tvmscript_parser_evaluator.py | 1 +
tests/python/tvmscript/test_tvmscript_parser_ir.py | 1 +
.../tvmscript/test_tvmscript_parser_source.py | 1 +
.../tvmscript/test_tvmscript_printer_annotation.py | 1 +
.../python/tvmscript/test_tvmscript_printer_doc.py | 1 +
.../tvmscript/test_tvmscript_printer_highlight.py | 1 +
.../tvmscript/test_tvmscript_printer_metadata.py | 1 +
.../test_tvmscript_printer_structural_equal.py | 1 +
.../python/tvmscript/test_tvmscript_printer_tir.py | 1 +
.../python/tvmscript/test_tvmscript_regression.py | 1 +
tests/python/tvmscript/test_tvmscript_roundtrip.py | 1 +
.../tvmscript/test_tvmscript_syntax_sugar.py | 1 +
tests/scripts/ci.py | 1 +
tests/scripts/release/gather_prs.py | 1 +
tests/scripts/release/make_notes.py | 2 +-
tests/scripts/request_hook/request_hook.py | 6 +-
tests/scripts/task_build.py | 1 +
version.py | 13 +-
web/tests/python/prepare_test_libs.py | 2 +-
671 files changed, 1304 insertions(+), 1350 deletions(-)
diff --git a/.gitignore b/.gitignore
index cd44d5fcdd..93f5841047 100644
--- a/.gitignore
+++ b/.gitignore
@@ -281,3 +281,9 @@ tvm-site/
# Agent tracking files
LOG.md
STATUS.md
+
+# Local editable-install artifacts (pip install -e .)
+python/tvm_ffi/
+python/bin/
+python/typing_extensions.py
+python/*.dist-info/
diff --git a/apps/android_rpc/tests/android_rpc_test.py b/apps/android_rpc/tests/android_rpc_test.py
index f2cb384071..d1c27e23c8 100644
--- a/apps/android_rpc/tests/android_rpc_test.py
+++ b/apps/android_rpc/tests/android_rpc_test.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""Testcode for Android RPC.
To use it, start an RPC tracker with "python -m tvm.exec.rpc_tracker".
@@ -77,7 +78,7 @@ def test_rpc_module():
b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
time_f = f1.time_evaluator(f1.entry_name, dev, number=10)
cost = time_f(a, b).mean
- print("%g secs/op\n" % cost)
+ print(f"{cost:g} secs/op\n")
np.testing.assert_equal(b.numpy(), a.numpy() + 1)
diff --git a/apps/ios_rpc/init_proj.py b/apps/ios_rpc/init_proj.py
index 635ab4181a..2cca891198 100644
--- a/apps/ios_rpc/init_proj.py
+++ b/apps/ios_rpc/init_proj.py
@@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.
import argparse
-import re
default_team_id = "3FR42MXLK9"
default_tvm_build_dir = "path-to-tvm-ios-build-folder"
diff --git a/apps/ios_rpc/tests/ios_rpc_test.py b/apps/ios_rpc/tests/ios_rpc_test.py
index efdec8b524..b29694bbd0 100644
--- a/apps/ios_rpc/tests/ios_rpc_test.py
+++ b/apps/ios_rpc/tests/ios_rpc_test.py
@@ -21,9 +21,6 @@ And configure the proxy host field as commented.
"""
import argparse
-import os
-import re
-import sys
import numpy as np
@@ -77,7 +74,7 @@ def test_rpc_module(host, port, key, mode):
b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
time_f = f1.time_evaluator(f1.entry_name, dev, number=10)
cost = time_f(a, b).mean
- print("Metal: %g secs/op" % cost)
+ print(f"Metal: {cost:g} secs/op")
np.testing.assert_equal(b.numpy(), a.numpy() + 1)
diff --git a/ci/jenkins/generated/lint_jenkinsfile.groovy b/ci/jenkins/generated/lint_jenkinsfile.groovy
deleted file mode 100644
index d6a1833dee..0000000000
--- a/ci/jenkins/generated/lint_jenkinsfile.groovy
+++ /dev/null
@@ -1,524 +0,0 @@
-// 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.
-// -*- mode: groovy -*-
-
-// 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.
-
-// Jenkins pipeline
-// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/
-
-// Docker env used for testing
-// Different image may have different version tag
-// because some of them are more stable than anoter.
-//
-// Docker images are maintained by PMC, cached in dockerhub
-// and remains relatively stable over the time.
-// Flow for upgrading docker env(need commiter)
-//
-// - Send PR to upgrade build script in the repo
-// - Build the new docker image
-// - Tag the docker image with a new version and push to a binary cache.
-// - Update the version in the Jenkinsfile, send a PR
-// - Fix any issues wrt to the new image version in the PR
-// - Merge the PR and now we are in new version
-// - Tag the new version as the lates
-// - Periodically cleanup the old versions on local workers
-//
-
-// ============================= IMPORTANT NOTE =============================
-// This file is generated by 'jenkins/generate.py'. Do not edit this file directly!
-// Make edits to 'jenkins/Jenkinsfile.j2' and regenerate this with
-// 'python3 jenkins/generate.py'
-// Note: This timestamp is here to ensure that updates to the Jenkinsfile are
-// always rebased on main before merging:
-// Generated at 2026-02-09T16:32:44.083887
-
-import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
-// These are set at runtime from data in ci/jenkins/docker-images.yml, update
-// image tags in that file
-ci_lint = ''
-ci_gpu = ''
-ci_cpu = ''
-ci_minimal = ''
-ci_wasm = ''
-ci_cortexm = ''
-ci_arm = ''
-ci_riscv = ''
-
-// Parameters to allow overriding (in Jenkins UI), the images
-// to be used by a given build. When provided, they take precedence
-// over default values above.
-properties([
- parameters([
- string(name: 'ci_arm_param', defaultValue: ''),
- string(name: 'ci_cpu_param', defaultValue: ''),
- string(name: 'ci_gpu_param', defaultValue: ''),
- string(name: 'ci_lint_param', defaultValue: ''),
- string(name: 'ci_wasm_param', defaultValue: ''),
- ])
-])
-
-// Placeholders for newly built Docker image names (if rebuild_docker_images
-// is used)
- built_ci_arm = null;
- built_ci_cpu = null;
- built_ci_gpu = null;
- built_ci_lint = null;
- built_ci_wasm = null;
-
-// Global variable assigned during Sanity Check that holds the sha1 which should be
-// merged into the PR in all branches.
-upstream_revision = null
-
-// command to start a docker container
-docker_run = 'docker/bash.sh --env CI --env PLATFORM --env TVM_SHARD_INDEX --env TVM_NUM_SHARDS --env RUN_DISPLAY_URL --env PLATFORM --env SKIP_SLOW_TESTS --env TEST_STEP_NAME'
-docker_build = 'docker/build.sh'
-// timeout in minutes
-max_time = 180
-rebuild_docker_images = false
-
-s3_bucket = 'tvm-jenkins-artifacts-prod'
-s3_prefix = "tvm/${env.BRANCH_NAME}/${env.BUILD_NUMBER}"
-
-// Jenkins script root directory
-jenkins_scripts_root = "ci/scripts/jenkins"
-
-
-// General note: Jenkins has limits on the size of a method (or top level code)
-// that are pretty strict, so most usage of groovy methods in these templates
-// are purely to satisfy the JVM
-def per_exec_ws(folder) {
- return "workspace/exec_${env.EXECUTOR_NUMBER}/" + folder
-}
-
-// initialize source codes
-def init_git() {
- retry(5) {
- checkout scm
- }
-
- // Add more info about job node
- sh (
- script: './tests/scripts/task_show_node_info.sh',
- label: 'Show executor node info',
- )
-
- // Determine merge commit to use for all stages
- if (env.BRANCH_NAME == 'main') {
- // Only set upstream_revision to HEAD and skip merging to avoid a race with another commit merged to main.
- update_upstream_revision("HEAD")
- } else {
- // This is PR branch so merge with latest main.
- merge_with_main()
- }
-
- sh(
- script: """
- set -eux
- . ${jenkins_scripts_root}/retry.sh
- retry 3 timeout 5m git submodule update --init --recursive -f --jobs 0
- """,
- label: 'Update git submodules',
- )
- checkout_trusted_files()
-}
-
-def update_upstream_revision(git_ref) {
- if (upstream_revision == null) {
- upstream_revision = sh(
- script: "git log -1 ${git_ref} --format=\'%H\'",
- label: 'Determine upstream revision',
- returnStdout: true,
- ).trim()
- }
-}
-
-def merge_with_main() {
- sh (
- script: 'git fetch origin main',
- label: 'Fetch upstream',
- )
- update_upstream_revision("FETCH_HEAD")
- sh (
- script: "git -c user.name=TVM-Jenkins -c user.email=jenkins@tvm.apache.org merge ${upstream_revision}",
- label: 'Merge to origin/main'
- )
-}
-
-def docker_init(image) {
- // Clear out all Docker images that aren't going to be used
- sh(
- script: """
- set -eux
- docker image ls --all
- IMAGES=\$(docker image ls --all --format '{{.Repository}}:{{.Tag}} {{.ID}}')
-
- echo -e "Found images:\\n\$IMAGES"
- echo "\$IMAGES" | { grep -vE '${image}' || test \$? = 1; } | { xargs docker rmi || test \$? = 123; }
-
- docker image ls --all
- """,
- label: 'Clean old Docker images',
- )
-
- if (image.contains("amazonaws.com")) {
- // If this string is in the image name it's from ECR and needs to be pulled
- // with the right credentials
- ecr_pull(image)
- } else {
- sh(
- script: """
- set -eux
- . ${jenkins_scripts_root}/retry.sh
- retry 5 docker pull ${image}
- """,
- label: 'Pull docker image',
- )
- }
-}
-
-def ecr_pull(full_name) {
- aws_account_id = sh(
- returnStdout: true,
- script: 'aws sts get-caller-identity | grep Account | cut -f4 -d\\"',
- label: 'Get AWS ID'
- ).trim()
-
- try {
- withEnv([
- "AWS_ACCOUNT_ID=${aws_account_id}",
- 'AWS_DEFAULT_REGION=us-west-2',
- "AWS_ECR_REPO=${aws_account_id}.dkr.ecr.us-west-2.amazonaws.com"]) {
- sh(
- script: '''
- set -eux
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ECR_REPO
- ''',
- label: 'Log in to ECR'
- )
- sh(
- script: """
- set -eux
- . ${jenkins_scripts_root}/retry.sh
- retry 5 docker pull ${full_name}
- """,
- label: 'Pull image from ECR'
- )
- }
- } finally {
- withEnv([
- "AWS_ACCOUNT_ID=${aws_account_id}",
- 'AWS_DEFAULT_REGION=us-west-2',
- "AWS_ECR_REPO=${aws_account_id}.dkr.ecr.us-west-2.amazonaws.com"]) {
- sh(
- script: 'docker logout $AWS_ECR_REPO',
- label: 'Clean up login credentials'
- )
- }
- }
-}
-
-def should_skip_slow_tests(pr_number) {
- withCredentials([string(
- credentialsId: 'tvm-bot-jenkins-reader',
- variable: 'GITHUB_TOKEN',
- )]) {
- // Exit code of 1 means run slow tests, exit code of 0 means skip slow tests
- result = sh (
- returnStatus: true,
- script: "./${jenkins_scripts_root}/should_run_slow_tests.py --pr '${pr_number}'",
- label: 'Check if CI should run slow tests',
- )
- }
- return result == 0
-}
-
-def cancel_previous_build() {
- // cancel previous build if it is not on main.
- if (env.BRANCH_NAME != 'main') {
- def buildNumber = env.BUILD_NUMBER as int
- // Milestone API allows us to cancel previous build
- // with the same milestone number
- if (buildNumber > 1) milestone(buildNumber - 1)
- milestone(buildNumber)
- }
-}
-
-def is_last_build() {
- // check whether it is last build
- try {
- return currentBuild.number == currentBuild.rawBuild.project.getLastBuild().number
- } catch (Throwable ex) {
- echo 'Error during check is_last_build ' + ex.toString()
- return false
- }
-}
-
-def checkout_trusted_files() {
- // trust everything from branch builds
- if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
- return;
- }
-
- // trust peoople listed in CONTRIBUTING.md
- grep_code = sh(
- returnStatus: true,
- script: "git show '${upstream_revision}:CONTRIBUTORS.md' | grep '@${env.CHANGE_AUTHOR}'",
- label: 'Check if change is from a contributor',
- )
-
- if (grep_code == 1) {
- // Any scripts that run on the bare host and not inside a Docker container
- // (especially those that access secrets) should be checked out here so
- // only trusted versions are used in CI
- sh(
- script: "git checkout ${upstream_revision} ${jenkins_scripts_root}/.",
- label: 'Check out trusted files',
- )
- }
-}
-
-def should_skip_ci(pr_number) {
- if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
- // never skip CI on build sourced from a branch
- return false
- }
- glob_skip_ci_code = sh (
- returnStatus: true,
- script: "./${jenkins_scripts_root}/git_skip_ci_globs.py",
- label: 'Check if CI should be skipped due to changed files',
- )
- if (glob_skip_ci_code == 0) {
- return true
- }
- withCredentials([string(
- credentialsId: 'tvm-bot-jenkins-reader',
- variable: 'GITHUB_TOKEN',
- )]) {
- // Exit code of 1 means run full CI (or the script had an error, so run
- // full CI just in case). Exit code of 0 means skip CI.
- git_skip_ci_code = sh (
- returnStatus: true,
- script: "./${jenkins_scripts_root}/git_skip_ci.py --pr '${pr_number}'",
- label: 'Check if CI should be skipped',
- )
- }
- return git_skip_ci_code == 0
-}
-
-def check_pr(pr_number) {
- if (env.BRANCH_NAME == null || !env.BRANCH_NAME.startsWith('PR-')) {
- // never skip CI on build sourced from a branch
- return false
- }
- withCredentials([string(
- credentialsId: 'tvm-bot-jenkins-reader',
- variable: 'GITHUB_TOKEN',
- )]) {
- sh (
- script: "python3 ${jenkins_scripts_root}/check_pr.py --pr ${pr_number}",
- label: 'Check PR title and body',
- )
- }
-
-}
-
-def prepare(node_type) {
- stage('Prepare') {
- node(node_type) {
- ws("workspace/exec_${env.EXECUTOR_NUMBER}/tvm/prepare") {
- init_git()
-
- check_pr(env.CHANGE_ID)
-
- if (env.DETERMINE_DOCKER_IMAGES == 'yes') {
- sh(
- script: "./${jenkins_scripts_root}/determine_docker_images.py ci_arm ci_cpu ci_gpu ci_lint ci_wasm ",
- label: 'Decide whether to use tlcpack or tlcpackstaging for Docker images',
- )
- // Pull image names from the results of should_rebuild_docker.py
- ci_arm = sh(
- script: "cat .docker-image-names/ci_arm",
- label: "Find docker image name for ci_arm",
- returnStdout: true,
- ).trim()
- ci_cpu = sh(
- script: "cat .docker-image-names/ci_cpu",
- label: "Find docker image name for ci_cpu",
- returnStdout: true,
- ).trim()
- ci_gpu = sh(
- script: "cat .docker-image-names/ci_gpu",
- label: "Find docker image name for ci_gpu",
- returnStdout: true,
- ).trim()
- ci_lint = sh(
- script: "cat .docker-image-names/ci_lint",
- label: "Find docker image name for ci_lint",
- returnStdout: true,
- ).trim()
- ci_wasm = sh(
- script: "cat .docker-image-names/ci_wasm",
- label: "Find docker image name for ci_wasm",
- returnStdout: true,
- ).trim()
- }
-
- ci_arm = params.ci_arm_param ?: ci_arm
- ci_cpu = params.ci_cpu_param ?: ci_cpu
- ci_gpu = params.ci_gpu_param ?: ci_gpu
- ci_lint = params.ci_lint_param ?: ci_lint
- ci_wasm = params.ci_wasm_param ?: ci_wasm
-
- sh (script: """
- echo "Docker images being used in this build:"
- echo " ci_arm = ${ci_arm}"
- echo " ci_cpu = ${ci_cpu}"
- echo " ci_gpu = ${ci_gpu}"
- echo " ci_lint = ${ci_lint}"
- echo " ci_wasm = ${ci_wasm}"
- """, label: 'Docker image names')
-
- is_docs_only_build = sh (
- returnStatus: true,
- script: "./${jenkins_scripts_root}/git_change_docs.sh",
- label: 'Check for docs only changes',
- )
- skip_ci = should_skip_ci(env.CHANGE_ID)
- skip_slow_tests = should_skip_slow_tests(env.CHANGE_ID)
- rebuild_docker_images = sh (
- returnStatus: true,
- script: "./${jenkins_scripts_root}/git_change_docker.sh",
- label: 'Check for any docker changes',
- )
-
- if (skip_ci) {
- // Don't rebuild when skipping CI
- rebuild_docker_images = false
- }
- }
- }
- }
-}
-def ci_setup(image) {
- sh (
- script: "${docker_run} ${image} ./tests/scripts/task_clear_pytest.sh",
- label: 'Clean up old workspace',
- )
-}
-
-def python_unittest(image) {
- sh (
- script: "${docker_run} ${image} ./tests/scripts/task_python_unittest.sh",
- label: 'Run Python unit tests',
- )
-}
-
-def make_cpp_tests(image, build_dir) {
- sh (
- script: """
- set -eux
- ${docker_run} ${image} python3 ./tests/scripts/task_build.py \
- --sccache-bucket tvm-sccache-prod \
- --sccache-region us-west-2 \
- --cmake-target cpptest \
- --build-dir ${build_dir}
- """,
- label: 'Make C++ tests',
- )
-}
-
-def cmake_build(image, path) {
- sh (
- script: "${docker_run} --env CI_NUM_EXECUTORS ${image} ./tests/scripts/task_build.py --sccache-bucket tvm-sccache-prod --sccache-region us-west-2 --build-dir ${path}",
- label: 'Run CMake build',
- )
-}
-def cpp_unittest(image) {
- sh (
- script: "${docker_run} --env CI_NUM_EXECUTORS ${image} ./tests/scripts/task_cpp_unittest.sh",
- label: 'Run C++ tests',
- )
-}
-
-cancel_previous_build()
-
-try {
- prepare('CPU-SMALL-SPOT')
-} catch(Exception ex) {
- prepare('CPU-SMALL')
-}
-
-stage('Lint') {
- parallel(
- 'Lint 1 of 2': {
- node('CPU-SMALL') {
- ws("workspace/exec_${env.EXECUTOR_NUMBER}/tvm/lint") {
- init_git()
- docker_init(ci_lint)
- timeout(time: max_time, unit: 'MINUTES') {
- withEnv([
- 'TVM_NUM_SHARDS=2',
- 'TEST_STEP_NAME=Lint',
- 'TVM_SHARD_INDEX=0',
- "SKIP_SLOW_TESTS=${skip_slow_tests}"], {
- sh (
- script: "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh",
- label: 'Run lint',
- )
- })
- }
- }
- }
- },
- 'Lint 2 of 2': {
- node('CPU-SMALL') {
- ws("workspace/exec_${env.EXECUTOR_NUMBER}/tvm/lint") {
- init_git()
- docker_init(ci_lint)
- timeout(time: max_time, unit: 'MINUTES') {
- withEnv([
- 'TVM_NUM_SHARDS=2',
- 'TEST_STEP_NAME=Lint',
- 'TVM_SHARD_INDEX=1',
- "SKIP_SLOW_TESTS=${skip_slow_tests}"], {
- sh (
- script: "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh",
- label: 'Run lint',
- )
- })
- }
- }
- }
- },
- )
-}
diff --git a/ci/jenkins/templates/lint_jenkinsfile.groovy.j2 b/ci/jenkins/templates/lint_jenkinsfile.groovy.j2
deleted file mode 100644
index 7423ee1710..0000000000
--- a/ci/jenkins/templates/lint_jenkinsfile.groovy.j2
+++ /dev/null
@@ -1,58 +0,0 @@
-// 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.
-{% include "utils/base.groovy.j2" with context %}
-{% import 'utils/macros.j2' as m with context -%}
-
-{% macro sharded_lint_step(name, num_shards, docker_image, node, ws) %}
-{% for shard_index in range(1, num_shards + 1) %}
- '{{ name }} {{ shard_index }} of {{ num_shards }}': {
- node('{{ node }}') {
- ws({{ m.per_exec_ws(ws) }}) {
- init_git()
- docker_init({{ docker_image }})
- timeout(time: max_time, unit: 'MINUTES') {
- withEnv([
- 'TVM_NUM_SHARDS={{ num_shards }}',
- 'TEST_STEP_NAME={{ name }}',
- 'TVM_SHARD_INDEX={{ shard_index - 1 }}',
- "SKIP_SLOW_TESTS=${skip_slow_tests}"], {
- {{ caller() | trim | indent(width=6) }}
- })
- }
- }
- }
- },
-{% endfor %}
-{% endmacro %}
-
-stage('Lint') {
- parallel(
- {% call sharded_lint_step(
- name='Lint',
- num_shards=2,
- node='CPU-SMALL',
- ws='tvm/lint',
- docker_image='ci_lint',
- )
- %}
- sh (
- script: "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh",
- label: 'Run lint',
- )
- {% endcall %}
- )
-}
diff --git a/ci/scripts/github/github_cc_reviewers.py b/ci/scripts/github/github_cc_reviewers.py
index 0ae36c2200..1bee762bf1 100755
--- a/ci/scripts/github/github_cc_reviewers.py
+++ b/ci/scripts/github/github_cc_reviewers.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
import argparse
import json
@@ -22,7 +23,7 @@ import os
import re
import sys
from pathlib import Path
-from typing import Any, Dict, List
+from typing import List
from urllib import error
# Hackery to enable importing of utils from ci/scripts/jenkins
diff --git a/ci/scripts/github/github_commenter.py b/ci/scripts/github/github_commenter.py
index 1f45c3e787..5b5893b829 100644
--- a/ci/scripts/github/github_commenter.py
+++ b/ci/scripts/github/github_commenter.py
@@ -15,12 +15,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402, E501, RUF012
import logging
import re
import sys
from pathlib import Path
-from typing import Any, Dict, List, Optional, Tuple, Union
+from typing import Any, Dict, List, Optional, Tuple
# Hackery to enable importing of utils from ci/scripts/jenkins
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
diff --git a/ci/scripts/github/github_pr_comment.py b/ci/scripts/github/github_pr_comment.py
index 23af9a49bd..2d523b21b3 100755
--- a/ci/scripts/github/github_pr_comment.py
+++ b/ci/scripts/github/github_pr_comment.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
import argparse
import json
import os
diff --git a/ci/scripts/github/github_skipped_tests_comment.py b/ci/scripts/github/github_skipped_tests_comment.py
index df8a7f6636..74224195c5 100755
--- a/ci/scripts/github/github_skipped_tests_comment.py
+++ b/ci/scripts/github/github_skipped_tests_comment.py
@@ -15,7 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-import inspect
+# ruff: noqa: E501
import json
import logging
import os
diff --git a/ci/scripts/github/github_tag_teams.py b/ci/scripts/github/github_tag_teams.py
index 26b624d6c8..81956cedd7 100755
--- a/ci/scripts/github/github_tag_teams.py
+++ b/ci/scripts/github/github_tag_teams.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
import argparse
import json
diff --git a/ci/scripts/github/github_tvmbot.py b/ci/scripts/github/github_tvmbot.py
index 44faa5effa..0d8981b1ba 100755
--- a/ci/scripts/github/github_tvmbot.py
+++ b/ci/scripts/github/github_tvmbot.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402, E501, F841, RUF012
import argparse
import json
@@ -193,7 +194,7 @@ class PR:
owner: str,
repo: str,
dry_run: bool = False,
- raw_data: Dict[str, Any] = None,
+ raw_data: Optional[Dict[str, Any]] = None,
):
self.owner = owner
self.number = number
diff --git a/ci/scripts/github/ping_reviewers.py b/ci/scripts/github/ping_reviewers.py
index a859fd7bec..abe2ac0677 100755
--- a/ci/scripts/github/ping_reviewers.py
+++ b/ci/scripts/github/ping_reviewers.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402, E501, F821
import argparse
import datetime
@@ -23,7 +24,7 @@ import re
import sys
import textwrap
from pathlib import Path
-from typing import List
+from typing import List, Optional
# Hackery to enable importing of utils from ci/scripts/jenkins
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
@@ -34,7 +35,7 @@ from git_utils import git, parse_remote
GIT_DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
-def prs_query(user: str, repo: str, cursor: str = None):
+def prs_query(user: str, repo: str, cursor: Optional[str] = None):
after = ""
if cursor is not None:
after = f', before:"{cursor}"'
diff --git a/ci/scripts/github/update_branch.py b/ci/scripts/github/update_branch.py
index b175423e5d..62552989ae 100755
--- a/ci/scripts/github/update_branch.py
+++ b/ci/scripts/github/update_branch.py
@@ -15,13 +15,14 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
import argparse
import json
import os
import sys
from pathlib import Path
-from typing import Any, Dict
+from typing import Any, Dict, Optional
# Hackery to enable importing of utils from ci/scripts/jenkins
REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
@@ -57,7 +58,7 @@ _commit_query_fields = """
"""
-def commits_query(user: str, repo: str, cursor: str = None):
+def commits_query(user: str, repo: str, cursor: Optional[str] = None):
"""
Create a GraphQL query to find the last N commits along with their statuses
and some metadata (paginated after 'cursor')
diff --git a/ci/scripts/jenkins/check_pr.py b/ci/scripts/jenkins/check_pr.py
index 801efa58fc..445c636fea 100755
--- a/ci/scripts/jenkins/check_pr.py
+++ b/ci/scripts/jenkins/check_pr.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import argparse
import json
import os
diff --git a/ci/scripts/jenkins/cmd_utils.py b/ci/scripts/jenkins/cmd_utils.py
index 625cf27239..4b33ce44d2 100644
--- a/ci/scripts/jenkins/cmd_utils.py
+++ b/ci/scripts/jenkins/cmd_utils.py
@@ -20,7 +20,6 @@ import os
import re
import subprocess
import sys
-import tempfile
from pathlib import Path
from typing import List
diff --git a/ci/scripts/jenkins/determine_docker_images.py b/ci/scripts/jenkins/determine_docker_images.py
index e1b9871843..a0d5b633e5 100755
--- a/ci/scripts/jenkins/determine_docker_images.py
+++ b/ci/scripts/jenkins/determine_docker_images.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import argparse
import configparser
import datetime
diff --git a/ci/scripts/jenkins/git_skip_ci_globs.py b/ci/scripts/jenkins/git_skip_ci_globs.py
index bc225c337d..dca941e7c8 100755
--- a/ci/scripts/jenkins/git_skip_ci_globs.py
+++ b/ci/scripts/jenkins/git_skip_ci_globs.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import argparse
import fnmatch
diff --git a/ci/scripts/jenkins/git_utils.py b/ci/scripts/jenkins/git_utils.py
index 82e87df429..05301a046a 100644
--- a/ci/scripts/jenkins/git_utils.py
+++ b/ci/scripts/jenkins/git_utils.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, RUF005
import base64
import json
@@ -128,7 +129,7 @@ class GitHubRepo:
logging.info(f"Got response from {full_url}: {content}")
try:
response = json.loads(content)
- except json.decoder.JSONDecodeError as e:
+ except json.decoder.JSONDecodeError:
return content
return response
diff --git a/ci/scripts/jenkins/pytest_wrapper.py b/ci/scripts/jenkins/pytest_wrapper.py
index a7d04cf685..fc00fc8159 100755
--- a/ci/scripts/jenkins/pytest_wrapper.py
+++ b/ci/scripts/jenkins/pytest_wrapper.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import argparse
import logging
import os
diff --git a/ci/scripts/jenkins/should_rebuild_docker.py b/ci/scripts/jenkins/should_rebuild_docker.py
index 5b7aa57838..238bea04ef 100755
--- a/ci/scripts/jenkins/should_rebuild_docker.py
+++ b/ci/scripts/jenkins/should_rebuild_docker.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import argparse
import datetime
import json
diff --git a/conftest.py b/conftest.py
index 95a6815f05..dd32937620 100644
--- a/conftest.py
+++ b/conftest.py
@@ -14,13 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import hashlib
import os
import sys
from pathlib import Path
-import pytest
-
pytest_plugins = ["tvm.testing.plugin"]
IS_IN_CI = os.getenv("CI", "") == "true"
REPO_ROOT = Path(__file__).resolve().parent
diff --git a/docs/conf.py b/docs/conf.py
index c8eb5e7b45..57d08025c4 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402, E501, F401
#
# documentation build configuration file, created by
@@ -58,7 +59,7 @@ sys.path.insert(0, str(tvm_path.resolve() / "docs"))
# General information about the project.
project = "tvm"
author = "Apache Software Foundation"
-copyright = "2020 - 2023, %s" % author
+copyright = f"2020 - 2023, {author}"
github_doc_root = "https://github.com/apache/tvm/tree/main/docs/"
os.environ["TVM_BUILD_DOC"] = "1"
@@ -71,7 +72,7 @@ def git_describe_version(original_version):
exec(compile(open(ver_py, "rb").read(), ver_py, "exec"), libver, libver)
_, gd_version = libver["git_describe_version"]()
if gd_version != original_version:
- print("Use git describe based version %s" % gd_version)
+ print(f"Use git describe based version {gd_version}")
return gd_version
@@ -391,7 +392,7 @@ latex_elements = {}
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
- (main_doc, "%s.tex" % project, project, author, "manual"),
+ (main_doc, f"{project}.tex", project, author, "manual"),
]
intersphinx_mapping = {
@@ -436,7 +437,7 @@ class WithinSubsectionOrder:
):
index = within_subsection_order[self.src_dir].index(filename)
assert index < 1e10
- return "\0%010d" % index
+ return f"\0{index:010d}"
# Otherwise, sort by filename
return filename
@@ -468,9 +469,8 @@ sphinx_gallery_conf = {
"download_all_examples": False,
"min_reported_time": 60,
"expected_failing_examples": [],
- "reset_modules": ("matplotlib", "seaborn", force_gc),
+ "reset_modules": ("matplotlib", "seaborn", force_gc, install_request_hook),
"promote_jupyter_magic": True,
- "reset_modules": (install_request_hook),
}
autodoc_default_options = {
@@ -603,7 +603,7 @@ def update_alias_docstring(name, obj, lines):
if hasattr(sys.modules[amod], target_name):
obj_type = ":py:func" if callable(obj) else ":py:class"
- lines.append(".. rubric:: Alias of %s:`%s.%s`" % (obj_type, amod, target_name))
+ lines.append(f".. rubric:: Alias of {obj_type}:`{amod}.{target_name}`")
tvm_class_name_rewrite_map = {
diff --git a/docs/deep_dive/relax/tutorials/relax_creation.py b/docs/deep_dive/relax/tutorials/relax_creation.py
index 7b2d9a1ad2..a20ad73504 100644
--- a/docs/deep_dive/relax/tutorials/relax_creation.py
+++ b/docs/deep_dive/relax/tutorials/relax_creation.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _relax-creation:
diff --git a/docs/deep_dive/relax/tutorials/relax_transformation.py b/docs/deep_dive/relax/tutorials/relax_transformation.py
index d3cecd32b3..930bfae547 100644
--- a/docs/deep_dive/relax/tutorials/relax_transformation.py
+++ b/docs/deep_dive/relax/tutorials/relax_transformation.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _relax-transform:
diff --git a/docs/deep_dive/tensor_ir/tutorials/tir_creation.py b/docs/deep_dive/tensor_ir/tutorials/tir_creation.py
index a7c35c6d44..0254dbb3a0 100644
--- a/docs/deep_dive/tensor_ir/tutorials/tir_creation.py
+++ b/docs/deep_dive/tensor_ir/tutorials/tir_creation.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _tir-creation:
diff --git a/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py b/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py
index 26bc5e7a0d..71758152fb 100644
--- a/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py
+++ b/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _tir-transform:
diff --git a/docs/get_started/tutorials/ir_module.py b/docs/get_started/tutorials/ir_module.py
index acb0324b95..e47e4fba4b 100644
--- a/docs/get_started/tutorials/ir_module.py
+++ b/docs/get_started/tutorials/ir_module.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _ir_module:
diff --git a/docs/get_started/tutorials/quick_start.py b/docs/get_started/tutorials/quick_start.py
index 65570edde9..a1de5686a9 100644
--- a/docs/get_started/tutorials/quick_start.py
+++ b/docs/get_started/tutorials/quick_start.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402, E501
"""
.. _quick_start:
diff --git a/docs/how_to/tutorials/cross_compilation_and_rpc.py b/docs/how_to/tutorials/cross_compilation_and_rpc.py
index 23c0724a52..a6e9bc8e71 100644
--- a/docs/how_to/tutorials/cross_compilation_and_rpc.py
+++ b/docs/how_to/tutorials/cross_compilation_and_rpc.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""
.. _tutorial-cross-compilation-and-rpc:
@@ -195,7 +196,7 @@ np.testing.assert_equal(b.numpy(), a.numpy() + 1)
time_f = func.time_evaluator(func.entry_name, dev, number=10)
cost = time_f(a, b).mean
-print("%g secs/op" % cost)
+print(f"{cost:g} secs/op")
#########################################################################
# Run OpenCL Kernel Remotely by RPC
diff --git a/docs/how_to/tutorials/customize_opt.py b/docs/how_to/tutorials/customize_opt.py
index 1a592918aa..342184dc15 100644
--- a/docs/how_to/tutorials/customize_opt.py
+++ b/docs/how_to/tutorials/customize_opt.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402, E501, F401
"""
.. _customize_opt:
diff --git a/docs/how_to/tutorials/e2e_opt_model.py b/docs/how_to/tutorials/e2e_opt_model.py
index 26617ae730..6bd1be512c 100644
--- a/docs/how_to/tutorials/e2e_opt_model.py
+++ b/docs/how_to/tutorials/e2e_opt_model.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _optimize_model:
diff --git a/docs/how_to/tutorials/export_and_load_executable.py b/docs/how_to/tutorials/export_and_load_executable.py
index 4074dac4a6..1b4092125b 100644
--- a/docs/how_to/tutorials/export_and_load_executable.py
+++ b/docs/how_to/tutorials/export_and_load_executable.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E402
"""
.. _deploy_export_and_load_executable:
diff --git a/docs/how_to/tutorials/optimize_llm.py b/docs/how_to/tutorials/optimize_llm.py
index a333f03c3b..d8d3842a79 100644
--- a/docs/how_to/tutorials/optimize_llm.py
+++ b/docs/how_to/tutorials/optimize_llm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""
.. _opt_llm:
@@ -377,7 +378,7 @@ pprint(named_params[:5]) # Only show the first 5 parameters for demonstration
@register_pipeline("opt_llm")
def _pipeline( # pylint: disable=too-many-arguments
- ext_mods: List[nn.ExternModule] = None,
+ ext_mods: Optional[List[nn.ExternModule]] = None,
):
ext_mods = ext_mods or []
diff --git a/jvm/core/src/test/scripts/prepare_test_libs.py b/jvm/core/src/test/scripts/prepare_test_libs.py
index a268c582ee..5917151372 100644
--- a/jvm/core/src/test/scripts/prepare_test_libs.py
+++ b/jvm/core/src/test/scripts/prepare_test_libs.py
@@ -45,7 +45,7 @@ def prepare_relax_lib(base_path):
def prepare_cpu_lib(base_path):
target = "llvm"
if not tvm.runtime.enabled(target):
- raise RuntimeError("Target %s is not enbaled" % target)
+ raise RuntimeError(f"Target {target} is not enbaled")
n = te.var("n")
A = te.placeholder((n,), name="A")
B = te.placeholder((n,), name="B")
diff --git a/jvm/core/src/test/scripts/test_rpc_proxy_server.py b/jvm/core/src/test/scripts/test_rpc_proxy_server.py
index 50e461daa5..2ce148c321 100644
--- a/jvm/core/src/test/scripts/test_rpc_proxy_server.py
+++ b/jvm/core/src/test/scripts/test_rpc_proxy_server.py
@@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-import time
from tvm.rpc import proxy
diff --git a/pyproject.toml b/pyproject.toml
index a3b4c6d618..633e69f5a7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -184,7 +184,17 @@ python_classes = ["Test*"]
python_functions = ["test_*"]
[tool.ruff]
-include = ["python/**/*.py", "tests/**/*.py", "docs/**/*.py"]
+include = [
+ "python/**/*.py",
+ "tests/**/*.py",
+ "docs/**/*.py",
+ "apps/**/*.py",
+ "ci/scripts/**/*.py",
+ "conftest.py",
+ "jvm/**/*.py",
+ "version.py",
+ "web/tests/**/*.py",
+]
line-length = 100
indent-width = 4
target-version = "py39"
@@ -207,48 +217,20 @@ select = [
"RUF", # ruff, https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
]
ignore = [
- "E101", # mixed-spaces-and-tabs (legacy code)
- "E402", # module-import-not-at-top-of-file
- "E501", # line-too-long (let ruff-format handle soft wrapping)
- "E711", # none-comparison
- "E712", # true-false-comparison
- "E721", # type-comparison
- "E731", # lambda-assignment (common pattern in TVM)
- "E741", # ambiguous-variable-name (common in math-heavy code)
- "F401", # unused-import (too many false positives with __init__.py re-exports)
- "F402", # import-shadowed-by-loop-var
- "F403", # undefined-local-with-import-star
- "F405", # undefined-local-with-import-star-usage
- "F601", # multi-value-repeated-key-literal
- "F811", # redefined-while-unused
- "F821", # undefined-name (false positives from star imports)
- "F841", # unused-variable (too many in test code)
- "UP006", # non-pep585-annotation (requires Python 3.9+ everywhere)
- "UP007", # non-pep604-annotation-union
- "UP028", # yield-in-for-loop
- "UP030", # format-literals
- "UP031", # printf-string-formatting
- "UP035", # deprecated-import (typing compat)
- "RUF002", # ambiguous-unicode-character-docstring
- "RUF003", # ambiguous-unicode-character-comment
- "RUF005", # collection-literal-concatenation
- "RUF012", # mutable-class-default
- "RUF013", # implicit-optional
- "RUF015", # unnecessary-iterable-allocation-for-first-element
- "RUF017", # quadratic-list-summation
- "RUF022", # unsorted-dunder-all
- "RUF028", # invalid-formatter-suppression-comment
+ # pyupgrade (needs `from __future__ import annotations`)
+ "UP006", # non-pep585-annotation
+ "UP007", # non-pep604-annotation-union
+ "UP035", # deprecated-import
+ "UP045", # non-pep604-annotation-optional
+ # ruff (preview rules, not yet stable)
"RUF043", # pytest-raises-ambiguous-pattern
- "RUF046", # unnecessary-cast-to-int
"RUF059", # unused-unpacked-variable
- "E722", # bare-except
- "UP022", # replace-stdout-stderr
]
fixable = ["ALL"]
unfixable = []
[tool.ruff.lint.per-file-ignores]
-"__init__.py" = ["F401"] # pyflakes: unused-import
+"__init__.py" = ["E402", "F401", "F403", "F405"]
[tool.ruff.lint.isort]
known-first-party = ["tvm"]
diff --git a/python/tvm/base.py b/python/tvm/base.py
index 63daa58528..2ac783b233 100644
--- a/python/tvm/base.py
+++ b/python/tvm/base.py
@@ -16,6 +16,7 @@
# under the License.
# coding: utf-8
# pylint: disable=invalid-name, import-outside-toplevel
+# ruff: noqa: F401
"""Base library for TVM."""
import ctypes
diff --git a/python/tvm/contrib/cudnn.py b/python/tvm/contrib/cudnn.py
index ced90f030b..d77b4afe0e 100644
--- a/python/tvm/contrib/cudnn.py
+++ b/python/tvm/contrib/cudnn.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""External function interface to CuDNN v7 library."""
# pylint: disable-msg=C0103
diff --git a/python/tvm/contrib/cutlass/attention_operation.py b/python/tvm/contrib/cutlass/attention_operation.py
index 38dff789b1..f4f059daf0 100644
--- a/python/tvm/contrib/cutlass/attention_operation.py
+++ b/python/tvm/contrib/cutlass/attention_operation.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E501
"""Generator for CUTLASS attention kernels."""
from .library import substitute_template
@@ -190,32 +191,32 @@ def instantiate_flash_attention_template(attrs):
flash_attn::flash_attention_forward(
static_cast<const cutlass::half_t*>(${query}->data),
- static_cast<const cutlass::half_t*>(${key}->data),
- static_cast<const cutlass::half_t*>(${value}->data),
- static_cast<cutlass::half_t*>(out0->data),
- ${num_batches},
- ${num_queries},
- ${num_keys},
- ${num_q_heads},
- ${num_kv_heads},
- ${head_dim},
- q_batch_stride,
- k_batch_stride,
- v_batch_stride,
- o_batch_stride,
- q_head_stride,
- k_head_stride,
- v_head_stride,
- o_head_stride,
- q_row_stride,
- k_row_stride,
- v_row_stride,
- o_row_stride,
- ${scale},
- ${is_causal},
+ static_cast<const cutlass::half_t*>(${key}->data),
+ static_cast<const cutlass::half_t*>(${value}->data),
+ static_cast<cutlass::half_t*>(out0->data),
+ ${num_batches},
+ ${num_queries},
+ ${num_keys},
+ ${num_q_heads},
+ ${num_kv_heads},
+ ${head_dim},
+ q_batch_stride,
+ k_batch_stride,
+ v_batch_stride,
+ o_batch_stride,
+ q_head_stride,
+ k_head_stride,
+ v_head_stride,
+ o_head_stride,
+ q_row_stride,
+ k_row_stride,
+ v_row_stride,
+ o_row_stride,
+ ${scale},
+ ${is_causal},
${window_size_left},
${window_size_right},
- stream);
+ stream);
"""
template_stacked = """
@@ -240,32 +241,32 @@ def instantiate_flash_attention_template(attrs):
flash_attn::flash_attention_forward(
static_cast<const cutlass::half_t*>(${qkv}->data),
- static_cast<const cutlass::half_t*>(${qkv}->data) + ${head_dim} * ${num_q_heads},
- static_cast<const cutlass::half_t*>(${qkv}->data) + ${head_dim} * (${num_q_heads} + ${num_kv_heads}),
- static_cast<cutlass::half_t*>(out0->data),
- ${num_batches},
- ${num_queries},
- ${num_keys},
- ${num_q_heads},
- ${num_kv_heads},
- ${head_dim},
- q_batch_stride,
- k_batch_stride,
- v_batch_stride,
- o_batch_stride,
- q_head_stride,
- k_head_stride,
- v_head_stride,
- o_head_stride,
- q_row_stride,
- k_row_stride,
- v_row_stride,
- o_row_stride,
- ${scale},
- ${is_causal},
+ static_cast<const cutlass::half_t*>(${qkv}->data) + ${head_dim} * ${num_q_heads},
+ static_cast<const cutlass::half_t*>(${qkv}->data) + ${head_dim} * (${num_q_heads} + ${num_kv_heads}),
+ static_cast<cutlass::half_t*>(out0->data),
+ ${num_batches},
+ ${num_queries},
+ ${num_keys},
+ ${num_q_heads},
+ ${num_kv_heads},
+ ${head_dim},
+ q_batch_stride,
+ k_batch_stride,
+ v_batch_stride,
+ o_batch_stride,
+ q_head_stride,
+ k_head_stride,
+ v_head_stride,
+ o_head_stride,
+ q_row_stride,
+ k_row_stride,
+ v_row_stride,
+ o_row_stride,
+ ${scale},
+ ${is_causal},
${window_size_left},
${window_size_right},
- stream);
+ stream);
"""
if "qkv" in attrs:
@@ -296,31 +297,31 @@ def instantiate_flash_attention_var_len_template(attrs):
flash_attn::flash_attention_var_len_forward(
static_cast<const cutlass::half_t*>(${query}->data),
- static_cast<const cutlass::half_t*>(${key}->data),
- static_cast<const cutlass::half_t*>(${value}->data),
+ static_cast<const cutlass::half_t*>(${key}->data),
+ static_cast<const cutlass::half_t*>(${value}->data),
static_cast<const int*>(${seqstart_q}->data),
static_cast<const int*>(${seqstart_k}->data),
- static_cast<cutlass::half_t*>(out0->data),
- batch_size,
- _max_seqlen_q,
- _max_seqlen_k,
- ${num_q_heads},
- ${num_kv_heads},
- ${head_dim},
- q_head_stride,
- k_head_stride,
- v_head_stride,
- o_head_stride,
- q_row_stride,
- k_row_stride,
- v_row_stride,
- o_row_stride,
- ${scale},
- ${is_causal},
+ static_cast<cutlass::half_t*>(out0->data),
+ batch_size,
+ _max_seqlen_q,
+ _max_seqlen_k,
+ ${num_q_heads},
+ ${num_kv_heads},
+ ${head_dim},
+ q_head_stride,
+ k_head_stride,
+ v_head_stride,
+ o_head_stride,
+ q_row_stride,
+ k_row_stride,
+ v_row_stride,
+ o_row_stride,
+ ${scale},
+ ${is_causal},
// For SWA, is_causal must be false.
${is_causal} ? _max_seqlen_k : ${window_size_left},
${window_size_right},
- stream);
+ stream);
"""
return substitute_template(template, attrs)
diff --git a/python/tvm/contrib/cutlass/build.py b/python/tvm/contrib/cutlass/build.py
index 6cb251c66f..c1ad062b90 100644
--- a/python/tvm/contrib/cutlass/build.py
+++ b/python/tvm/contrib/cutlass/build.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, dangerous-default-value, arguments-differ
+# ruff: noqa: F821
"""Driver for partitioning and building a Relax module for CUTLASS offload."""
import itertools
@@ -380,10 +381,10 @@ def _extract_relax_function_signature(f):
for i, arg in enumerate(f.params):
sinfo = arg.struct_info
if isinstance(sinfo, relax.TensorStructInfo):
- signature["arg%d_shape" % i] = get_const_tuple(sinfo.shape)
- signature["arg%d_dtype" % i] = sinfo.dtype
+ signature[f"arg{i}_shape"] = get_const_tuple(sinfo.shape)
+ signature[f"arg{i}_dtype"] = sinfo.dtype
elif isinstance(sinfo, relax.ShapeStructInfo):
- signature["arg%d_shape" % i] = get_const_tuple(sinfo.values)
+ signature[f"arg{i}_shape"] = get_const_tuple(sinfo.values)
else:
raise NotImplementedError()
diff --git a/python/tvm/contrib/cutlass/conv2d_operation.py b/python/tvm/contrib/cutlass/conv2d_operation.py
index f969ab2860..9a0df587a6 100644
--- a/python/tvm/contrib/cutlass/conv2d_operation.py
+++ b/python/tvm/contrib/cutlass/conv2d_operation.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-wildcard-import, wildcard-import
+# ruff: noqa: E501, F403, F405
"""Generator for CUTLASS Conv2D kernels."""
from .library import *
@@ -60,7 +61,7 @@ class Conv2dOperation:
intermediate_type = ""
if self.tile_description.math_instruction.opcode_class == OpcodeClass.TensorOp:
- inst_shape = "%d%d%d" % tuple(self.tile_description.math_instruction.instruction_shape)
+ inst_shape = "{}{}{}".format(*self.tile_description.math_instruction.instruction_shape)
if (
self.tile_description.math_instruction.element_a != self.A.element
and self.tile_description.math_instruction.element_a != self.accumulator_type()
@@ -69,13 +70,7 @@ class Conv2dOperation:
else:
inst_shape = ""
- return "%s%s%s%s_%s" % (
- ShortDataTypeNames[self.accumulator_type()],
- inst_shape,
- intermediate_type,
- ConvKindNames[self.conv_kind],
- IteratorAlgorithmNames[self.iterator_algorithm],
- )
+ return f"{ShortDataTypeNames[self.accumulator_type()]}{inst_shape}{intermediate_type}{ConvKindNames[self.conv_kind]}_{IteratorAlgorithmNames[self.iterator_algorithm]}"
def extended_name(self):
"""Append data types if they differ from compute type."""
@@ -112,12 +107,7 @@ class Conv2dOperation:
"""
opcode_class_name = OpcodeClassNames[self.tile_description.math_instruction.opcode_class]
- threadblock = "%dx%d_%dx%d" % (
- self.tile_description.threadblock_shape[0],
- self.tile_description.threadblock_shape[1],
- self.tile_description.threadblock_shape[2],
- self.tile_description.stages,
- )
+ threadblock = f"{self.tile_description.threadblock_shape[0]}x{self.tile_description.threadblock_shape[1]}_{self.tile_description.threadblock_shape[2]}x{self.tile_description.stages}"
if self.stride_support == StrideSupport.Unity:
configuration_name = (
diff --git a/python/tvm/contrib/cutlass/conv2d_profiler.py b/python/tvm/contrib/cutlass/conv2d_profiler.py
index e6e4e2727d..4395c225a4 100644
--- a/python/tvm/contrib/cutlass/conv2d_profiler.py
+++ b/python/tvm/contrib/cutlass/conv2d_profiler.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=import-outside-toplevel, invalid-name
+# ruff: noqa: E501
"""Instantiate a C++ source for profiling CUTLASS kernels."""
from .library import DataTypeTag
@@ -34,17 +35,17 @@ class Conv2dProfilerEmitter:
problem_size.split_k_slices,
cutlass::conv::implicit_gemm_tensor_c_size(kConvolutionalOperator, problem_size),
{
- reinterpret_cast<ImplicitGemm::ElementC*> (workspace.get()),
- ReductionStrideIndex(tensor_c.stride()[ImplicitGemm::UnderlyingKernel::kTensorCStrideIdx])
- },
+ reinterpret_cast<ImplicitGemm::ElementC*> (workspace.get()),
+ ReductionStrideIndex(tensor_c.stride()[ImplicitGemm::UnderlyingKernel::kTensorCStrideIdx])
+ },
{
- tensor_d.device_data(),
- ReductionStrideIndex(tensor_d.stride()[ImplicitGemm::UnderlyingKernel::kTensorCStrideIdx])
- },
+ tensor_d.device_data(),
+ ReductionStrideIndex(tensor_d.stride()[ImplicitGemm::UnderlyingKernel::kTensorCStrideIdx])
+ },
{
- tensor_c.device_data(),
- ReductionStrideIndex(tensor_c.stride()[ImplicitGemm::UnderlyingKernel::kTensorCStrideIdx])
- },
+ tensor_c.device_data(),
+ ReductionStrideIndex(tensor_c.stride()[ImplicitGemm::UnderlyingKernel::kTensorCStrideIdx])
+ },
{ElementComputeEpilogue(1), ElementComputeEpilogue(0)}
);
@@ -124,15 +125,15 @@ double profile_convolution(Options const &options) {
int split_k_slices = {{SplitK}};
cutlass::conv::Conv2dProblemSize problem_size(
- options.input_size,
- options.filter_size,
- options.padding,
- options.conv_stride,
- options.dilation,
- options.output_size(),
- cutlass::conv::Mode::kCrossCorrelation,
- split_k_slices
- );
+ options.input_size,
+ options.filter_size,
+ options.padding,
+ options.conv_stride,
+ options.dilation,
+ options.output_size(),
+ cutlass::conv::Mode::kCrossCorrelation,
+ split_k_slices
+ );
auto conv_kind = ImplicitGemm::kConvolutionalOperator;
auto a_extent = implicit_gemm_tensor_a_extent(conv_kind, problem_size);
diff --git a/python/tvm/contrib/cutlass/gemm_operation.py b/python/tvm/contrib/cutlass/gemm_operation.py
index 3007e42602..372f269436 100644
--- a/python/tvm/contrib/cutlass/gemm_operation.py
+++ b/python/tvm/contrib/cutlass/gemm_operation.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-wildcard-import, wildcard-import, pointless-exception-statement
+# ruff: noqa: E501, F403, F405
"""Generator for CUTLASS GEMM kernels."""
from .library import *
@@ -59,7 +60,7 @@ class GemmOperation:
self.tile_description.math_instruction.opcode_class == OpcodeClass.TensorOp
or self.tile_description.math_instruction.opcode_class == OpcodeClass.WmmaTensorOp
):
- inst_shape = "%d%d%d" % tuple(self.tile_description.math_instruction.instruction_shape)
+ inst_shape = "{}{}{}".format(*self.tile_description.math_instruction.instruction_shape)
if (
self.tile_description.math_instruction.element_a != self.A.element
and self.tile_description.math_instruction.element_a
diff --git a/python/tvm/contrib/cutlass/gen_conv2d.py b/python/tvm/contrib/cutlass/gen_conv2d.py
index 7355fe76b5..cbee959b0c 100644
--- a/python/tvm/contrib/cutlass/gen_conv2d.py
+++ b/python/tvm/contrib/cutlass/gen_conv2d.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, dangerous-default-value
+# ruff: noqa: E501
"""Conv2d kernel generator and profiler for CUTLASS."""
import os
@@ -283,7 +284,7 @@ class CutlassConv2DProfiler:
elif dtype in ["float", "float32"]:
alignments = [4, 2, 1]
else:
- raise ValueError("Unsupported data type: %s" % dtype)
+ raise ValueError(f"Unsupported data type: {dtype}")
return alignments
alignments_c = [align for align in alignments(out_dtype) if OC % align == 0]
@@ -312,10 +313,9 @@ class CutlassConv2DProfiler:
if not find_first_valid:
self.engine.compile_all(ops, use_multiprocessing)
- args = (
- "--n=%d --h=%d --w=%d --c=%d --k=%d --r=%d --s=%d --pad_h=%d --pad_w=%d "
- "--stride_h=%d --stride_w=%d --dilation_h=%d --dilation_w=%d"
- ) % workload
+ args = "--n={} --h={} --w={} --c={} --k={} --r={} --s={} --pad_h={} --pad_w={} --stride_h={} --stride_w={} --dilation_h={} --dilation_w={}".format(
+ *workload
+ )
for op in ops:
out = self.engine.evaluate(op, args.split(" "))
diff --git a/python/tvm/contrib/cutlass/gen_tensor_op.py b/python/tvm/contrib/cutlass/gen_tensor_op.py
index 5273e105d7..bcddffa5b8 100644
--- a/python/tvm/contrib/cutlass/gen_tensor_op.py
+++ b/python/tvm/contrib/cutlass/gen_tensor_op.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: F821
"""Common functions and classes for CUTLASS GEMM and Conv2d geneator."""
import logging
diff --git a/python/tvm/contrib/cutlass/layer_norm_operation.py b/python/tvm/contrib/cutlass/layer_norm_operation.py
index 6163d02f28..e854bbfa35 100644
--- a/python/tvm/contrib/cutlass/layer_norm_operation.py
+++ b/python/tvm/contrib/cutlass/layer_norm_operation.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E501
"""Generator for CUTLASS layer norm kernels."""
from .library import substitute_template
diff --git a/python/tvm/contrib/cutlass/library.py b/python/tvm/contrib/cutlass/library.py
index 568f112d82..cacff3232f 100644
--- a/python/tvm/contrib/cutlass/library.py
+++ b/python/tvm/contrib/cutlass/library.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name,line-too-long
+# ruff: noqa: E501
"""Various type definitions to help instantiate CUTLASS kernels."""
import enum
@@ -290,12 +291,7 @@ class TileDescription:
self.maximum_compute_capability = max_compute
def procedural_name(self):
- return "%dx%d_%dx%d" % (
- self.threadblock_shape[0],
- self.threadblock_shape[1],
- self.threadblock_shape[2],
- self.stages,
- )
+ return f"{self.threadblock_shape[0]}x{self.threadblock_shape[1]}_{self.threadblock_shape[2]}x{self.stages}"
class TensorDescription:
diff --git a/python/tvm/contrib/cutlass/rms_norm_operation.py b/python/tvm/contrib/cutlass/rms_norm_operation.py
index d076cfa173..c67843db63 100644
--- a/python/tvm/contrib/cutlass/rms_norm_operation.py
+++ b/python/tvm/contrib/cutlass/rms_norm_operation.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E501
"""Generator for CUTLASS rms norm kernels."""
from .library import substitute_template
diff --git a/python/tvm/contrib/hexagon/build.py b/python/tvm/contrib/hexagon/build.py
index 74c3bf9275..27d0183f36 100644
--- a/python/tvm/contrib/hexagon/build.py
+++ b/python/tvm/contrib/hexagon/build.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=consider-using-with, unnecessary-ellipsis
+# ruff: noqa: RUF005, RUF012
"""Defines top-level glue functions for building Hexagon."""
@@ -32,7 +33,7 @@ import string
import subprocess
import sys
import tempfile
-from typing import Union
+from typing import Optional, Union
from tvm_ffi import libinfo
@@ -57,8 +58,7 @@ def _check_call_verbose(cmd, **kwargs) -> None:
cmd,
check=True,
encoding="UTF-8",
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
+ capture_output=True,
**kwargs,
)
except subprocess.CalledProcessError as err:
@@ -191,7 +191,10 @@ class HexagonLauncherRPC(metaclass=abc.ABCMeta):
"""
def __init__(
- self, rpc_info: dict, workspace: Union[str, pathlib.Path] = None, serial_number: str = None
+ self,
+ rpc_info: dict,
+ workspace: Optional[Union[str, pathlib.Path]] = None,
+ serial_number: Optional[str] = None,
):
self._rpc_info = {
"rpc_tracker_host": "0.0.0.0",
@@ -331,7 +334,7 @@ class HexagonLauncherAndroid(HexagonLauncherRPC):
self,
serial_number: str,
rpc_info: dict,
- workspace: Union[str, pathlib.Path] = None,
+ workspace: Optional[Union[str, pathlib.Path]] = None,
hexagon_debug: bool = False,
clear_logcat: bool = False,
sysmon_profile: bool = False,
@@ -656,7 +659,7 @@ class HexagonLauncherSimulator(HexagonLauncherRPC):
SIMULATOR_HEXAGON_RPC_FILES = ["tvm_rpc_x86", "libhexagon_rpc_sim.so"]
- def __init__(self, rpc_info: dict, workspace: Union[str, pathlib.Path] = None):
+ def __init__(self, rpc_info: dict, workspace: Optional[Union[str, pathlib.Path]] = None):
"""Configure a new HexagonLauncherSimulator
Parameters are same as for HexagonLauncherRPC.
@@ -827,7 +830,7 @@ def farf_config_from_python_log_level(level) -> str:
def HexagonLauncher(
serial_number: str,
rpc_info: dict,
- workspace: Union[str, pathlib.Path] = None,
+ workspace: Optional[Union[str, pathlib.Path]] = None,
hexagon_debug: bool = False,
clear_logcat: bool = False,
sysmon_profile: bool = False,
diff --git a/python/tvm/contrib/hexagon/hexagon_profiler.py b/python/tvm/contrib/hexagon/hexagon_profiler.py
index 1b11df4c34..bbf360bc0a 100644
--- a/python/tvm/contrib/hexagon/hexagon_profiler.py
+++ b/python/tvm/contrib/hexagon/hexagon_profiler.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=consider-using-with
+# ruff: noqa: RUF005
"""Define HexagonProfiler class to enable profiling for Hexagon"""
diff --git a/python/tvm/contrib/hexagon/profiling/process_lwp_data.py b/python/tvm/contrib/hexagon/profiling/process_lwp_data.py
index c17491d658..b82fbd4f88 100644
--- a/python/tvm/contrib/hexagon/profiling/process_lwp_data.py
+++ b/python/tvm/contrib/hexagon/profiling/process_lwp_data.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E741
import argparse
import csv
diff --git a/python/tvm/contrib/hexagon/tools.py b/python/tvm/contrib/hexagon/tools.py
index 053c2e1e3e..f9d8b8d1ec 100644
--- a/python/tvm/contrib/hexagon/tools.py
+++ b/python/tvm/contrib/hexagon/tools.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, f-string-without-interpolation, consider-using-from-import
+# ruff: noqa: E501
"""Tools/compilers/linkers for Hexagon"""
import io
@@ -477,8 +478,7 @@ class ContainerSession:
@staticmethod
def _get_docker_client():
try:
- # pylint: disable=import-outside-toplevel
- from docker import from_env
+ from docker import from_env # pylint: disable=import-outside-toplevel
from docker.errors import DockerException
except (ModuleNotFoundError, ImportError):
raise Exception("Docker SDK module is not installed. Please install it.")
diff --git a/python/tvm/contrib/mps.py b/python/tvm/contrib/mps.py
index f0c4478add..477932527a 100644
--- a/python/tvm/contrib/mps.py
+++ b/python/tvm/contrib/mps.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""External function interface to MPS libraries."""
import tvm
diff --git a/python/tvm/contrib/msc/core/codegen/codegen.py b/python/tvm/contrib/msc/core/codegen/codegen.py
index 9f61f06804..fec642dad2 100644
--- a/python/tvm/contrib/msc/core/codegen/codegen.py
+++ b/python/tvm/contrib/msc/core/codegen/codegen.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, RUF005
"""tvm.contrib.msc.core.codegen.codegen"""
import os
diff --git a/python/tvm/contrib/msc/core/frontend/translate.py b/python/tvm/contrib/msc/core/frontend/translate.py
index 3bf101597e..1bceff8818 100644
--- a/python/tvm/contrib/msc/core/frontend/translate.py
+++ b/python/tvm/contrib/msc/core/frontend/translate.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""tvm.contrib.msc.core.frontend.translate"""
from typing import Dict, List, Optional, Tuple
diff --git a/python/tvm/contrib/msc/core/gym/agent/base_agent.py b/python/tvm/contrib/msc/core/gym/agent/base_agent.py
index 0257cbe891..ae49dd9143 100644
--- a/python/tvm/contrib/msc/core/gym/agent/base_agent.py
+++ b/python/tvm/contrib/msc/core/gym/agent/base_agent.py
@@ -18,7 +18,7 @@
import copy
import logging
-from typing import Any, Dict, List, Tuple
+from typing import Any, Dict, List, Optional, Tuple
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.gym.namespace import GYMObject
@@ -48,9 +48,9 @@ class BaseAgent:
name: str,
workspace: msc_utils.MSCDirectory,
executors: dict,
- options: dict = None,
+ options: Optional[dict] = None,
debug_level: int = 0,
- logger: logging.Logger = None,
+ logger: Optional[logging.Logger] = None,
):
self._name = name
self._workspace = workspace
diff --git a/python/tvm/contrib/msc/core/gym/control/controller.py b/python/tvm/contrib/msc/core/gym/control/controller.py
index 7e03c3b50b..d1b1f725fb 100644
--- a/python/tvm/contrib/msc/core/gym/control/controller.py
+++ b/python/tvm/contrib/msc/core/gym/control/controller.py
@@ -16,7 +16,7 @@
# under the License.
"""tvm.contrib.msc.core.gym.control.controller"""
-from typing import Any, Dict
+from typing import Any, Dict, Optional
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.gym.namespace import GYMAction, GYMObject
@@ -68,7 +68,7 @@ class BaseController:
return self._service.summary()
-def create_controller(stage: str, config: dict, extra_config: dict = None):
+def create_controller(stage: str, config: dict, extra_config: Optional[dict] = None):
"""Update the gym config
Parameters
diff --git a/python/tvm/contrib/msc/core/gym/control/service.py b/python/tvm/contrib/msc/core/gym/control/service.py
index 8a8aa7d692..6deed1ab18 100644
--- a/python/tvm/contrib/msc/core/gym/control/service.py
+++ b/python/tvm/contrib/msc/core/gym/control/service.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""tvm.contrib.msc.core.gym.control.service"""
import copy
@@ -22,7 +23,7 @@ import queue
import time
from functools import partial, reduce
from multiprocessing import Manager
-from typing import Any, Dict, List, Tuple
+from typing import Any, Dict, List, Optional, Tuple
import numpy as np
@@ -53,7 +54,7 @@ def _send_message(msg_queue: queue.Queue, header: str, body: dict, header_type:
def _wait_message(
msg_queue: queue.Queue,
header: str,
- checker: callable = None,
+ checker: Optional[callable] = None,
wait_time: int = 2,
max_retry: int = -1,
header_type: str = "message",
@@ -81,7 +82,7 @@ def _wait_message(
The message body
"""
- def _check_message(message: dict, checker: callable = None) -> bool:
+ def _check_message(message: dict, checker: Optional[callable] = None) -> bool:
"""Check the message
Parameters
@@ -160,13 +161,13 @@ class BaseService:
workspace: msc_utils.MSCDirectory,
env: Dict[str, Any],
agent: Dict[str, Any],
- tasks: List[str] = None,
- dist_manager: Manager = None,
+ tasks: Optional[List[str]] = None,
+ dist_manager: Optional[Manager] = None,
world_size: int = 1,
max_iter: int = 1,
record_step: int = 5,
debug_level: int = 0,
- verbose: str = None,
+ verbose: Optional[str] = None,
):
self._workspace = workspace
tasks = tasks or [GYMObject.ENV + ":0", GYMObject.AGENT + ":0"]
@@ -322,7 +323,7 @@ class BaseService:
def _wait_request(
self,
msg_key: str,
- checker: callable = None,
+ checker: Optional[callable] = None,
wait_time: int = 2,
max_retry: int = -1,
) -> dict:
@@ -345,7 +346,7 @@ class BaseService:
def _wait_response(
self,
msg_key: str,
- checker: callable = None,
+ checker: Optional[callable] = None,
wait_time: int = 2,
max_retry: int = -1,
) -> dict:
@@ -597,7 +598,7 @@ class MainService(BaseService):
self,
msg_key: str,
requests: List[dict],
- checker: callable = None,
+ checker: Optional[callable] = None,
wait_time: int = 2,
max_retry: int = -1,
) -> dict:
diff --git a/python/tvm/contrib/msc/core/gym/environment/base_env.py b/python/tvm/contrib/msc/core/gym/environment/base_env.py
index d60482af8d..24a986bfab 100644
--- a/python/tvm/contrib/msc/core/gym/environment/base_env.py
+++ b/python/tvm/contrib/msc/core/gym/environment/base_env.py
@@ -18,7 +18,7 @@
import copy
import logging
-from typing import Any, Dict, List, Tuple, Union
+from typing import Any, Dict, List, Optional, Tuple, Union
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.gym.namespace import GYMObject
@@ -56,11 +56,11 @@ class BaseEnv:
data_loader: Any,
workspace: msc_utils.MSCDirectory,
executors: dict,
- knowledge: dict = None,
- options: dict = None,
+ knowledge: Optional[dict] = None,
+ options: Optional[dict] = None,
max_tasks: int = -1,
debug_level: int = 0,
- logger: logging.Logger = None,
+ logger: Optional[logging.Logger] = None,
):
self._name = name
self._runner = runner
diff --git a/python/tvm/contrib/msc/core/gym/environment/method.py b/python/tvm/contrib/msc/core/gym/environment/method.py
index aa81d7ae57..92768ca9ac 100644
--- a/python/tvm/contrib/msc/core/gym/environment/method.py
+++ b/python/tvm/contrib/msc/core/gym/environment/method.py
@@ -17,7 +17,7 @@
# pylint: disable=unused-argument
"""tvm.contrib.msc.core.gym.agent.method"""
-from typing import Any, List
+from typing import Any, List, Optional
import numpy as np
@@ -60,7 +60,7 @@ class EnvMethod:
data_loader: callable,
task_id: int,
loss_type: str = "lp_norm",
- loss_config: dict = None,
+ loss_config: Optional[dict] = None,
) -> dict:
"""Reward runner with baseline
diff --git a/python/tvm/contrib/msc/core/gym/environment/prune_env.py b/python/tvm/contrib/msc/core/gym/environment/prune_env.py
index fae0205b55..87b777809a 100644
--- a/python/tvm/contrib/msc/core/gym/environment/prune_env.py
+++ b/python/tvm/contrib/msc/core/gym/environment/prune_env.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""tvm.contrib.msc.core.gym.prune_env"""
from typing import List, Union
diff --git a/python/tvm/contrib/msc/core/ir/graph.py b/python/tvm/contrib/msc/core/ir/graph.py
index 0a30f45293..7c930fca24 100644
--- a/python/tvm/contrib/msc/core/ir/graph.py
+++ b/python/tvm/contrib/msc/core/ir/graph.py
@@ -54,7 +54,7 @@ class MSCTensor(Object):
layout: str,
shape: List[int],
alias: Optional[str] = None,
- prims: List[str] = None,
+ prims: Optional[List[str]] = None,
):
if not isinstance(dtype, tvm.DataType):
dtype = tvm.DataType(dtype)
@@ -763,8 +763,7 @@ class MSCGraph(BaseGraph):
"""
for node in self.get_nodes():
- for weight in node.get_weights().values():
- yield weight
+ yield from node.get_weights().values()
def input_at(self, idx: int) -> MSCTensor:
"""Get input at idx.
@@ -830,12 +829,9 @@ class MSCGraph(BaseGraph):
"""
for node in self.get_nodes():
- for t_input in node.get_inputs():
- yield t_input
- for weight in node.get_weights().values():
- yield weight
- for t_output in self.get_outputs():
- yield t_output
+ yield from node.get_inputs()
+ yield from node.get_weights().values()
+ yield from self.get_outputs()
def to_json(self) -> str:
"""Dump the graph to json.
diff --git a/python/tvm/contrib/msc/core/runtime/jit.py b/python/tvm/contrib/msc/core/runtime/jit.py
index db766cee62..968c37c55a 100644
--- a/python/tvm/contrib/msc/core/runtime/jit.py
+++ b/python/tvm/contrib/msc/core/runtime/jit.py
@@ -18,7 +18,7 @@
"""tvm.contrib.msc.core.runtime.jit_model"""
import logging
-from typing import Any, Dict, List, Tuple, Union
+from typing import Any, Dict, List, Optional, Tuple, Union
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.tools import ToolType
@@ -55,8 +55,8 @@ class BaseJIT:
outputs: List[str],
device: str = "cpu",
training: bool = False,
- hooks: dict = None,
- logger: logging.Logger = None,
+ hooks: Optional[dict] = None,
+ logger: Optional[logging.Logger] = None,
):
self._model = model
self._jit_model = model
@@ -174,7 +174,9 @@ class BaseJIT:
tools = {n: r["runner"].get_tool(tool_type) for n, r in self._runner_ctxs.items()}
def _finalize_tool(
- checker: callable, post_batch: callable = None, post_iter: callable = None
+ checker: callable,
+ post_batch: Optional[callable] = None,
+ post_iter: Optional[callable] = None,
):
while any(not checker(t) for t in tools.values()):
assert data_loader, "data_loader should be given to make plan for " + tool_type
diff --git a/python/tvm/contrib/msc/core/runtime/runner.py b/python/tvm/contrib/msc/core/runtime/runner.py
index 56a4f1c456..a7b4ae29ed 100644
--- a/python/tvm/contrib/msc/core/runtime/runner.py
+++ b/python/tvm/contrib/msc/core/runtime/runner.py
@@ -83,7 +83,7 @@ class BaseRunner:
plugin: Any = None,
name: str = "main",
debug_level: int = 0,
- logger: logging.Logger = None,
+ logger: Optional[logging.Logger] = None,
):
self._mod = mod
if tools_config:
@@ -174,7 +174,7 @@ class BaseRunner:
self,
cache_dir: msc_utils.MSCDirectory = None,
force_build: bool = False,
- disable_tools: List[str] = None,
+ disable_tools: Optional[List[str]] = None,
) -> Any:
"""Build the runnable object
@@ -390,9 +390,9 @@ class BaseRunner:
def reset_tools(
self,
- graphs: List[MSCGraph] = None,
- weights: List[Dict[str, tvm.runtime.Tensor]] = None,
- tools: List[BaseTool] = None,
+ graphs: Optional[List[MSCGraph]] = None,
+ weights: Optional[List[Dict[str, tvm.runtime.Tensor]]] = None,
+ tools: Optional[List[BaseTool]] = None,
cache_dir: msc_utils.MSCDirectory = None,
):
"""Reset the tools
@@ -647,7 +647,9 @@ class BaseRunner:
"""
def _finalize_tool(
- checker: callable, post_batch: callable = None, post_iter: callable = None
+ checker: callable,
+ post_batch: Optional[callable] = None,
+ post_iter: Optional[callable] = None,
):
tool = self.get_tool(tool_type)
while not checker(tool):
@@ -770,7 +772,7 @@ class BaseRunner:
return self._model_info["outputs"]
def get_weights(
- self, framework: str = None, device: str = None
+ self, framework: Optional[str] = None, device: Optional[str] = None
) -> Iterable[tvm.runtime.Tensor]:
"""Get the weights from graphs
@@ -1081,7 +1083,7 @@ class BaseRunner:
@classmethod
def dump_nativate(
- cls, model: Any, folder: msc_utils.MSCDirectory, dump_config: dict = None
+ cls, model: Any, folder: msc_utils.MSCDirectory, dump_config: Optional[dict] = None
) -> str:
"""Dump the nativate model
diff --git a/python/tvm/contrib/msc/core/tools/configer.py b/python/tvm/contrib/msc/core/tools/configer.py
index ac192398c2..a1d45b3145 100644
--- a/python/tvm/contrib/msc/core/tools/configer.py
+++ b/python/tvm/contrib/msc/core/tools/configer.py
@@ -16,7 +16,7 @@
# under the License.
"""tvm.contrib.msc.core.tools.configer"""
-from typing import Union
+from typing import Optional, Union
from tvm.contrib.msc.core import utils as msc_utils
@@ -26,7 +26,7 @@ from .tool import ToolType
class ToolConfiger:
"""Base configer for tool"""
- def config(self, raw_config: dict = None) -> dict:
+ def config(self, raw_config: Optional[dict] = None) -> dict:
"""Get the config
Parameters
diff --git a/python/tvm/contrib/msc/core/tools/prune/pruner.py b/python/tvm/contrib/msc/core/tools/prune/pruner.py
index d0e38a6350..63c3db381d 100644
--- a/python/tvm/contrib/msc/core/tools/prune/pruner.py
+++ b/python/tvm/contrib/msc/core/tools/prune/pruner.py
@@ -14,9 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""tvm.contrib.msc.core.tools.prune.pruner"""
-from typing import Any, Dict, List, Tuple
+from typing import Any, Dict, List, Optional, Tuple
import numpy as np
@@ -339,7 +340,7 @@ class BasePruner(WeightTool):
def _prune_by_shape(tensor: MSCTensor, shape: List[int]):
return MSCTensor(tensor.name, tensor.dtype, tensor.layout.name, shape, tensor.alias)
- def _prune_by_channel(tensor: MSCTensor, dim, channel_axis: int = None):
+ def _prune_by_channel(tensor: MSCTensor, dim, channel_axis: Optional[int] = None):
shape = tensor.get_shape()
if channel_axis is None:
if self.has_w_node(tensor.name):
diff --git a/python/tvm/contrib/msc/core/tools/quantize/method.py b/python/tvm/contrib/msc/core/tools/quantize/method.py
index 3710a3e5c8..5cca88b824 100644
--- a/python/tvm/contrib/msc/core/tools/quantize/method.py
+++ b/python/tvm/contrib/msc/core/tools/quantize/method.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-argument
+# ruff: noqa: RUF005
"""tvm.contrib.msc.core.tools.quantize.method"""
from typing import Any, Union
diff --git a/python/tvm/contrib/msc/core/tools/tool.py b/python/tvm/contrib/msc/core/tools/tool.py
index ab3630a8d5..0901a1a0dc 100644
--- a/python/tvm/contrib/msc/core/tools/tool.py
+++ b/python/tvm/contrib/msc/core/tools/tool.py
@@ -15,13 +15,14 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-argument
+# ruff: noqa: RUF012
"""tvm.contrib.msc.core.tools.base_tool"""
import copy
import logging
import os
from itertools import product
-from typing import Any, Dict, Iterable, List, Tuple, Union
+from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
import numpy as np
@@ -68,7 +69,7 @@ class ToolExecutor:
The config for execute
"""
- def __init__(self, name: str, method: callable, config: dict = None):
+ def __init__(self, name: str, method: callable, config: Optional[dict] = None):
self._name = name
self._method = method
self._config = config or {}
@@ -95,7 +96,12 @@ class ToolExecutor:
kwargs.update(self._config)
return self._method(*args, **kwargs)
- def copy(self, name: str = None, method: callable = None, config: dict = None):
+ def copy(
+ self,
+ name: Optional[str] = None,
+ method: Optional[callable] = None,
+ config: Optional[dict] = None,
+ ):
"""Copy a executor
Parameters
@@ -208,7 +214,7 @@ class ToolStrategy:
if not self._stage:
self._stage = stage
- def get_executor(self, stage: str = None) -> Tuple[callable, dict]:
+ def get_executor(self, stage: Optional[str] = None) -> Tuple[callable, dict]:
"""Get executor of current stage
Parameters
@@ -250,10 +256,10 @@ class ToolStrategy:
def copy(
self,
- name: str = None,
- tensor_type: str = None,
- stage: str = None,
- configs: Dict[str, dict] = None,
+ name: Optional[str] = None,
+ tensor_type: Optional[str] = None,
+ stage: Optional[str] = None,
+ configs: Optional[Dict[str, dict]] = None,
):
"""Copy a strategy
@@ -319,10 +325,10 @@ class BaseTool:
strategys: List[dict],
training: bool = False,
cache_processed: bool = True,
- options: dict = None,
+ options: Optional[dict] = None,
debug_level: int = 0,
verbose_step: int = 50,
- logger: logging.Logger = None,
+ logger: Optional[logging.Logger] = None,
):
self._tag = tag
self._stage = stage
@@ -1134,8 +1140,7 @@ class BaseTool:
"""
for g in self._graphs:
- for n in g.get_nodes():
- yield n
+ yield from g.get_nodes()
def find_node(self, name: str) -> MSCJoint:
"""Find node by name.
@@ -1166,8 +1171,7 @@ class BaseTool:
"""
for graph in self._graphs:
- for tensor in graph.get_tensors():
- yield tensor
+ yield from graph.get_tensors()
def get_tensor_ids(self) -> Iterable[MSCTensor]:
"""Get all the tensor ids in the graphs.
@@ -1547,8 +1551,7 @@ class WeightTool(BaseTool):
"""
for g in self._weight_graphs:
- for n in g.get_nodes():
- yield n
+ yield from g.get_nodes()
def has_w_node(self, name: str) -> bool:
"""Check if name in weight_graphs.
diff --git a/python/tvm/contrib/msc/core/transform/pattern.py b/python/tvm/contrib/msc/core/transform/pattern.py
index 0771f60c5a..07b5cfd88f 100644
--- a/python/tvm/contrib/msc/core/transform/pattern.py
+++ b/python/tvm/contrib/msc/core/transform/pattern.py
@@ -18,7 +18,7 @@
"""tvm.contrib.msc.core.transform.pattern"""
from functools import partial
-from typing import Dict, List, Mapping, Tuple
+from typing import Dict, List, Mapping, Optional, Tuple
import tvm
from tvm.contrib.msc.core import _ffi_api
@@ -32,8 +32,8 @@ from tvm.relax.transform import PatternCheckContext
def msc_attrs_getter(
annotated_expr: Dict[str, tvm.relax.Expr],
anchor: str = "out",
- output: str = None,
- inputs: List[str] = None,
+ output: Optional[str] = None,
+ inputs: Optional[List[str]] = None,
) -> Dict[str, str]:
"""Get attributes for fused pattern
diff --git a/python/tvm/contrib/msc/core/transform/transform.py b/python/tvm/contrib/msc/core/transform/transform.py
index 3a0e0d2b6a..2b8fb7fc57 100644
--- a/python/tvm/contrib/msc/core/transform/transform.py
+++ b/python/tvm/contrib/msc/core/transform/transform.py
@@ -17,7 +17,7 @@
# pylint: disable=invalid-name
"""tvm.contrib.msc.core.transform.transform"""
-from typing import Dict
+from typing import Dict, Optional
import tvm
from tvm.contrib.msc.core import utils as msc_utils
@@ -27,7 +27,7 @@ from tvm.relax.transform import _ffi_api
def SetExprName(
entry_name: str = "main",
target: str = "",
- var_names: Dict[str, str] = None,
+ var_names: Optional[Dict[str, str]] = None,
) -> tvm.ir.transform.Pass:
"""Set name for the call and constant in IRModule.
diff --git a/python/tvm/contrib/msc/core/utils/arguments.py b/python/tvm/contrib/msc/core/utils/arguments.py
index 97ccdf19d2..7fae33191a 100644
--- a/python/tvm/contrib/msc/core/utils/arguments.py
+++ b/python/tvm/contrib/msc/core/utils/arguments.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""tvm.contrib.msc.core.utils.arguments"""
import copy
diff --git a/python/tvm/contrib/msc/core/utils/dataset.py b/python/tvm/contrib/msc/core/utils/dataset.py
index 5d26f01fe0..8bf5c856a2 100644
--- a/python/tvm/contrib/msc/core/utils/dataset.py
+++ b/python/tvm/contrib/msc/core/utils/dataset.py
@@ -20,7 +20,7 @@
import json
import os
import shutil
-from typing import Any, Dict, List, Tuple, Union
+from typing import Any, Dict, List, Optional, Tuple, Union
import numpy as np
@@ -69,7 +69,7 @@ def random_data(
info: Union[List, Tuple, dict],
framework: str = MSCFramework.MSC,
device: str = "cpu",
- max_val: int = None,
+ max_val: Optional[int] = None,
) -> Any:
"""Create random data from info
@@ -365,7 +365,7 @@ class BaseDataSaver:
def __init__(
self,
folder: str,
- options: dict = None,
+ options: Optional[dict] = None,
start: int = 0,
max_size: int = -1,
):
@@ -557,7 +557,7 @@ class IODataSaver(BaseDataSaver):
def save_batch(
self,
inputs: Union[Dict[str, np.ndarray], List[np.ndarray]],
- outputs: Union[Dict[str, np.ndarray], List[np.ndarray]] = None,
+ outputs: Optional[Union[Dict[str, np.ndarray], List[np.ndarray]]] = None,
) -> int:
"""Save 1 batch inputs and outputs.
diff --git a/python/tvm/contrib/msc/core/utils/expr.py b/python/tvm/contrib/msc/core/utils/expr.py
index 6984bd3bcf..e5aed4782e 100644
--- a/python/tvm/contrib/msc/core/utils/expr.py
+++ b/python/tvm/contrib/msc/core/utils/expr.py
@@ -17,7 +17,7 @@
"""tvm.contrib.msc.core.utils.expr"""
import copy
-from typing import Dict, List
+from typing import Dict, List, Optional
import tvm
from tvm import relax
@@ -25,7 +25,7 @@ from tvm.contrib.msc.core import _ffi_api
from tvm.relax import PyExprVisitor
-def legalize_expr_name(name: str, symbols: List[str] = None, dst: str = "_") -> str:
+def legalize_expr_name(name: str, symbols: Optional[List[str]] = None, dst: str = "_") -> str:
"""Legalize expr name
Parameters
diff --git a/python/tvm/contrib/msc/core/utils/file.py b/python/tvm/contrib/msc/core/utils/file.py
index 6ef9790c77..7323f076d3 100644
--- a/python/tvm/contrib/msc/core/utils/file.py
+++ b/python/tvm/contrib/msc/core/utils/file.py
@@ -23,7 +23,7 @@ import tempfile
import types
from functools import partial
from importlib.machinery import SourceFileLoader
-from typing import Any, List, Union
+from typing import Any, List, Optional, Union
from .namespace import MSCFramework, MSCKey, MSCMap
from .register import get_registered_func
@@ -85,7 +85,9 @@ def load_callable(name: str, framework: str = MSCFramework.MSC) -> callable:
class MSCDirectory:
"""Create a directory manager for MSC"""
- def __init__(self, path: str = None, keep_history: bool = True, cleanup: bool = False):
+ def __init__(
+ self, path: Optional[str] = None, keep_history: bool = True, cleanup: bool = False
+ ):
self._path = os.path.abspath(path or tempfile.mkdtemp())
self._cleanup = cleanup
self._cwd = os.getcwd()
@@ -140,7 +142,7 @@ class MSCDirectory:
f.write(contains)
return file_path
- def move(self, src_path: str, dst_path: str = None):
+ def move(self, src_path: str, dst_path: Optional[str] = None):
"""Move a file or folder to another folder
Parameters
@@ -166,7 +168,7 @@ class MSCDirectory:
os.rename(src_path, dst_path)
return dst_path
- def copy(self, src_path: str, dst_path: str = None) -> str:
+ def copy(self, src_path: str, dst_path: Optional[str] = None) -> str:
"""Copy a file to another folder
Parameters
@@ -312,7 +314,9 @@ class MSCDirectory:
return self._path
-def msc_dir(path: str = None, keep_history: bool = True, cleanup: bool = False) -> MSCDirectory:
+def msc_dir(
+ path: Optional[str] = None, keep_history: bool = True, cleanup: bool = False
+) -> MSCDirectory:
"""Create MSCDirectory
Parameters
@@ -409,7 +413,7 @@ def change_workspace(new_workspace: MSCDirectory):
def get_workspace_subdir(
- name: str = None, keep_history: bool = True, cleanup: bool = False
+ name: Optional[str] = None, keep_history: bool = True, cleanup: bool = False
) -> MSCDirectory:
"""Create sub dir for workspace
@@ -455,7 +459,7 @@ def to_abs_path(path: str, root_dir: MSCDirectory = None, keep_history: bool = T
return root_dir.relpath(path, keep_history)
-def pack_folder(path: str, dst: str = None, style="tar.gz"):
+def pack_folder(path: str, dst: Optional[str] = None, style="tar.gz"):
"""Pack the folder
Parameters
@@ -488,7 +492,7 @@ def pack_folder(path: str, dst: str = None, style="tar.gz"):
return dst
-def unpack_folder(path: str, dst: str = None, style="tar.gz"):
+def unpack_folder(path: str, dst: Optional[str] = None, style="tar.gz"):
"""UnPack the folder
Parameters
diff --git a/python/tvm/contrib/msc/core/utils/info.py b/python/tvm/contrib/msc/core/utils/info.py
index 7da805245e..1b5b428c72 100644
--- a/python/tvm/contrib/msc/core/utils/info.py
+++ b/python/tvm/contrib/msc/core/utils/info.py
@@ -14,9 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""tvm.contrib.msc.core.utils.info"""
-from typing import Any, Dict, List, Tuple, Union
+from typing import Any, Dict, List, Optional, Tuple, Union
import numpy as np
from packaging.version import parse
@@ -154,7 +155,7 @@ class MSCArray:
return tvm.runtime.tensor(data, device=self.get_device(device, framework))
return data
- def get_device(self, device: str, framework: str = None) -> Any:
+ def get_device(self, device: str, framework: Optional[str] = None) -> Any:
"""Change device from name to device obj
Parameters
diff --git a/python/tvm/contrib/msc/core/utils/log.py b/python/tvm/contrib/msc/core/utils/log.py
index 4794cb5003..278e231a5b 100644
--- a/python/tvm/contrib/msc/core/utils/log.py
+++ b/python/tvm/contrib/msc/core/utils/log.py
@@ -18,7 +18,7 @@
import logging
import os
-from typing import Union
+from typing import Optional, Union
from .file import get_workspace
from .namespace import MSCKey, MSCMap
@@ -52,7 +52,9 @@ class IOLogger:
raise Exception(msg)
-def create_file_logger(level: Union[str, int] = logging.INFO, path: str = None) -> logging.Logger:
+def create_file_logger(
+ level: Union[str, int] = logging.INFO, path: Optional[str] = None
+) -> logging.Logger:
"""Create file logger
Parameters
@@ -102,7 +104,9 @@ def create_file_logger(level: Union[str, int] = logging.INFO, path: str = None)
return logger
-def set_global_logger(level: Union[str, int] = logging.INFO, path: str = None) -> logging.Logger:
+def set_global_logger(
+ level: Union[str, int] = logging.INFO, path: Optional[str] = None
+) -> logging.Logger:
"""Create file logger and set to global
Parameters
diff --git a/python/tvm/contrib/msc/core/utils/message.py b/python/tvm/contrib/msc/core/utils/message.py
index e07b3a7ab6..830ef23cbc 100644
--- a/python/tvm/contrib/msc/core/utils/message.py
+++ b/python/tvm/contrib/msc/core/utils/message.py
@@ -14,11 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""tvm.contrib.msc.core.utils.message"""
import datetime
import logging
-from typing import List, Tuple
+from typing import List, Optional, Tuple
from .arguments import dump_dict, map_dict
from .log import get_global_logger, split_line
@@ -61,7 +62,7 @@ class MSCStage:
return cls.ALL
-def time_stamp(stage: str, log_stage: bool = True, logger: logging.Logger = None):
+def time_stamp(stage: str, log_stage: bool = True, logger: Optional[logging.Logger] = None):
"""Mark the stamp and record time.
Parameters
diff --git a/python/tvm/contrib/msc/core/utils/namespace.py b/python/tvm/contrib/msc/core/utils/namespace.py
index 24520a66b3..e3e663b8f2 100644
--- a/python/tvm/contrib/msc/core/utils/namespace.py
+++ b/python/tvm/contrib/msc/core/utils/namespace.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""tvm.contrib.msc.core.utils.namespace"""
import copy
diff --git a/python/tvm/contrib/msc/core/utils/register.py b/python/tvm/contrib/msc/core/utils/register.py
index d6c74c1b62..23b9238baa 100644
--- a/python/tvm/contrib/msc/core/utils/register.py
+++ b/python/tvm/contrib/msc/core/utils/register.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""tvm.contrib.msc.core.utils.register"""
from typing import Any, Optional
diff --git a/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py b/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py
index 061b7b016d..5ea57f390d 100644
--- a/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py
+++ b/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""tvm.contrib.msc.framework.tensorflow.codegen.codegen"""
from typing import Any, Dict, Optional
diff --git a/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py b/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py
index d9e6af1657..6cf5ef5fac 100644
--- a/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=not-context-manager,unused-import
+# ruff: noqa: F401
"""tvm.contrib.msc.framework.tensorflow.runtime.runner"""
import time
diff --git a/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py b/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py
index 38d4cece77..a1c1ec4966 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-import
+# ruff: noqa: F401
"""tvm.contrib.msc.framework.tensorrt.runtime.runner"""
import os
diff --git a/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py b/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
index c6edff562b..f0a0cbd978 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""tvm.contrib.msc.framework.tensorrt.tools.quantize.quantizer"""
import os
diff --git a/python/tvm/contrib/msc/framework/tensorrt/transform/pattern.py b/python/tvm/contrib/msc/framework/tensorrt/transform/pattern.py
index 8a415153e0..726303b7e5 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/transform/pattern.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/transform/pattern.py
@@ -18,7 +18,7 @@
"""tvm.contrib.msc.framework.tensorrt.transform.pattern"""
from functools import partial, wraps
-from typing import Callable, Dict, List, Mapping, Tuple, Union
+from typing import Callable, Dict, List, Mapping, Optional, Tuple, Union
import tvm
from tvm import relax
@@ -30,7 +30,7 @@ from tvm.relax.transform import FusionPattern, PatternCheckContext
def basic_pattern(
- op_name: str, input_types: List[str] = None
+ op_name: str, input_types: Optional[List[str]] = None
) -> Tuple[pattern.DFPattern, Mapping[str, pattern.DFPattern]]:
"""create basic pattern for tensorrt support ops.
@@ -114,7 +114,7 @@ def argmaxmin_pattern(op_name: str) -> Tuple[pattern.DFPattern, Mapping[str, pat
return out, {"input": data, "argmaxmin": argmaxmin, "out": out}
-def _check_expr(expr: relax.Expr, dtypes: Tuple[str] = None) -> bool:
+def _check_expr(expr: relax.Expr, dtypes: Optional[Tuple[str]] = None) -> bool:
"""Check if the expr can be fused on tensorrt.
Parameters
diff --git a/python/tvm/contrib/msc/framework/tensorrt/transform/transform.py b/python/tvm/contrib/msc/framework/tensorrt/transform/transform.py
index 32e955f890..c92df6c4bf 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/transform/transform.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/transform/transform.py
@@ -17,7 +17,7 @@
# pylint: disable=invalid-name
"""tvm.contrib.msc.framework.tensorrt.transform.transform"""
-from typing import List
+from typing import List, Optional
import tvm
from tvm.contrib.msc.core import utils as msc_utils
@@ -26,7 +26,7 @@ from tvm.relax.transform import _ffi_api as relax_api
def TransformTensorRT(
- version: List[int] = None, linear_to_conv: bool = False
+ version: Optional[List[int]] = None, linear_to_conv: bool = False
) -> tvm.ir.transform.Pass:
"""Transform the Function to fit TensorRT.
diff --git a/python/tvm/contrib/msc/framework/torch/frontend/translate.py b/python/tvm/contrib/msc/framework/torch/frontend/translate.py
index 915e51c3da..7c54894244 100644
--- a/python/tvm/contrib/msc/framework/torch/frontend/translate.py
+++ b/python/tvm/contrib/msc/framework/torch/frontend/translate.py
@@ -66,7 +66,7 @@ def from_torch(
trans_config: Optional[Dict[str, str]] = None,
build_config: Optional[Dict[str, str]] = None,
as_msc: bool = True,
- custom_convert_map: dict = None,
+ custom_convert_map: Optional[dict] = None,
) -> Tuple[Union[MSCGraph, tvm.IRModule], Dict[str, tvm.runtime.Tensor]]:
"""Change torch nn.Module to MSCGraph.
diff --git a/python/tvm/contrib/msc/framework/torch/runtime/jit.py b/python/tvm/contrib/msc/framework/torch/runtime/jit.py
index eeb4011c65..36d6db4797 100644
--- a/python/tvm/contrib/msc/framework/torch/runtime/jit.py
+++ b/python/tvm/contrib/msc/framework/torch/runtime/jit.py
@@ -18,7 +18,7 @@
"""tvm.contrib.msc.framework.torch.runtime.jit_model"""
from functools import partial
-from typing import Any, Dict, List, Tuple
+from typing import Any, Dict, List, Optional, Tuple
import torch
from torch import _dynamo as dynamo
@@ -178,7 +178,10 @@ class TorchJIT(BaseJIT):
@classmethod
def dump_nativate(
- cls, model: torch.nn.Module, folder: msc_utils.MSCDirectory, dump_config: dict = None
+ cls,
+ model: torch.nn.Module,
+ folder: msc_utils.MSCDirectory,
+ dump_config: Optional[dict] = None,
) -> str:
"""Dump the nativate model
diff --git a/python/tvm/contrib/msc/framework/torch/runtime/runner.py b/python/tvm/contrib/msc/framework/torch/runtime/runner.py
index 00664a6323..0664b9222a 100644
--- a/python/tvm/contrib/msc/framework/torch/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/torch/runtime/runner.py
@@ -15,10 +15,11 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-import
+# ruff: noqa: F401
"""tvm.contrib.msc.framework.torch.runtime.runner"""
import time
-from typing import Any, Dict, List, Tuple, Union
+from typing import Any, Dict, List, Optional, Tuple, Union
import numpy as np
import torch
@@ -252,7 +253,7 @@ class TorchRunner(ModelRunner):
cls,
model: torch.nn.Module,
folder: msc_utils.MSCDirectory,
- dump_config: dict = None,
+ dump_config: Optional[dict] = None,
) -> str:
"""Dump the nativate model
diff --git a/python/tvm/contrib/msc/framework/tvm/runtime/runner.py b/python/tvm/contrib/msc/framework/tvm/runtime/runner.py
index 9b0966a81d..cb242d2cbd 100644
--- a/python/tvm/contrib/msc/framework/tvm/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/tvm/runtime/runner.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-import
+# ruff: noqa: F401
"""tvm.contrib.msc.framework.runtime.tvm.runner"""
import os
diff --git a/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py b/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py
index ff739e8ca1..703d8efb4b 100644
--- a/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py
+++ b/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-argument
+# ruff: noqa: RUF005
"""tvm.contrib.msc.framework.tvm.tools.quantize.quantizer"""
from typing import List, Union
diff --git a/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py b/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py
index 6c14512c7a..0e29ddcb93 100644
--- a/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py
+++ b/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-argument
+# ruff: noqa: RUF005
"""tvm.contrib.msc.framework.tvm.tools.track.tracker"""
from typing import List, Union
diff --git a/python/tvm/contrib/msc/pipeline/dynamic.py b/python/tvm/contrib/msc/pipeline/dynamic.py
index 7766831e9b..9fe066de07 100644
--- a/python/tvm/contrib/msc/pipeline/dynamic.py
+++ b/python/tvm/contrib/msc/pipeline/dynamic.py
@@ -17,7 +17,7 @@
# pylint: disable=unused-argument
"""tvm.contrib.msc.pipeline.dynamic"""
-from typing import Any, List, Tuple
+from typing import Any, List, Optional, Tuple
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.runtime import BaseJIT
@@ -175,7 +175,7 @@ class MSCDynamic(BasePipeline):
return all(w["worker"].tool_applied(tool_type) for w in self._worker_ctxs.values())
def _apply_tool(
- self, tool_type: str, knowledge: dict = None, data_loader: Any = None
+ self, tool_type: str, knowledge: Optional[dict] = None, data_loader: Any = None
) -> Tuple[dict, dict]:
"""Apply tool with runner
@@ -209,9 +209,9 @@ class MSCDynamic(BasePipeline):
def _create_runtime(
self,
stage: str,
- tools: List[str] = None,
- run_type: str = None,
- run_config: dict = None,
+ tools: Optional[List[str]] = None,
+ run_type: Optional[str] = None,
+ run_config: Optional[dict] = None,
visualize: bool = True,
profile: bool = True,
use_cache: bool = True,
@@ -437,7 +437,7 @@ class MSCDynamic(BasePipeline):
return outputs
- def _record_stage(self, stage: str, info: dict = None, report: dict = None):
+ def _record_stage(self, stage: str, info: Optional[dict] = None, report: Optional[dict] = None):
"""Record the stage
Parameters
diff --git a/python/tvm/contrib/msc/pipeline/manager.py b/python/tvm/contrib/msc/pipeline/manager.py
index c1eff34276..b997f124b2 100644
--- a/python/tvm/contrib/msc/pipeline/manager.py
+++ b/python/tvm/contrib/msc/pipeline/manager.py
@@ -16,7 +16,7 @@
# under the License.
"""tvm.contrib.msc.pipeline.manager"""
-from typing import Any, List, Tuple
+from typing import Any, List, Optional, Tuple
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.gym.control import create_controller
@@ -90,7 +90,7 @@ class MSCManager(BasePipeline):
return self._worker.tool_applied(tool_type)
def _apply_tool(
- self, tool_type: str, knowledge: dict = None, data_loader: Any = None
+ self, tool_type: str, knowledge: Optional[dict] = None, data_loader: Any = None
) -> Tuple[dict, dict]:
"""Apply tool with runner
@@ -116,9 +116,9 @@ class MSCManager(BasePipeline):
def _create_runtime(
self,
stage: str,
- tools: List[str] = None,
- run_type: str = None,
- run_config: dict = None,
+ tools: Optional[List[str]] = None,
+ run_type: Optional[str] = None,
+ run_config: Optional[dict] = None,
visualize: bool = True,
profile: bool = True,
use_cache: bool = True,
diff --git a/python/tvm/contrib/msc/pipeline/pipeline.py b/python/tvm/contrib/msc/pipeline/pipeline.py
index aa0587a544..132a2d51d7 100644
--- a/python/tvm/contrib/msc/pipeline/pipeline.py
+++ b/python/tvm/contrib/msc/pipeline/pipeline.py
@@ -20,7 +20,7 @@
import json
import os
import traceback
-from typing import Any, List, Tuple, Union
+from typing import Any, List, Optional, Tuple, Union
from tvm.contrib.msc.core import _ffi_api
from tvm.contrib.msc.core import utils as msc_utils
@@ -56,10 +56,10 @@ class BasePipeline:
self,
model: Any,
config: dict,
- plugins: dict = None,
+ plugins: Optional[dict] = None,
run_optimize: bool = True,
run_compile: bool = True,
- root: str = None,
+ root: Optional[str] = None,
):
# change path to root path
if root:
@@ -361,7 +361,7 @@ class BasePipeline:
return False
def _apply_tool(
- self, tool_type: str, knowledge: dict = None, data_loader: Any = None
+ self, tool_type: str, knowledge: Optional[dict] = None, data_loader: Any = None
) -> Tuple[dict, dict]:
"""Apply tool with runner
@@ -387,9 +387,9 @@ class BasePipeline:
def _create_runtime(
self,
stage: str,
- tools: List[str] = None,
- run_type: str = None,
- run_config: dict = None,
+ tools: Optional[List[str]] = None,
+ run_type: Optional[str] = None,
+ run_config: Optional[dict] = None,
visualize: bool = True,
profile: bool = True,
use_cache: bool = True,
@@ -445,7 +445,7 @@ class BasePipeline:
raise NotImplementedError("_run_gym is not implemented in " + str(self.__class__))
- def summary(self, err_msg: str = None, err_info: str = None) -> dict:
+ def summary(self, err_msg: Optional[str] = None, err_info: Optional[str] = None) -> dict:
"""Summary the pipeline.
Parameters
@@ -469,7 +469,7 @@ class BasePipeline:
self._report["duration"] = msc_utils.get_duration()
return self._report
- def export(self, path: str = None, dump: bool = True) -> Union[str, dict]:
+ def export(self, path: Optional[str] = None, dump: bool = True) -> Union[str, dict]:
"""Export the pipeline
Parameters
@@ -719,7 +719,7 @@ class BasePipeline:
self._logger.debug(self.pipe_mark(msg))
return loader
- def _record_stage(self, stage: str, info: dict = None, report: dict = None):
+ def _record_stage(self, stage: str, info: Optional[dict] = None, report: Optional[dict] = None):
"""Record the stage
Parameters
@@ -790,7 +790,7 @@ class BasePipeline:
raise NotImplementedError("get_runtime is not implemented in " + str(self.__class__))
- def create_worker(self, model: Any, name: str, config: dict = None):
+ def create_worker(self, model: Any, name: str, config: Optional[dict] = None):
"""Create pipe worker
Parameters
diff --git a/python/tvm/contrib/msc/pipeline/utils.py b/python/tvm/contrib/msc/pipeline/utils.py
index 17ec4f7ab9..e162ef89fd 100644
--- a/python/tvm/contrib/msc/pipeline/utils.py
+++ b/python/tvm/contrib/msc/pipeline/utils.py
@@ -17,7 +17,7 @@
"""tvm.contrib.msc.pipeline.config"""
import copy
-from typing import Dict, List, Tuple, Union
+from typing import Dict, List, Optional, Tuple, Union
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.tools import ToolType
@@ -124,14 +124,14 @@ def create_config(
inputs: List[dict],
outputs: List[str],
model_type: str,
- baseline_type: str = None,
- optimize_type: str = None,
- compile_type: str = None,
- dataset: Dict[str, dict] = None,
- tools: List[Tuple[str, Union[dict, str]]] = None,
+ baseline_type: Optional[str] = None,
+ optimize_type: Optional[str] = None,
+ compile_type: Optional[str] = None,
+ dataset: Optional[Dict[str, dict]] = None,
+ tools: Optional[List[Tuple[str, Union[dict, str]]]] = None,
dynamic: bool = False,
- run_config: Dict[str, dict] = None,
- skip_config: Dict[str, str] = None,
+ run_config: Optional[Dict[str, dict]] = None,
+ skip_config: Optional[Dict[str, str]] = None,
**extra_config,
) -> dict:
"""Create config for msc pipeline
diff --git a/python/tvm/contrib/msc/pipeline/worker.py b/python/tvm/contrib/msc/pipeline/worker.py
index 04da6e4183..bdac631706 100644
--- a/python/tvm/contrib/msc/pipeline/worker.py
+++ b/python/tvm/contrib/msc/pipeline/worker.py
@@ -15,12 +15,13 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=import-outside-toplevel, unused-argument
+# ruff: noqa: E501
"""tvm.contrib.msc.pipeline.worker"""
import logging
import os
import time
-from typing import Any, List, Tuple
+from typing import Any, List, Optional, Tuple
import tvm
from tvm.contrib.msc.core import utils as msc_utils
@@ -60,8 +61,8 @@ class BasePipeWorker:
model: Any,
config: dict,
workspace: msc_utils.MSCDirectory,
- plugins: dict = None,
- logger: logging.Logger = None,
+ plugins: Optional[dict] = None,
+ logger: Optional[logging.Logger] = None,
name: str = "main",
):
# check/set default stage
@@ -128,7 +129,7 @@ class BasePipeWorker:
{"inputs": self._config["inputs"], "outputs": self._config["outputs"]}
)
- def _set_debug_level(stage: str, sub_config: dict, default: int = None) -> dict:
+ def _set_debug_level(stage: str, sub_config: dict, default: Optional[int] = None) -> dict:
if "debug_level" in sub_config:
debug_levels[stage] = sub_config["debug_level"]
elif default is not None:
@@ -376,7 +377,7 @@ class BasePipeWorker:
return os.path.isfile(config["plan_file"])
def apply_tool(
- self, tool_type: str, knowledge: dict = None, data_loader: Any = None
+ self, tool_type: str, knowledge: Optional[dict] = None, data_loader: Any = None
) -> Tuple[dict, dict]:
"""Apply tool with runner
@@ -415,9 +416,9 @@ class BasePipeWorker:
def create_runner(
self,
stage: str,
- tools: List[str] = None,
- run_type: str = None,
- run_config: dict = None,
+ tools: Optional[List[str]] = None,
+ run_type: Optional[str] = None,
+ run_config: Optional[dict] = None,
visualize: bool = True,
profile: bool = True,
use_cache: bool = True,
@@ -670,7 +671,7 @@ class BasePipeWorker:
return self._runner.model
raise TypeError("Unexpect return type " + str(ret_type))
- def _get_repeat(self, benchmark: dict, device: str = None) -> int:
+ def _get_repeat(self, benchmark: dict, device: Optional[str] = None) -> int:
"""Get the repeat number for benchmark
Parameters
diff --git a/python/tvm/contrib/msc/pipeline/wrapper.py b/python/tvm/contrib/msc/pipeline/wrapper.py
index e8bfd0a903..875846f70a 100644
--- a/python/tvm/contrib/msc/pipeline/wrapper.py
+++ b/python/tvm/contrib/msc/pipeline/wrapper.py
@@ -17,7 +17,7 @@
"""tvm.contrib.msc.pipeline.wrapper"""
import shutil
-from typing import Any, List, Union
+from typing import Any, List, Optional, Union
from tvm.contrib.msc.core import utils as msc_utils
from tvm.contrib.msc.core.utils.message import MSCStage
@@ -42,7 +42,11 @@ class BaseWrapper:
"""
def __init__(
- self, model: Any, config: dict, workspace: str = "msc_workspace", plugins: dict = None
+ self,
+ model: Any,
+ config: dict,
+ workspace: str = "msc_workspace",
+ plugins: Optional[dict] = None,
):
self._meta_model = model
self._optimized_model, self._compiled_model = None, None
@@ -205,9 +209,9 @@ class BaseWrapper:
cls,
inputs: List[dict],
outputs: List[str],
- baseline_type: str = None,
- optimize_type: str = None,
- compile_type: str = None,
+ baseline_type: Optional[str] = None,
+ optimize_type: Optional[str] = None,
+ compile_type: Optional[str] = None,
**kwargs,
) -> dict:
"""Create config for msc pipeline
diff --git a/python/tvm/contrib/msc/plugin/codegen/codegen.py b/python/tvm/contrib/msc/plugin/codegen/codegen.py
index 4b4d7fe2e8..c2debbedd3 100644
--- a/python/tvm/contrib/msc/plugin/codegen/codegen.py
+++ b/python/tvm/contrib/msc/plugin/codegen/codegen.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""tvm.contrib.msc.core.codegen.codegen"""
import os
@@ -55,8 +56,8 @@ class BasePluginCodeGen:
codegen_config: Optional[Dict[str, str]] = None,
cpp_print_config: Optional[Dict[str, str]] = None,
py_print_config: Optional[Dict[str, str]] = None,
- extern_sources: Dict[str, str] = None,
- extern_libs: Dict[str, str] = None,
+ extern_sources: Optional[Dict[str, str]] = None,
+ extern_libs: Optional[Dict[str, str]] = None,
on_debug: bool = False,
):
self._codegen_config = msc_utils.copy_dict(codegen_config)
@@ -270,8 +271,8 @@ def get_codegen(
codegen_config: Optional[Dict[str, str]] = None,
cpp_print_config: Optional[Dict[str, str]] = None,
py_print_config: Optional[Dict[str, str]] = None,
- extern_sources: Dict[str, str] = None,
- extern_libs: Dict[str, str] = None,
+ extern_sources: Optional[Dict[str, str]] = None,
+ extern_libs: Optional[Dict[str, str]] = None,
on_debug: bool = False,
):
"""Create codegen for framework
diff --git a/python/tvm/contrib/msc/plugin/codegen/sources.py b/python/tvm/contrib/msc/plugin/codegen/sources.py
index a0923cd321..ee2c5e9922 100644
--- a/python/tvm/contrib/msc/plugin/codegen/sources.py
+++ b/python/tvm/contrib/msc/plugin/codegen/sources.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""tvm.contrib.msc.plugin.codegen.sources"""
from typing import Dict
diff --git a/python/tvm/contrib/nnpack.py b/python/tvm/contrib/nnpack.py
index 70291effd1..9e4d69efdd 100644
--- a/python/tvm/contrib/nnpack.py
+++ b/python/tvm/contrib/nnpack.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""External function interface to NNPACK libraries."""
import tvm_ffi
diff --git a/python/tvm/contrib/nvcc.py b/python/tvm/contrib/nvcc.py
index a869c3834a..b9770ab95e 100644
--- a/python/tvm/contrib/nvcc.py
+++ b/python/tvm/contrib/nvcc.py
@@ -679,9 +679,9 @@ def get_cuda_version(cuda_path=None):
(out, _) = proc.communicate()
out = py_str(out)
if proc.returncode == 0:
- release_line = [line for line in out.split("\n") if "release" in line][0]
+ release_line = next(line for line in out.split("\n") if "release" in line)
release_fields = [s.strip() for s in release_line.split(",")]
- version_str = [f[1:] for f in release_fields if f.startswith("V")][0]
+ version_str = next(f[1:] for f in release_fields if f.startswith("V"))
return tuple(int(field) for field in version_str.split("."))
raise RuntimeError("Cannot read CUDA version file")
diff --git a/python/tvm/contrib/pickle_memoize.py b/python/tvm/contrib/pickle_memoize.py
index ebe0adf817..f9981a5ea4 100644
--- a/python/tvm/contrib/pickle_memoize.py
+++ b/python/tvm/contrib/pickle_memoize.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005, RUF012
"""Memoize result of function via pickle, used for cache testcases."""
# pylint: disable=broad-except,superfluous-parens
diff --git a/python/tvm/contrib/popen_pool.py b/python/tvm/contrib/popen_pool.py
index 436f0f3c34..76f9d65962 100644
--- a/python/tvm/contrib/popen_pool.py
+++ b/python/tvm/contrib/popen_pool.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E731
"""Multiprocessing via Popen.
This module provides a multi-processing pool backed by Popen.
diff --git a/python/tvm/contrib/rpc.py b/python/tvm/contrib/rpc.py
index 4a13ef3e04..5fbc06a9f1 100644
--- a/python/tvm/contrib/rpc.py
+++ b/python/tvm/contrib/rpc.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Deprecation RPC module"""
# pylint: disable=unused-import
diff --git a/python/tvm/contrib/tvmjs.py b/python/tvm/contrib/tvmjs.py
index 9227a352ed..a419f7c4d7 100644
--- a/python/tvm/contrib/tvmjs.py
+++ b/python/tvm/contrib/tvmjs.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401
"""Namespace to store utilities for building web runtime."""
import hashlib
@@ -255,7 +256,7 @@ def dump_tensor_cache(
f32_to_bf16_triggered = False
- print("Start storing to cache %s" % cache_dir)
+ print(f"Start storing to cache {cache_dir}")
shard_cap_nbytes = shard_cap_mb * (1 << 20)
nd_cache_json = os.path.join(cache_dir, "tensor-cache.json")
@@ -305,7 +306,7 @@ def dump_tensor_cache(
counter += 1
if show_progress:
- last_cmd = "[%04d] saving %s" % (counter, k)
+ last_cmd = f"[{counter:04d}] saving {k}"
flush = "\r" + (" " * max_out_length) + "\r"
max_out_length = max(len(last_cmd), max_out_length)
sys.stdout.write(flush + last_cmd)
@@ -316,8 +317,7 @@ def dump_tensor_cache(
with open(nd_cache_json, "w") as outfile:
json.dump({"metadata": meta_data, "records": records}, outfile, indent=4)
print(
- "\nAll finished, %d total shards committed, record saved to %s"
- % (shard_manager.counter, nd_cache_json)
+ f"\nAll finished, {shard_manager.counter} total shards committed, record saved to {nd_cache_json}"
)
if f32_to_bf16_triggered:
@@ -330,7 +330,7 @@ def dump_tensor_cache(
# also dump a file that contains bf16
with open(b16_nd_cache_json, "w") as outfile:
json.dump({"metadata": meta_data, "records": records}, outfile, indent=4)
- print("Also saved a bf16 record to %s" % b16_nd_cache_json)
+ print(f"Also saved a bf16 record to {b16_nd_cache_json}")
def load_tensor_cache(cachepath: str, device: tvm.runtime.Device):
diff --git a/python/tvm/contrib/utils.py b/python/tvm/contrib/utils.py
index e7882aba39..63611997c2 100644
--- a/python/tvm/contrib/utils.py
+++ b/python/tvm/contrib/utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005, RUF012
"""Common system utilities"""
import atexit
diff --git a/python/tvm/contrib/xcode.py b/python/tvm/contrib/xcode.py
index 91f3c6bf66..d67a86395b 100644
--- a/python/tvm/contrib/xcode.py
+++ b/python/tvm/contrib/xcode.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E501, RUF005
"""Utility to invoke Xcode compiler toolchain"""
import json
diff --git a/python/tvm/exec/disco_remote_socket_session.py b/python/tvm/exec/disco_remote_socket_session.py
index 324ca16048..b79acf4342 100644
--- a/python/tvm/exec/disco_remote_socket_session.py
+++ b/python/tvm/exec/disco_remote_socket_session.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: F401
"""Launch disco session in the remote node and connect to the server."""
import sys
diff --git a/python/tvm/exec/disco_worker.py b/python/tvm/exec/disco_worker.py
index bf06a84c98..505dbff5c4 100644
--- a/python/tvm/exec/disco_worker.py
+++ b/python/tvm/exec/disco_worker.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF005
"""Internal DiscoWorker for Disco ProcessSession."""
import os
diff --git a/python/tvm/exec/gpu_memory_bandwidth.py b/python/tvm/exec/gpu_memory_bandwidth.py
index 2b12e847a8..4a5fb092f0 100644
--- a/python/tvm/exec/gpu_memory_bandwidth.py
+++ b/python/tvm/exec/gpu_memory_bandwidth.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F821
"""A script to measure GPU memory bandwidth"""
import argparse
diff --git a/python/tvm/exec/popen_worker.py b/python/tvm/exec/popen_worker.py
index 5ba7bd66a9..0fd77ccb17 100644
--- a/python/tvm/exec/popen_worker.py
+++ b/python/tvm/exec/popen_worker.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF012
"""Internal PopenWorker for PopenPool."""
import logging
diff --git a/python/tvm/exec/query_rpc_tracker.py b/python/tvm/exec/query_rpc_tracker.py
index 234a3e036b..f4d1627846 100644
--- a/python/tvm/exec/query_rpc_tracker.py
+++ b/python/tvm/exec/query_rpc_tracker.py
@@ -40,8 +40,8 @@ def main():
conn = rpc.connect_tracker(args.host, args.port)
# pylint: disable=superfluous-parens
- print("Tracker address %s:%d\n" % (args.host, args.port))
- print("%s" % conn.text_summary())
+ print(f"Tracker address {args.host}:{args.port}\n")
+ print(f"{conn.text_summary()}")
if __name__ == "__main__":
diff --git a/python/tvm/exec/rpc_proxy.py b/python/tvm/exec/rpc_proxy.py
index 132b4038e2..a425edd9a1 100644
--- a/python/tvm/exec/rpc_proxy.py
+++ b/python/tvm/exec/rpc_proxy.py
@@ -47,7 +47,7 @@ def find_example_resource():
for base in resource_bases:
if not os.path.isdir(base):
continue
- for full_name in glob.glob("%s/**" % base, recursive=True):
+ for full_name in glob.glob(f"{base}/**", recursive=True):
fname = os.path.relpath(full_name, base)
dirname = os.path.dirname(fname)
fmt = fname.rsplit(".", 1)[-1]
@@ -57,7 +57,7 @@ def find_example_resource():
for item in resource_files:
fname = item[-1]
if not os.path.exists(fname):
- raise RuntimeError("Cannot find %s" % fname)
+ raise RuntimeError(f"Cannot find {fname}")
if not any(item[-1].endswith("rpc_plugin.html") for item in resource_files):
resource_files.append(("/", default_plugin_page))
diff --git a/python/tvm/ffi.py b/python/tvm/ffi.py
index 1d5e359acb..29d82a477b 100644
--- a/python/tvm/ffi.py
+++ b/python/tvm/ffi.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=wildcard-import
+# ruff: noqa: F403
"""Redirects to tvm_ffi"""
from tvm_ffi import *
diff --git a/python/tvm/libinfo.py b/python/tvm/libinfo.py
index d1cd15b6f5..3f69bb98ec 100644
--- a/python/tvm/libinfo.py
+++ b/python/tvm/libinfo.py
@@ -176,7 +176,7 @@ def find_lib_path(name=None, search_path=None, optional=False):
return None
if use_runtime:
- sys.stderr.write("Loading runtime library %s... exec only\n" % lib_found[0])
+ sys.stderr.write(f"Loading runtime library {lib_found[0]}... exec only\n")
sys.stderr.flush()
return lib_found
diff --git a/python/tvm/relax/analysis/analysis.py b/python/tvm/relax/analysis/analysis.py
index bbd9a5549a..3545203b53 100644
--- a/python/tvm/relax/analysis/analysis.py
+++ b/python/tvm/relax/analysis/analysis.py
@@ -52,8 +52,8 @@ def get_static_type(sinfo: StructInfo) -> Type:
def erase_to_well_defined(
sinfo: StructInfo,
- shape_var_map: Dict[tir.Var, tir.PrimExpr] = None,
- var_map: Dict[Var, Expr] = None,
+ shape_var_map: Optional[Dict[tir.Var, tir.PrimExpr]] = None,
+ var_map: Optional[Dict[Var, Expr]] = None,
) -> StructInfo:
"""Erase sinfo into a well defined form.
diff --git a/python/tvm/relax/backend/cuda/cutlass.py b/python/tvm/relax/backend/cuda/cutlass.py
index bc92cc7d73..1e57df319f 100644
--- a/python/tvm/relax/backend/cuda/cutlass.py
+++ b/python/tvm/relax/backend/cuda/cutlass.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E731
"""Pattern table for CUTLASS backend"""
import operator
diff --git a/python/tvm/relax/backend/patterns.py b/python/tvm/relax/backend/patterns.py
index c01f7c175b..4baea6d5c1 100644
--- a/python/tvm/relax/backend/patterns.py
+++ b/python/tvm/relax/backend/patterns.py
@@ -17,7 +17,7 @@
# pylint: disable=invalid-name
"""Common patterns used in BYOC"""
-from typing import Dict, Mapping, Tuple, Union
+from typing import Dict, Mapping, Optional, Tuple, Union
from tvm.relax.dpl.pattern import (
DFPattern,
@@ -36,7 +36,7 @@ def _with_bias_activation_pattern(
out: DFPattern,
annotations: Dict[str, DFPattern],
with_bias: bool = False,
- activation: str = None,
+ activation: Optional[str] = None,
) -> Tuple[DFPattern, Mapping[str, DFPattern]]:
if with_bias:
annotations["bias"] = bias = wildcard()
@@ -51,7 +51,7 @@ def _with_bias_activation_pattern(
def make_fused_bias_activation_pattern(
op_name: str,
with_bias: bool = False,
- activation: str = None,
+ activation: Optional[str] = None,
) -> Tuple[DFPattern, Mapping[str, DFPattern]]:
"""
A simple utility to create patterns for an operation fused with bias addition and activation.
@@ -133,7 +133,7 @@ def make_residual_block_pattern(
def make_conv2d_pattern(
with_bias: bool = False,
- activation: str = None,
+ activation: Optional[str] = None,
) -> Tuple[DFPattern, Mapping[str, DFPattern]]:
"""
Create pattern for 2D convolution.
@@ -169,7 +169,7 @@ def make_conv2d_pattern(
def make_matmul_pattern(
with_bias: bool = False,
- activation: str = None,
+ activation: Optional[str] = None,
transposed_rhs: bool = False,
) -> Tuple[DFPattern, Mapping[str, DFPattern]]:
"""
diff --git a/python/tvm/relax/base_py_module.py b/python/tvm/relax/base_py_module.py
index 2ec84e9c37..e38ee4d4b9 100644
--- a/python/tvm/relax/base_py_module.py
+++ b/python/tvm/relax/base_py_module.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821
"""BasePyModule: Base class for IRModules with Python function support."""
import inspect
diff --git a/python/tvm/relax/block_builder.py b/python/tvm/relax/block_builder.py
index 9f462946fb..c0673e0fbf 100644
--- a/python/tvm/relax/block_builder.py
+++ b/python/tvm/relax/block_builder.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=no-else-return, invalid-name, unused-argument, import-outside-toplevel
+# ruff: noqa: RUF012
"""Developer API of constructing Relax AST."""
from typing import Any, Callable, Dict, List, Optional, Sequence, Union
@@ -370,7 +371,7 @@ class BlockBuilder(Object):
func: Callable,
*args: Any,
te_grad_name: str,
- te_grad_kwargs: Dict[str, Object] = None,
+ te_grad_kwargs: Optional[Dict[str, Object]] = None,
**kwargs: Any,
) -> Expr:
"""Generate a call node according to the te function.
diff --git a/python/tvm/relax/dpl/pattern.py b/python/tvm/relax/dpl/pattern.py
index 0ca3ef289f..179246d8d2 100644
--- a/python/tvm/relax/dpl/pattern.py
+++ b/python/tvm/relax/dpl/pattern.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""Pattern types in Relax Dataflow Pattern Language"""
# pylint: disable=no-member
@@ -940,7 +941,7 @@ def is_call_dps_packed(
def is_call_packed(
- func_name: str, args: Union[List[DFPattern], Tuple[DFPattern]] = None
+ func_name: str, args: Optional[Union[List[DFPattern], Tuple[DFPattern]]] = None
) -> CallPattern:
"""
Syntax sugar for creating a CallPattern for call_packed
diff --git a/python/tvm/relax/exec_builder.py b/python/tvm/relax/exec_builder.py
index 84ca24c978..e530b7e7c6 100644
--- a/python/tvm/relax/exec_builder.py
+++ b/python/tvm/relax/exec_builder.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF012
"""A builder to build Relax VM executable."""
from enum import IntEnum
@@ -94,7 +95,7 @@ class ExecBuilder(tvm_ffi.core.Object):
_ffi_api.ExecBuilderDeclareFunction(self, func_name, kind) # type: ignore
def function(
- self, func_name: str, num_inputs: Optional[int] = 0, param_names: List[str] = None
+ self, func_name: str, num_inputs: Optional[int] = 0, param_names: Optional[List[str]] = None
) -> VMFuncScope:
"""annotate a VM function."""
_ffi_api.ExecBuilderEmitFunction(self, func_name, num_inputs, param_names) # type: ignore
@@ -111,7 +112,7 @@ class ExecBuilder(tvm_ffi.core.Object):
self,
name: str,
args: Optional[List[Union[tvm.runtime.Tensor, tvm.DataType]]] = None,
- dst: int = None,
+ dst: Optional[int] = None,
) -> None:
"""emit a call instruction which calls a packed function."""
self._check_scope()
diff --git a/python/tvm/relax/expr.py b/python/tvm/relax/expr.py
index 0977b498b9..5b9581818a 100644
--- a/python/tvm/relax/expr.py
+++ b/python/tvm/relax/expr.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""The expression nodes of Relax."""
import typing
diff --git a/python/tvm/relax/expr_functor.py b/python/tvm/relax/expr_functor.py
index 4049291652..7cbd4d2a38 100644
--- a/python/tvm/relax/expr_functor.py
+++ b/python/tvm/relax/expr_functor.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, arguments-differ
+# ruff: noqa: RUF012
"""The expression functor of Relax."""
from typing import Callable, Optional
@@ -276,33 +277,33 @@ class _PyExprVisitor(tvm_ffi.core.Object):
def __init__(
self,
- f_visit_expr: Callable = None,
- f_visit_constant_: Callable = None,
- f_visit_tuple_: Callable = None,
- f_visit_var_: Callable = None,
- f_visit_dataflow_var_: Callable = None,
- f_visit_shape_expr_: Callable = None,
- f_visit_extern_func_: Callable = None,
- f_visit_global_var_: Callable = None,
- f_visit_function_: Callable = None,
- f_visit_call_: Callable = None,
- f_visit_seq_expr_: Callable = None,
- f_visit_if_: Callable = None,
- f_visit_op_: Callable = None,
- f_visit_tuple_getitem_: Callable = None,
- f_visit_prim_value_: Callable = None,
- f_visit_string_imm_: Callable = None,
- f_visit_data_type_imm_: Callable = None,
- f_visit_binding: Callable = None,
- f_visit_var_binding_: Callable = None,
- f_visit_match_cast_: Callable = None,
- f_visit_binding_block: Callable = None,
- f_visit_binding_block_: Callable = None,
- f_visit_dataflow_block_: Callable = None,
- f_visit_var_def: Callable = None,
- f_visit_var_def_: Callable = None,
- f_visit_dataflow_var_def_: Callable = None,
- f_visit_span: Callable = None,
+ f_visit_expr: Optional[Callable] = None,
+ f_visit_constant_: Optional[Callable] = None,
+ f_visit_tuple_: Optional[Callable] = None,
+ f_visit_var_: Optional[Callable] = None,
+ f_visit_dataflow_var_: Optional[Callable] = None,
+ f_visit_shape_expr_: Optional[Callable] = None,
+ f_visit_extern_func_: Optional[Callable] = None,
+ f_visit_global_var_: Optional[Callable] = None,
+ f_visit_function_: Optional[Callable] = None,
+ f_visit_call_: Optional[Callable] = None,
+ f_visit_seq_expr_: Optional[Callable] = None,
+ f_visit_if_: Optional[Callable] = None,
+ f_visit_op_: Optional[Callable] = None,
+ f_visit_tuple_getitem_: Optional[Callable] = None,
+ f_visit_prim_value_: Optional[Callable] = None,
+ f_visit_string_imm_: Optional[Callable] = None,
+ f_visit_data_type_imm_: Optional[Callable] = None,
+ f_visit_binding: Optional[Callable] = None,
+ f_visit_var_binding_: Optional[Callable] = None,
+ f_visit_match_cast_: Optional[Callable] = None,
+ f_visit_binding_block: Optional[Callable] = None,
+ f_visit_binding_block_: Optional[Callable] = None,
+ f_visit_dataflow_block_: Optional[Callable] = None,
+ f_visit_var_def: Optional[Callable] = None,
+ f_visit_var_def_: Optional[Callable] = None,
+ f_visit_dataflow_var_def_: Optional[Callable] = None,
+ f_visit_span: Optional[Callable] = None,
) -> None:
"""Constructor."""
@@ -797,33 +798,33 @@ class _PyExprMutator(Object):
def __init__(
self,
builder: BlockBuilder = None,
- f_visit_expr: Callable = None,
- f_visit_constant_: Callable = None,
- f_visit_tuple_: Callable = None,
- f_visit_var_: Callable = None,
- f_visit_dataflow_var_: Callable = None,
- f_visit_shape_expr_: Callable = None,
- f_visit_extern_func_: Callable = None,
- f_visit_global_var_: Callable = None,
- f_visit_function_: Callable = None,
- f_visit_call_: Callable = None,
- f_visit_seq_expr_: Callable = None,
- f_visit_if_: Callable = None,
- f_visit_op_: Callable = None,
- f_visit_tuple_getitem_: Callable = None,
- f_visit_prim_value_: Callable = None,
- f_visit_string_imm_: Callable = None,
- f_visit_data_type_imm_: Callable = None,
- f_visit_binding: Callable = None,
- f_visit_var_binding_: Callable = None,
- f_visit_match_cast_: Callable = None,
- f_visit_binding_block: Callable = None,
- f_visit_binding_block_: Callable = None,
- f_visit_dataflow_block_: Callable = None,
- f_visit_var_def: Callable = None,
- f_visit_var_def_: Callable = None,
- f_visit_dataflow_var_def_: Callable = None,
- f_visit_span: Callable = None,
+ f_visit_expr: Optional[Callable] = None,
+ f_visit_constant_: Optional[Callable] = None,
+ f_visit_tuple_: Optional[Callable] = None,
+ f_visit_var_: Optional[Callable] = None,
+ f_visit_dataflow_var_: Optional[Callable] = None,
+ f_visit_shape_expr_: Optional[Callable] = None,
+ f_visit_extern_func_: Optional[Callable] = None,
+ f_visit_global_var_: Optional[Callable] = None,
+ f_visit_function_: Optional[Callable] = None,
+ f_visit_call_: Optional[Callable] = None,
+ f_visit_seq_expr_: Optional[Callable] = None,
+ f_visit_if_: Optional[Callable] = None,
+ f_visit_op_: Optional[Callable] = None,
+ f_visit_tuple_getitem_: Optional[Callable] = None,
+ f_visit_prim_value_: Optional[Callable] = None,
+ f_visit_string_imm_: Optional[Callable] = None,
+ f_visit_data_type_imm_: Optional[Callable] = None,
+ f_visit_binding: Optional[Callable] = None,
+ f_visit_var_binding_: Optional[Callable] = None,
+ f_visit_match_cast_: Optional[Callable] = None,
+ f_visit_binding_block: Optional[Callable] = None,
+ f_visit_binding_block_: Optional[Callable] = None,
+ f_visit_dataflow_block_: Optional[Callable] = None,
+ f_visit_var_def: Optional[Callable] = None,
+ f_visit_var_def_: Optional[Callable] = None,
+ f_visit_dataflow_var_def_: Optional[Callable] = None,
+ f_visit_span: Optional[Callable] = None,
) -> None:
"""Constructor."""
diff --git a/python/tvm/relax/frontend/nn/_tensor_op.py b/python/tvm/relax/frontend/nn/_tensor_op.py
index 6692bceb3d..0a5142f3a1 100644
--- a/python/tvm/relax/frontend/nn/_tensor_op.py
+++ b/python/tvm/relax/frontend/nn/_tensor_op.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""Adding member operators to nn.Tensor."""
from typing import Optional
diff --git a/python/tvm/relax/frontend/nn/exporter.py b/python/tvm/relax/frontend/nn/exporter.py
index 3e96456eaf..07db1821f6 100644
--- a/python/tvm/relax/frontend/nn/exporter.py
+++ b/python/tvm/relax/frontend/nn/exporter.py
@@ -16,6 +16,8 @@
# under the License.
"""Export `nn.Module` to TVM's IRModule."""
+import functools
+import operator
import threading
import typing
@@ -226,7 +228,7 @@ def _emit_method( # pylint: disable=too-many-locals,too-many-branches,too-many-
effect_input = effect.create(name)
effect.set_state(effect_input)
unflat_inputs.append(effect_input)
- inputs: typing.List[rx.Var] = sum(unflat_inputs, [])
+ inputs: typing.List[rx.Var] = functools.reduce(operator.iadd, unflat_inputs, [])
if mode == "none":
return []
if mode == "plain":
diff --git a/python/tvm/relax/frontend/nn/extern.py b/python/tvm/relax/frontend/nn/extern.py
index af9f7ef471..4ad55a0c7e 100644
--- a/python/tvm/relax/frontend/nn/extern.py
+++ b/python/tvm/relax/frontend/nn/extern.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""External modules to be linked into the exported IRModule."""
import os
diff --git a/python/tvm/relax/frontend/nn/llm/kv_cache.py b/python/tvm/relax/frontend/nn/llm/kv_cache.py
index 07bec2b0ce..21d238b7c2 100644
--- a/python/tvm/relax/frontend/nn/llm/kv_cache.py
+++ b/python/tvm/relax/frontend/nn/llm/kv_cache.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E731, RUF005, RUF012
"""Attention KV cache modeling."""
@@ -490,7 +491,6 @@ class FlashInferPagedKVCache(PagedKVCache): # pylint: disable=too-few-public-me
bb.add_func(_copy_single_page(num_key_value_heads, page_size, qk_head_dim, dtype, target) if attn_kind_single == "mha" else _copy_single_page_mla(page_size, qk_head_dim, dtype, target), "kv_cache_copy_single_page"),
bb.add_func(_kv_cache_debug_get_kv(num_hidden_layers, num_key_value_heads, qk_head_dim, dtype), "kv_cache_debug_get_kv"),
bb.add_func(_compact_kv_copy(num_key_value_heads, qk_head_dim, dtype, target), "kv_cache_compact_kv_copy"),
- # fmt: on
# pylint: enable=line-too-long
]
super().__init__(
@@ -613,7 +613,6 @@ class TIRPagedKVCache(PagedKVCache): # pylint: disable=too-few-public-methods
rope_ext_factors,
rx.op.zeros((), dtype),
# pylint: disable=line-too-long
- # fmt: off
bb.add_func(
_kv_cache_transpose_append(num_key_value_heads, qk_head_dim, dtype),
"kv_cache_transpose_append",
@@ -621,7 +620,6 @@ class TIRPagedKVCache(PagedKVCache): # pylint: disable=too-few-public-methods
bb.add_func(
_kv_cache_transpose_append_mla(qk_head_dim, dtype), "kv_cache_transpose_append_mla"
),
- # fmt: on
# pylint: enable=line-too-long
]
@@ -1139,7 +1137,7 @@ def _schedule_prefill_kernel(
def get_tile_size(x, y, t):
cnt = (x * y) // t
assert (x * y) % t == 0
- tile_y = (int)(math.ceil(math.sqrt(cnt)))
+ tile_y = math.ceil(math.sqrt(cnt))
while (cnt % tile_y != 0 or y % tile_y != 0 or x % (cnt // tile_y) != 0) and tile_y <= cnt:
tile_y += 1
assert tile_y <= cnt
diff --git a/python/tvm/relax/frontend/nn/llm/tree_attn.py b/python/tvm/relax/frontend/nn/llm/tree_attn.py
index 88f2aff2d5..433ce75928 100644
--- a/python/tvm/relax/frontend/nn/llm/tree_attn.py
+++ b/python/tvm/relax/frontend/nn/llm/tree_attn.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E501, F841, RUF005
"""Operators for tree attention."""
@@ -584,7 +585,7 @@ def tree_attn(h_kv, h_q, d, dtype, rope_scaling: Dict[str, Any], target: Target)
def get_tile_size(x, y, t):
cnt = (x * y) // t
assert (x * y) % t == 0
- tile_y = (int)(math.ceil(math.sqrt(cnt)))
+ tile_y = math.ceil(math.sqrt(cnt))
while (cnt % tile_y != 0 or y % tile_y != 0) and tile_y <= cnt:
tile_y += 1
assert tile_y <= cnt
@@ -1277,7 +1278,7 @@ def tree_attn_with_paged_kv_cache(
def get_tile_size(x, y, t):
cnt = (x * y) // t
assert (x * y) % t == 0
- tile_y = (int)(math.ceil(math.sqrt(cnt)))
+ tile_y = math.ceil(math.sqrt(cnt))
while (cnt % tile_y != 0 or y % tile_y != 0) and tile_y <= cnt:
tile_y += 1
assert tile_y <= cnt
diff --git a/python/tvm/relax/frontend/nn/modules.py b/python/tvm/relax/frontend/nn/modules.py
index a277339b84..c234f8a02c 100644
--- a/python/tvm/relax/frontend/nn/modules.py
+++ b/python/tvm/relax/frontend/nn/modules.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=too-many-arguments,invalid-name,protected-access,unused-argument
+# ruff: noqa: RUF005
"""Builtin Modules."""
from typing import List, Optional, Sequence, Union
@@ -757,7 +758,7 @@ class TimestepEmbedding(Module):
in_channels: int,
time_embed_dim: int,
act_fn: str = "silu",
- out_dim: int = None,
+ out_dim: Optional[int] = None,
post_act_fn: Optional[str] = None,
cond_proj_dim: Optional[int] = None,
):
diff --git a/python/tvm/relax/frontend/nn/op.py b/python/tvm/relax/frontend/nn/op.py
index 32ba80e535..03b05492d4 100644
--- a/python/tvm/relax/frontend/nn/op.py
+++ b/python/tvm/relax/frontend/nn/op.py
@@ -726,7 +726,7 @@ def broadcast_to(x: Tensor, shape: Sequence[IntExpr], name: str = "broadcast_to"
return wrap_nested(_op.broadcast_to(x._expr, shape), name)
-def permute_dims(x: Tensor, axes: Optional[List[int]] = None, name: str = None) -> Tensor:
+def permute_dims(x: Tensor, axes: Optional[List[int]] = None, name: Optional[str] = None) -> Tensor:
"""Permutes the dimensions of an array.
Parameters
diff --git a/python/tvm/relax/frontend/onnx/onnx_frontend.py b/python/tvm/relax/frontend/onnx/onnx_frontend.py
index 5a927f0839..a512e20e23 100644
--- a/python/tvm/relax/frontend/onnx/onnx_frontend.py
+++ b/python/tvm/relax/frontend/onnx/onnx_frontend.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E731, E741, F841, RUF005
"""ONNX: Open Neural Network Exchange importer for Relax.
This module implements the required functionality to read ONNX models
@@ -274,7 +275,7 @@ class onnx_input(list): # pylint: disable=invalid-name
return [self[i] for i in indices]
if isinstance(item, int):
return list(self)[item] if item < len(self) else None
- raise TypeError("list indices must be integers or slices, not %s" % type(item).__name__)
+ raise TypeError(f"list indices must be integers or slices, not {type(item).__name__}")
# pylint: disable=invalid-name, len-as-condition, unused-argument, too-many-lines, redefined-builtin
@@ -2083,7 +2084,7 @@ class Expand(OnnxOpConverter):
return relax.op.broadcast_to(data, relax.ShapeExpr(new_shape))
# Otherwise handle dynamic shapes.
- shape_ndim = [dim.value for dim in shape.struct_info.shape.values][0]
+ shape_ndim = next(dim.value for dim in shape.struct_info.shape.values)
shape_dataflow_var = bb.emit(
relax.Call(
relax.ExternFunc("vm.builtin.tensor_to_shape"),
@@ -2094,7 +2095,7 @@ class Expand(OnnxOpConverter):
shape_vars = []
for i in range(shape_ndim):
- shape_vars.append(tvm.tir.Var("x_%d" % i, "int64"))
+ shape_vars.append(tvm.tir.Var(f"x_{i}", "int64"))
bb.match_cast(shape_dataflow_var, relax.ShapeStructInfo(shape_vars))
# Applying broadcasting rules for dynamic shapes
@@ -4149,7 +4150,7 @@ class ONNXGraphImporter:
new_name = str(self._name_supply.fresh_name(new_name))
if new_name != name:
- warnings.warn("Renaming name %s to %s" % (name, new_name))
+ warnings.warn(f"Renaming name {name} to {new_name}")
return new_name
def _new_var(self, var_name: str, shape: List, dtype: str = "float32"):
@@ -4173,9 +4174,8 @@ class ONNXGraphImporter:
else:
if "?" in str(i_shape):
warning_msg = (
- "Input %s has unknown dimension shapes: %s. "
+ f"Input {i_name} has unknown dimension shapes: {i_shape_name!s}. "
"Specifying static values may improve performance"
- % (i_name, str(i_shape_name))
)
warnings.warn(warning_msg)
if isinstance(self._dtype, dict):
@@ -4361,7 +4361,7 @@ def from_onnx(
model: onnx.onnx_ml_pb2.GraphProto,
shape_dict: Optional[Dict[str, List]] = None,
dtype_dict: Optional[Union[str, Dict[str, str]]] = "float32",
- opset: int = None,
+ opset: Optional[int] = None,
keep_params_in_input: bool = False,
sanitize_input_names: bool = True,
) -> IRModule:
diff --git a/python/tvm/relax/frontend/stablehlo/stablehlo_translator.py b/python/tvm/relax/frontend/stablehlo/stablehlo_translator.py
index 4f47380f44..f3bb2a57fa 100644
--- a/python/tvm/relax/frontend/stablehlo/stablehlo_translator.py
+++ b/python/tvm/relax/frontend/stablehlo/stablehlo_translator.py
@@ -18,7 +18,7 @@
"""StableHLO frontend of Relax."""
-from typing import Any, Callable, Dict, List, Tuple, Union
+from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import tvm
from tvm import relax, tir
@@ -416,7 +416,7 @@ class StableHLOImporter:
def from_stablehlo(
stablehlo_module,
- input_info: List[Tuple[Tuple[int], str]] = None,
+ input_info: Optional[List[Tuple[Tuple[int], str]]] = None,
) -> tvm.IRModule:
"""Convert a StableHLO Module to a Relax program
diff --git a/python/tvm/relax/frontend/torch/base_fx_graph_translator.py b/python/tvm/relax/frontend/torch/base_fx_graph_translator.py
index d6b86b0a70..5fe0ef17d4 100644
--- a/python/tvm/relax/frontend/torch/base_fx_graph_translator.py
+++ b/python/tvm/relax/frontend/torch/base_fx_graph_translator.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731
# pylint: disable=invalid-name, inconsistent-return-statements, unidiomatic-typecheck
# pylint: disable=import-outside-toplevel
@@ -334,7 +335,7 @@ class BaseFXGraphImporter(metaclass=abc.ABCMeta):
if not isinstance(alpha, relax.Var):
alpha = self.block_builder.emit(relax.const(-alpha, dtype))
- # alpha * ReLU(1 − exp(x)) + ReLU(x)
+ # alpha * ReLU(1 - exp(x)) + ReLU(x)
return self.block_builder.emit(
relax.op.add(
relax.op.multiply(
diff --git a/python/tvm/relax/frontend/torch/exported_program_translator.py b/python/tvm/relax/frontend/torch/exported_program_translator.py
index 62f2d1231c..233cba8df9 100644
--- a/python/tvm/relax/frontend/torch/exported_program_translator.py
+++ b/python/tvm/relax/frontend/torch/exported_program_translator.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
# pylint: disable=invalid-name, inconsistent-return-statements, unidiomatic-typecheck
# pylint: disable=import-outside-toplevel
diff --git a/python/tvm/relax/frontend/torch/fx_translator.py b/python/tvm/relax/frontend/torch/fx_translator.py
index 75a5d6a175..74ffebd823 100644
--- a/python/tvm/relax/frontend/torch/fx_translator.py
+++ b/python/tvm/relax/frontend/torch/fx_translator.py
@@ -20,7 +20,7 @@
"""PyTorch FX frontend of Relax."""
from functools import partial, reduce
-from typing import Callable, Dict, List, Tuple, Union
+from typing import Callable, Dict, List, Optional, Tuple, Union
import tvm
from tvm import relax
@@ -1045,7 +1045,7 @@ class TorchFXImporter(BaseFXGraphImporter):
keep_params_as_input: bool,
unwrap_unit_return_tuple: bool,
no_bind_return_tuple: bool,
- custom_convert_map: dict = None,
+ custom_convert_map: Optional[dict] = None,
) -> tvm.IRModule:
"""Convert a PyTorch FX GraphModule to a Relax program."""
from torch import fx
@@ -1091,7 +1091,7 @@ class TorchFXImporter(BaseFXGraphImporter):
if not keep_params_as_input:
self.params[param] = self._convert_torch_tensor_to_relax(param)
else:
- raise ValueError("Unsupported data type for model parameters: %s" % dtype)
+ raise ValueError(f"Unsupported data type for model parameters: {dtype}")
# Translate the model.
for node in graph.nodes:
if node.op == "placeholder":
@@ -1155,7 +1155,7 @@ def from_fx(
keep_params_as_input: bool = False,
unwrap_unit_return_tuple: bool = False,
no_bind_return_tuple: bool = False,
- custom_convert_map: dict = None,
+ custom_convert_map: Optional[dict] = None,
default_image_layout: str = "NCHW",
) -> tvm.IRModule:
"""Convert a PyTorch FX GraphModule to a Relax program
diff --git a/python/tvm/relax/op/base.py b/python/tvm/relax/op/base.py
index 06f7d793f6..d3db6655a2 100644
--- a/python/tvm/relax/op/base.py
+++ b/python/tvm/relax/op/base.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# pylint: disable=redefined-builtin
+# ruff: noqa: F821
"""The base Relax operators."""
from typing import Callable, Dict, List, Optional, Tuple, Union
@@ -34,7 +35,7 @@ py_print = print # pylint: disable=invalid-name
def register_gradient(
op_name: str,
- fgradient: Callable[[Var, Call, Var, "BlockBuilder"], List[Expr]] = None,
+ fgradient: Optional[Callable[[Var, Call, Var, "BlockBuilder"], List[Expr]]] = None,
level: int = 10,
):
"""Register operator gradient function for a relax operator.
@@ -136,7 +137,7 @@ def call_tir_with_grad(
args: Expr,
out_sinfo: Union[TensorStructInfo, List[TensorStructInfo]],
te_grad_name: str,
- te_grad_kwargs: Dict[str, Object] = None,
+ te_grad_kwargs: Optional[Dict[str, Object]] = None,
tir_vars: Optional[Union[ShapeExpr, Tuple[PrimExpr], List[PrimExpr]]] = None,
) -> Call:
"""
diff --git a/python/tvm/relax/op/manipulate.py b/python/tvm/relax/op/manipulate.py
index 358952e49c..cd15d844b7 100644
--- a/python/tvm/relax/op/manipulate.py
+++ b/python/tvm/relax/op/manipulate.py
@@ -534,11 +534,11 @@ def gather_nd(data: Expr, indices: Expr, batch_dims: int = 0) -> Expr:
def index_tensor(data: Expr, indices: Union[Expr, List[Expr]]) -> Expr:
- """Advanced‑tensor indexing (NumPy/PyTorch‐style).
+ """Advanced-tensor indexing (NumPy/PyTorch-style).
- Given k index tensors ``indices = (I0, I1, …, Ik‑1)`` this
+ Given k index tensors ``indices = (I0, I1, …, Ik-1)`` this
operator selects elements from ``data`` as if one had written
- ``data[I0, I1, …, Ik‑1]`` in NumPy/PyTorch:
+ ``data[I0, I1, …, Ik-1]`` in NumPy/PyTorch:
All index tensors must have an integer dtype.
@@ -549,9 +549,9 @@ def index_tensor(data: Expr, indices: Union[Expr, List[Expr]]) -> Expr:
shape followed by the remaining axes of ``data`` that are *not*
indexed).
- At compile‑time Relax checks that the number of index tensors
+ At compile-time Relax checks that the number of index tensors
``k`` does not exceed ``data.ndim``, that the dtypes are integer,
- and that the shapes are consitent (broadcast‑compatible).
+ and that the shapes are consitent (broadcast-compatible).
Parameters
----------
diff --git a/python/tvm/relax/op/nn/nn.py b/python/tvm/relax/op/nn/nn.py
index bd6f4aef87..f4c8340460 100644
--- a/python/tvm/relax/op/nn/nn.py
+++ b/python/tvm/relax/op/nn/nn.py
@@ -557,7 +557,7 @@ def pixel_shuffle(data: Expr, upscale_factor: int):
This operator performs the pixel shuffle operation on the input tensor,
which is often used for efficient sub-pixel convolution in image
super-resolution tasks. It rearranges elements in a tensor of shape
- (N, C × r^2, H, W) to a tensor of shape (N, C, H × r, W × r), where `r`
+ (N, C x r^2, H, W) to a tensor of shape (N, C, H x r, W x r), where `r`
is the upscale factor.
Parameters
diff --git a/python/tvm/relax/relax_to_pyfunc_converter.py b/python/tvm/relax/relax_to_pyfunc_converter.py
index 5a3f3eddbd..2905d6fb4b 100644
--- a/python/tvm/relax/relax_to_pyfunc_converter.py
+++ b/python/tvm/relax/relax_to_pyfunc_converter.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Relax to Python Function Converter.
This module provides functionality to convert Relax functions to Python functions
@@ -363,7 +364,7 @@ class RelaxExpressionConverter:
self,
operator_map: Dict[str, str],
ir_module: IRModule = None,
- op_cache: Dict[str, str] = None,
+ op_cache: Optional[Dict[str, str]] = None,
):
"""Initialize the expression converter.
@@ -859,7 +860,7 @@ class RelaxExpressionConverter:
# Handle different types of axis
if hasattr(axis, "__iter__") and not isinstance(axis, str):
# It's an array/list, take the first element
- axis = list(axis)[0] if len(axis) > 0 else None
+ axis = next(iter(axis)) if len(axis) > 0 else None
# Handle TVM types
if hasattr(axis, "value"):
diff --git a/python/tvm/relax/struct_info.py b/python/tvm/relax/struct_info.py
index d0e02c77d5..2f8ccc62e4 100644
--- a/python/tvm/relax/struct_info.py
+++ b/python/tvm/relax/struct_info.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-import
+# ruff: noqa: F401
"""The struct info nodes of the Relax language."""
from typing import List, Optional, Union
diff --git a/python/tvm/relax/testing/matmul.py b/python/tvm/relax/testing/matmul.py
index 37ce123a6c..63986d84ca 100644
--- a/python/tvm/relax/testing/matmul.py
+++ b/python/tvm/relax/testing/matmul.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""Utilities to construct matmul workloads."""
import tvm
diff --git a/python/tvm/relax/testing/nn.py b/python/tvm/relax/testing/nn.py
index 4080b368a0..755ba6c2b4 100644
--- a/python/tvm/relax/testing/nn.py
+++ b/python/tvm/relax/testing/nn.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=redefined-builtin, invalid-name
+# ruff: noqa: RUF005
"""PyTorch-like nn.Module API for constructing workloads."""
import typing
diff --git a/python/tvm/relax/training/loss.py b/python/tvm/relax/training/loss.py
index c2a1787c8a..1c315161cf 100644
--- a/python/tvm/relax/training/loss.py
+++ b/python/tvm/relax/training/loss.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=redefined-builtin, invalid-name
+# ruff: noqa: RUF012
"""Loss functions library for relax."""
from typing import Optional, Union
diff --git a/python/tvm/relax/training/optimizer.py b/python/tvm/relax/training/optimizer.py
index d041ac2054..cea95e1756 100644
--- a/python/tvm/relax/training/optimizer.py
+++ b/python/tvm/relax/training/optimizer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Provide abstraction for defining optimizers and a set of common optimizers."""
from decimal import Decimal
diff --git a/python/tvm/relax/training/utils.py b/python/tvm/relax/training/utils.py
index 2fea6d4af0..4ab620cf73 100644
--- a/python/tvm/relax/training/utils.py
+++ b/python/tvm/relax/training/utils.py
@@ -160,7 +160,7 @@ def AppendLoss(
)
-def register_te_gradient(te_grad_name: str, te_grad_func: Callable = None):
+def register_te_gradient(te_grad_name: str, te_grad_func: Optional[Callable] = None):
"""Register a te gradient function bind with name te_grad_name. te_grad_name can be referenced
later in call_tir_with_grad nodes.
diff --git a/python/tvm/relax/transform/lazy_transform_params.py b/python/tvm/relax/transform/lazy_transform_params.py
index 0ef01d3aca..b7540d3398 100644
--- a/python/tvm/relax/transform/lazy_transform_params.py
+++ b/python/tvm/relax/transform/lazy_transform_params.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-argument, missing-function-docstring, abstract-method, missing-class-docstring
+# ruff: noqa: RUF005
"""Relax LazyTransformParams pass."""
from typing import Optional
diff --git a/python/tvm/relax/transform/legalize_ops/ccl.py b/python/tvm/relax/transform/legalize_ops/ccl.py
index 71f7974712..c3d1dee3e3 100644
--- a/python/tvm/relax/transform/legalize_ops/ccl.py
+++ b/python/tvm/relax/transform/legalize_ops/ccl.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF005
"""Default legalization function for ccl operators."""
from tvm import arith, tir, topi
diff --git a/python/tvm/relax/transform/legalize_ops/create.py b/python/tvm/relax/transform/legalize_ops/create.py
index 5d091f2f2e..354b09b677 100644
--- a/python/tvm/relax/transform/legalize_ops/create.py
+++ b/python/tvm/relax/transform/legalize_ops/create.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E731
"""Default legalization function for creation operators."""
from typing import Optional
diff --git a/python/tvm/relax/transform/legalize_ops/manipulate.py b/python/tvm/relax/transform/legalize_ops/manipulate.py
index bb5c717844..d087fcf8c0 100644
--- a/python/tvm/relax/transform/legalize_ops/manipulate.py
+++ b/python/tvm/relax/transform/legalize_ops/manipulate.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF005
"""Default legalization function for manipulate operators."""
from typing import Optional
diff --git a/python/tvm/relax/transform/legalize_ops/nn.py b/python/tvm/relax/transform/legalize_ops/nn.py
index 117134176a..8c6a78933b 100644
--- a/python/tvm/relax/transform/legalize_ops/nn.py
+++ b/python/tvm/relax/transform/legalize_ops/nn.py
@@ -538,7 +538,7 @@ def _nn_selu(bb: BlockBuilder, call: Call) -> Expr:
scale = tir.const(1.0507009873554804934193349852946, dtype)
# Compute SELU
- # SELU(x) = scale∗(max(0,x)+min(0,α∗(exp(x)−1)))
+ # SELU(x) = scale*(max(0,x)+min(0,a*(exp(x)-1)))
positive_part = topi.maximum(x, tir.const(0, dtype))
negative_part = topi.minimum(
tir.const(0, dtype), alpha * (topi.exp(x) - tir.const(1, dtype))
diff --git a/python/tvm/relax/transform/transform.py b/python/tvm/relax/transform/transform.py
index 153b6aebdc..2b88c41a0d 100644
--- a/python/tvm/relax/transform/transform.py
+++ b/python/tvm/relax/transform/transform.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E731, E741, F401, F811
"""Relax transformation passes."""
import functools
@@ -1372,7 +1373,7 @@ def AlterOpImpl(
def ConvertLayout(
desired_layouts: Dict[str, List[str]],
- layout_cb: Callable = None,
+ layout_cb: Optional[Callable] = None,
) -> tvm.ir.transform.Pass:
"""Automatic layout conversion pass.
diff --git a/python/tvm/relax/ty.py b/python/tvm/relax/ty.py
index 37857c6ee2..d7b619bf8d 100644
--- a/python/tvm/relax/ty.py
+++ b/python/tvm/relax/ty.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-import
+# ruff: noqa: F401
"""The type nodes of the Relax language."""
import tvm_ffi
diff --git a/python/tvm/relax/utils.py b/python/tvm/relax/utils.py
index 5d728e2278..7126947091 100644
--- a/python/tvm/relax/utils.py
+++ b/python/tvm/relax/utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, RUF005
# pylint: disable=invalid-name,too-many-locals
diff --git a/python/tvm/relax/vm_build.py b/python/tvm/relax/vm_build.py
index 38e408f5ed..873b801c8d 100644
--- a/python/tvm/relax/vm_build.py
+++ b/python/tvm/relax/vm_build.py
@@ -109,7 +109,7 @@ def _vmlink(
target: Optional[Union[str, tvm.target.Target]],
tir_mod: Optional[tvm.IRModule] = None,
tir_pipeline: Optional[Union[str, tvm.transform.Pass]] = "default",
- ext_libs: List[tvm.runtime.Module] = None,
+ ext_libs: Optional[List[tvm.runtime.Module]] = None,
params: Optional[Dict[str, list]] = None,
*,
system_lib: Optional[bool] = None,
diff --git a/python/tvm/rpc/client.py b/python/tvm/rpc/client.py
index 4ab69eb644..15967db59f 100644
--- a/python/tvm/rpc/client.py
+++ b/python/tvm/rpc/client.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=used-before-assignment,broad-exception-caught
+# ruff: noqa: F401
"""RPC client tools"""
import os
@@ -351,7 +352,7 @@ class TrackerSession:
sorted_server = sorted(data["server_info"], key=lambda x: x["key"])
for item in sorted_server:
addr = item["addr"]
- res += "%21s " % ":".join(map(str, addr))
+ res += f"{':'.join(map(str, addr)):21s} "
res += item["key"] + "\n"
key = item["key"].split(":")[1] # 'server:rasp3b` -> 'rasp3b'
if key not in total_ct:
diff --git a/python/tvm/rpc/proxy.py b/python/tvm/rpc/proxy.py
index da855517e1..12a1542b77 100644
--- a/python/tvm/rpc/proxy.py
+++ b/python/tvm/rpc/proxy.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""RPC proxy, allows both client/server to connect and match connection.
In normal RPC, client directly connect to server's IP address.
diff --git a/python/tvm/rpc/server.py b/python/tvm/rpc/server.py
index c59b58a0c1..64381acf22 100644
--- a/python/tvm/rpc/server.py
+++ b/python/tvm/rpc/server.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""RPC server implementation.
Note
diff --git a/python/tvm/rpc/server_ios_launcher.py b/python/tvm/rpc/server_ios_launcher.py
index 9eb9af9626..e3cb957ebc 100644
--- a/python/tvm/rpc/server_ios_launcher.py
+++ b/python/tvm/rpc/server_ios_launcher.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""
Python wrapper for running a RPC Server through iOS RPC
on the iOS simulator using the simctl command line tool.
diff --git a/python/tvm/rpc/tornado_util.py b/python/tvm/rpc/tornado_util.py
index e1af5a3214..0a3ba5bb4f 100644
--- a/python/tvm/rpc/tornado_util.py
+++ b/python/tvm/rpc/tornado_util.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Utilities used in tornado."""
import errno
diff --git a/python/tvm/runtime/_tensor.py b/python/tvm/runtime/_tensor.py
index 1616f595a2..d5810094b5 100644
--- a/python/tvm/runtime/_tensor.py
+++ b/python/tvm/runtime/_tensor.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-import, redefined-outer-name
+# ruff: noqa: E722, F401, RUF005
"""Runtime Tensor API"""
import ctypes
diff --git a/python/tvm/runtime/disco/session.py b/python/tvm/runtime/disco/session.py
index dc28a54e35..6200608c63 100644
--- a/python/tvm/runtime/disco/session.py
+++ b/python/tvm/runtime/disco/session.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""This module defines a Session in Disco. Session is the primary interface that users interact
with the distributed runtime.
"""
diff --git a/python/tvm/runtime/module.py b/python/tvm/runtime/module.py
index 9abaecb9a0..09f48ad749 100644
--- a/python/tvm/runtime/module.py
+++ b/python/tvm/runtime/module.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
# pylint: disable=invalid-name, unused-import, import-outside-toplevel, inconsistent-return-statements
"""Runtime Module namespace."""
diff --git a/python/tvm/runtime/object_generic.py b/python/tvm/runtime/object_generic.py
index 72d2dacbae..51c8805f94 100644
--- a/python/tvm/runtime/object_generic.py
+++ b/python/tvm/runtime/object_generic.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Common implementation of object generic related logic"""
# pylint: disable=unused-import, invalid-name
diff --git a/python/tvm/runtime/vm.py b/python/tvm/runtime/vm.py
index d4d6651d05..eb22870989 100644
--- a/python/tvm/runtime/vm.py
+++ b/python/tvm/runtime/vm.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, redefined-builtin, no-else-return, consider-using-dict-items
+# ruff: noqa: RUF005
"""The Relax virtual machine."""
from enum import IntEnum
@@ -223,7 +224,7 @@ class VirtualMachine:
elif isinstance(arg, str):
cargs.append(arg)
else:
- raise TypeError("Unsupported type: %s" % (type(arg)))
+ raise TypeError(f"Unsupported type: {type(arg)}")
def _convert_func_named_args(self, func_name: str, args: Any, **kwargs: Any) -> Any:
"""
diff --git a/python/tvm/s_tir/dlight/adreno/layout_transform.py b/python/tvm/s_tir/dlight/adreno/layout_transform.py
index 6730ada1df..daf749eb79 100644
--- a/python/tvm/s_tir/dlight/adreno/layout_transform.py
+++ b/python/tvm/s_tir/dlight/adreno/layout_transform.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
# Licensed to the apache software foundation (asf) under one
# or more contributor license agreements. See the NOTICE file
diff --git a/python/tvm/s_tir/dlight/adreno/pool.py b/python/tvm/s_tir/dlight/adreno/pool.py
index 8dd3fdb14d..1805fce65d 100644
--- a/python/tvm/s_tir/dlight/adreno/pool.py
+++ b/python/tvm/s_tir/dlight/adreno/pool.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring
+# ruff: noqa: F841
"""Pool schedule rule for Adreno operators."""
from tvm import s_tir, tir
diff --git a/python/tvm/s_tir/dlight/adreno/utils.py b/python/tvm/s_tir/dlight/adreno/utils.py
index 6c8daa11f1..0e6bca34d7 100644
--- a/python/tvm/s_tir/dlight/adreno/utils.py
+++ b/python/tvm/s_tir/dlight/adreno/utils.py
@@ -17,7 +17,7 @@
"""Utilis for Adreno operators."""
# pylint: disable=import-outside-toplevel, unused-argument, invalid-name, missing-function-docstring
-from typing import List
+from typing import List, Optional
from tvm import s_tir
from tvm.target import Target
@@ -67,13 +67,15 @@ def get_texture_storage(block_info: SBlockInfo):
return "global"
-def schedule_inline_blocks(sch: s_tir.Schedule, blocks: List[s_tir.schedule.SBlockRV] = None):
+def schedule_inline_blocks(
+ sch: s_tir.Schedule, blocks: Optional[List[s_tir.schedule.SBlockRV]] = None
+):
from .fallback import Fallback
return Fallback.schedule_inline_blocks(sch, blocks)
-def schedule_default(sch, blocks: List[s_tir.schedule.SBlockRV] = None):
+def schedule_default(sch, blocks: Optional[List[s_tir.schedule.SBlockRV]] = None):
from .fallback import Fallback
ret = []
diff --git a/python/tvm/s_tir/dlight/analysis/common_analysis.py b/python/tvm/s_tir/dlight/analysis/common_analysis.py
index 88dfcb693a..2ec12b26c0 100644
--- a/python/tvm/s_tir/dlight/analysis/common_analysis.py
+++ b/python/tvm/s_tir/dlight/analysis/common_analysis.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
# pylint: disable=missing-function-docstring, missing-class-docstring
# pylint: disable=unused-argument, unused-variable
diff --git a/python/tvm/s_tir/dlight/base/common_schedules.py b/python/tvm/s_tir/dlight/base/common_schedules.py
index 1bde675d36..43a856c3ba 100644
--- a/python/tvm/s_tir/dlight/base/common_schedules.py
+++ b/python/tvm/s_tir/dlight/base/common_schedules.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""Common schedule strategies for TIR."""
from typing import Callable, List
diff --git a/python/tvm/s_tir/dlight/gpu/gemv.py b/python/tvm/s_tir/dlight/gpu/gemv.py
index b2dd3c57b9..80df2435c8 100644
--- a/python/tvm/s_tir/dlight/gpu/gemv.py
+++ b/python/tvm/s_tir/dlight/gpu/gemv.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741, F821
"""A rule for GEMV and DecodeGEMV."""
from functools import reduce
diff --git a/python/tvm/s_tir/dlight/gpu/low_batch_gemv.py b/python/tvm/s_tir/dlight/gpu/low_batch_gemv.py
index ba094af092..23b2e3266b 100644
--- a/python/tvm/s_tir/dlight/gpu/low_batch_gemv.py
+++ b/python/tvm/s_tir/dlight/gpu/low_batch_gemv.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741, F821
"""A rule for low-batch GEMM / decode-GEMM using GEMV schedule."""
from functools import reduce
@@ -88,11 +89,11 @@ def is_gemv(sch: s_tir.Schedule, block_info: SBlockInfo) -> Optional[List[tir.Bu
)
if len(block_stmt.iter_vars) - len(const_iter_vars) != 1:
return None
- symbolic_iter_var = list(
+ symbolic_iter_var = next(
iter_var
for iter_var in block_stmt.iter_vars
if not isinstance(iter_var.dom.extent, tir.IntImm)
- )[0]
+ )
if symbolic_iter_var.iter_type != tir.stmt.IterVar.DataPar:
return None
ret = [
diff --git a/python/tvm/s_tir/dlight/gpu/matmul.py b/python/tvm/s_tir/dlight/gpu/matmul.py
index b187e1d383..c42072039e 100644
--- a/python/tvm/s_tir/dlight/gpu/matmul.py
+++ b/python/tvm/s_tir/dlight/gpu/matmul.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring, invalid-name
+# ruff: noqa: E722
"""A GEMM schedule rule for GPU operators."""
from dataclasses import dataclass
diff --git a/python/tvm/s_tir/meta_schedule/builder/builder.py b/python/tvm/s_tir/meta_schedule/builder/builder.py
index f2803e8b68..595ac1de1d 100644
--- a/python/tvm/s_tir/meta_schedule/builder/builder.py
+++ b/python/tvm/s_tir/meta_schedule/builder/builder.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Meta Schedule builders that translate IRModule to runtime.Module, and then export"""
from typing import Callable, Dict, List, Optional, Union
@@ -167,7 +168,7 @@ class _PyBuilder(Builder):
See also: PyBuilder
"""
- def __init__(self, f_build: Callable = None):
+ def __init__(self, f_build: Optional[Callable] = None):
"""Constructor."""
self.__init_handle_by_constructor__(
diff --git a/python/tvm/s_tir/meta_schedule/builder/local_builder.py b/python/tvm/s_tir/meta_schedule/builder/local_builder.py
index 7ce342fdb1..df447763e2 100644
--- a/python/tvm/s_tir/meta_schedule/builder/local_builder.py
+++ b/python/tvm/s_tir/meta_schedule/builder/local_builder.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Local builder that compile on the local host"""
import os
diff --git a/python/tvm/s_tir/meta_schedule/cost_model/cost_model.py b/python/tvm/s_tir/meta_schedule/cost_model/cost_model.py
index 1dbf5c81c0..0927fd961e 100644
--- a/python/tvm/s_tir/meta_schedule/cost_model/cost_model.py
+++ b/python/tvm/s_tir/meta_schedule/cost_model/cost_model.py
@@ -14,10 +14,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Meta Schedule CostModel."""
import ctypes
-from typing import Callable, List, Union
+from typing import Callable, List, Optional, Union
# isort: off
from typing_extensions import Literal
@@ -163,11 +164,11 @@ class _PyCostModel(CostModel):
def __init__(
self,
- f_load: Callable = None,
- f_save: Callable = None,
- f_update: Callable = None,
- predict_func: Callable = None,
- f_as_string: Callable = None,
+ f_load: Optional[Callable] = None,
+ f_save: Optional[Callable] = None,
+ f_update: Optional[Callable] = None,
+ predict_func: Optional[Callable] = None,
+ f_as_string: Optional[Callable] = None,
):
"""Constructor."""
diff --git a/python/tvm/s_tir/meta_schedule/cost_model/mlp_model.py b/python/tvm/s_tir/meta_schedule/cost_model/mlp_model.py
index f0d83b4901..c9aa71fde9 100644
--- a/python/tvm/s_tir/meta_schedule/cost_model/mlp_model.py
+++ b/python/tvm/s_tir/meta_schedule/cost_model/mlp_model.py
@@ -252,7 +252,7 @@ class SegmentDataLoader:
def lambda_rank_loss( # pylint: disable=too-many-locals
preds: "torch.Tensor",
labels: "torch.Tensor",
- k: int = None,
+ k: Optional[int] = None,
eps: float = 1e-10,
sigma: float = 1.0,
) -> "torch.Tensor":
diff --git a/python/tvm/s_tir/meta_schedule/cost_model/xgb_model.py b/python/tvm/s_tir/meta_schedule/cost_model/xgb_model.py
index 7ca404428e..c85c873663 100644
--- a/python/tvm/s_tir/meta_schedule/cost_model/xgb_model.py
+++ b/python/tvm/s_tir/meta_schedule/cost_model/xgb_model.py
@@ -675,7 +675,7 @@ def _get_custom_call_back(
fevals: List[Callable],
evals: List[Tuple["xgb.DMatrix", str]],
focused_metric: str = "tr-p-rmse",
- cvfolds: List["xgb.training.CVPack"] = None,
+ cvfolds: Optional[List["xgb.training.CVPack"]] = None,
) -> "TrainingCallback":
"""Get a customized callback function for XGBoost. Work around xgboost import."""
@@ -706,7 +706,7 @@ def _get_custom_call_back(
fevals: List[Callable],
evals: List[Tuple["xgb.DMatrix", str]],
focused_metric: str = "tr-p-rmse",
- cvfolds: List["xgb.training.CVPack"] = None,
+ cvfolds: Optional[List["xgb.training.CVPack"]] = None,
):
self.early_stopping_rounds = early_stopping_rounds
self.verbose_eval = verbose_eval
diff --git a/python/tvm/s_tir/meta_schedule/database/database.py b/python/tvm/s_tir/meta_schedule/database/database.py
index dafe5a83c9..3d9d6b1b0f 100644
--- a/python/tvm/s_tir/meta_schedule/database/database.py
+++ b/python/tvm/s_tir/meta_schedule/database/database.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""TuningRecord database"""
from typing import Any, Callable, List, Optional, Union
@@ -440,15 +441,15 @@ class _PyDatabase(Database):
def __init__(
self,
- f_has_workload: Callable = None,
- f_commit_workload: Callable = None,
- f_commit_tuning_record: Callable = None,
- f_get_top_k: Callable = None,
- f_get_all_tuning_records: Callable = None,
- f_query_tuning_record: Callable = None,
- f_query_schedule: Callable = None,
- f_query_ir_module: Callable = None,
- f_size: Callable = None,
+ f_has_workload: Optional[Callable] = None,
+ f_commit_workload: Optional[Callable] = None,
+ f_commit_tuning_record: Optional[Callable] = None,
+ f_get_top_k: Optional[Callable] = None,
+ f_get_all_tuning_records: Optional[Callable] = None,
+ f_query_tuning_record: Optional[Callable] = None,
+ f_query_schedule: Optional[Callable] = None,
+ f_query_ir_module: Optional[Callable] = None,
+ f_size: Optional[Callable] = None,
module_equality: str = "structural",
):
"""Constructor."""
diff --git a/python/tvm/s_tir/meta_schedule/feature_extractor/feature_extractor.py b/python/tvm/s_tir/meta_schedule/feature_extractor/feature_extractor.py
index e976b1a506..bab0588f78 100644
--- a/python/tvm/s_tir/meta_schedule/feature_extractor/feature_extractor.py
+++ b/python/tvm/s_tir/meta_schedule/feature_extractor/feature_extractor.py
@@ -14,9 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Meta Schedule FeatureExtractor."""
-from typing import Callable, List, Union
+from typing import Callable, List, Optional, Union
# isort: off
from typing_extensions import Literal
@@ -85,7 +86,7 @@ class _PyFeatureExtractor(FeatureExtractor):
See also: PyFeatureExtractor
"""
- def __init__(self, f_extract_from: Callable, f_as_string: Callable = None):
+ def __init__(self, f_extract_from: Callable, f_as_string: Optional[Callable] = None):
"""Constructor."""
self.__init_handle_by_constructor__(
diff --git a/python/tvm/s_tir/meta_schedule/measure_callback/measure_callback.py b/python/tvm/s_tir/meta_schedule/measure_callback/measure_callback.py
index 7478fb8e05..045d17c230 100644
--- a/python/tvm/s_tir/meta_schedule/measure_callback/measure_callback.py
+++ b/python/tvm/s_tir/meta_schedule/measure_callback/measure_callback.py
@@ -14,9 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Meta Schedule MeasureCallback."""
-from typing import TYPE_CHECKING, Callable, List, Union
+from typing import TYPE_CHECKING, Callable, List, Optional, Union
# isort: off
from typing_extensions import Literal
@@ -92,7 +93,7 @@ class _PyMeasureCallback(MeasureCallback):
See also: PyMeasureCallback
"""
- def __init__(self, f_apply: Callable, f_as_string: Callable = None):
+ def __init__(self, f_apply: Callable, f_as_string: Optional[Callable] = None):
"""Constructor."""
self.__init_handle_by_constructor__(
diff --git a/python/tvm/s_tir/meta_schedule/mutator/mutator.py b/python/tvm/s_tir/meta_schedule/mutator/mutator.py
index e684fb3143..0dcfda80a1 100644
--- a/python/tvm/s_tir/meta_schedule/mutator/mutator.py
+++ b/python/tvm/s_tir/meta_schedule/mutator/mutator.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Meta Schedule Mutator."""
from typing import TYPE_CHECKING, Callable, Dict, Optional
@@ -124,10 +125,10 @@ class _PyMutator(Mutator):
def __init__(
self,
- f_initialize_with_tune_context: Callable = None,
- f_apply: Callable = None,
- f_clone: Callable = None,
- f_as_string: Callable = None,
+ f_initialize_with_tune_context: Optional[Callable] = None,
+ f_apply: Optional[Callable] = None,
+ f_clone: Optional[Callable] = None,
+ f_as_string: Optional[Callable] = None,
):
"""Constructor."""
diff --git a/python/tvm/s_tir/meta_schedule/postproc/postproc.py b/python/tvm/s_tir/meta_schedule/postproc/postproc.py
index e815826e50..c78fdd5e4b 100644
--- a/python/tvm/s_tir/meta_schedule/postproc/postproc.py
+++ b/python/tvm/s_tir/meta_schedule/postproc/postproc.py
@@ -14,9 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Meta Schedule Postproc."""
-from typing import TYPE_CHECKING, Callable, List
+from typing import TYPE_CHECKING, Callable, List, Optional
# isort: off
from typing_extensions import Literal
@@ -118,10 +119,10 @@ class _PyPostproc(Postproc):
def __init__(
self,
- f_initialize_with_tune_context: Callable = None,
- f_apply: Callable = None,
- f_clone: Callable = None,
- f_as_string: Callable = None,
+ f_initialize_with_tune_context: Optional[Callable] = None,
+ f_apply: Optional[Callable] = None,
+ f_clone: Optional[Callable] = None,
+ f_as_string: Optional[Callable] = None,
):
"""Constructor."""
diff --git a/python/tvm/s_tir/meta_schedule/runner/runner.py b/python/tvm/s_tir/meta_schedule/runner/runner.py
index ad51464a1c..7680143871 100644
--- a/python/tvm/s_tir/meta_schedule/runner/runner.py
+++ b/python/tvm/s_tir/meta_schedule/runner/runner.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Runners"""
from typing import Callable, List, Optional, Union
@@ -120,7 +121,7 @@ class RunnerFuture(Object):
See also: PyRunnerFuture
"""
- def __init__(self, f_done: Callable, f_result: Callable = None) -> None:
+ def __init__(self, f_done: Callable, f_result: Optional[Callable] = None) -> None:
"""Constructor"""
self.__init_handle_by_constructor__(
@@ -216,7 +217,7 @@ class _PyRunner(Runner):
See also: PyRunner
"""
- def __init__(self, f_run: Callable = None) -> None:
+ def __init__(self, f_run: Optional[Callable] = None) -> None:
"""Constructor"""
self.__init_handle_by_constructor__(
diff --git a/python/tvm/s_tir/meta_schedule/schedule/cuda/layout_transform.py b/python/tvm/s_tir/meta_schedule/schedule/cuda/layout_transform.py
index 23eddc10de..1b0c39e821 100644
--- a/python/tvm/s_tir/meta_schedule/schedule/cuda/layout_transform.py
+++ b/python/tvm/s_tir/meta_schedule/schedule/cuda/layout_transform.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""layout_transform scheduling rule for CUDA."""
import math
diff --git a/python/tvm/s_tir/meta_schedule/schedule_rule/schedule_rule.py b/python/tvm/s_tir/meta_schedule/schedule_rule/schedule_rule.py
index 33e4211a13..923e6d7f56 100644
--- a/python/tvm/s_tir/meta_schedule/schedule_rule/schedule_rule.py
+++ b/python/tvm/s_tir/meta_schedule/schedule_rule/schedule_rule.py
@@ -14,12 +14,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""
Meta Schedule schedule rules are used for modification of
blocks in a schedule. See also PostOrderApply.
"""
-from typing import TYPE_CHECKING, Callable, List
+from typing import TYPE_CHECKING, Callable, List, Optional
# isort: off
from typing_extensions import Literal
@@ -125,10 +126,10 @@ class _PyScheduleRule(ScheduleRule):
def __init__(
self,
- f_initialize_with_tune_context: Callable = None,
- f_apply: Callable = None,
- f_clone: Callable = None,
- f_as_string: Callable = None,
+ f_initialize_with_tune_context: Optional[Callable] = None,
+ f_apply: Optional[Callable] = None,
+ f_clone: Optional[Callable] = None,
+ f_as_string: Optional[Callable] = None,
):
"""Constructor."""
diff --git a/python/tvm/s_tir/meta_schedule/search_strategy/search_strategy.py b/python/tvm/s_tir/meta_schedule/search_strategy/search_strategy.py
index 530802881a..b82feffbc4 100644
--- a/python/tvm/s_tir/meta_schedule/search_strategy/search_strategy.py
+++ b/python/tvm/s_tir/meta_schedule/search_strategy/search_strategy.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""
Meta Schedule search strategy that generates the measure
candidates for measurement.
@@ -232,12 +233,12 @@ class _PySearchStrategy(SearchStrategy):
def __init__(
self,
- f_initialize_with_tune_context: Callable = None,
- f_pre_tuning: Callable = None,
- f_post_tuning: Callable = None,
- f_generate_measure_candidates: Callable = None,
- f_notify_runner_results: Callable = None,
- f_clone: Callable = None,
+ f_initialize_with_tune_context: Optional[Callable] = None,
+ f_pre_tuning: Optional[Callable] = None,
+ f_post_tuning: Optional[Callable] = None,
+ f_generate_measure_candidates: Optional[Callable] = None,
+ f_notify_runner_results: Optional[Callable] = None,
+ f_clone: Optional[Callable] = None,
):
"""Constructor."""
diff --git a/python/tvm/s_tir/meta_schedule/space_generator/space_generator.py b/python/tvm/s_tir/meta_schedule/space_generator/space_generator.py
index 341072dfec..ceee06cd00 100644
--- a/python/tvm/s_tir/meta_schedule/space_generator/space_generator.py
+++ b/python/tvm/s_tir/meta_schedule/space_generator/space_generator.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""
Meta Schedule design space generators that generates design
space for generation of measure candidates.
diff --git a/python/tvm/s_tir/meta_schedule/task_scheduler/task_scheduler.py b/python/tvm/s_tir/meta_schedule/task_scheduler/task_scheduler.py
index 2bad38aa8f..7e32a50bbf 100644
--- a/python/tvm/s_tir/meta_schedule/task_scheduler/task_scheduler.py
+++ b/python/tvm/s_tir/meta_schedule/task_scheduler/task_scheduler.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Auto-tuning Task Scheduler"""
from typing import Callable, List, Optional, Union
diff --git a/python/tvm/s_tir/meta_schedule/testing/te_workload.py b/python/tvm/s_tir/meta_schedule/testing/te_workload.py
index 970d425d01..8db117f264 100644
--- a/python/tvm/s_tir/meta_schedule/testing/te_workload.py
+++ b/python/tvm/s_tir/meta_schedule/testing/te_workload.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""Workloads in TE"""
# pylint: disable=missing-docstring
diff --git a/python/tvm/s_tir/meta_schedule/testing/tune_te.py b/python/tvm/s_tir/meta_schedule/testing/tune_te.py
index 5d7cc91892..4b6caf189f 100644
--- a/python/tvm/s_tir/meta_schedule/testing/tune_te.py
+++ b/python/tvm/s_tir/meta_schedule/testing/tune_te.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring
+# ruff: noqa: F821
import argparse
import logging
from typing import Optional
diff --git a/python/tvm/s_tir/meta_schedule/testing/validate_database.py b/python/tvm/s_tir/meta_schedule/testing/validate_database.py
index e3779bbf83..a948351352 100644
--- a/python/tvm/s_tir/meta_schedule/testing/validate_database.py
+++ b/python/tvm/s_tir/meta_schedule/testing/validate_database.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F403
"""JSON Database validation script"""
import argparse
@@ -21,7 +22,7 @@ import itertools
import logging
import warnings
from statistics import mean
-from typing import Any, Callable, List, Tuple, Union
+from typing import Any, Callable, List, Optional, Tuple, Union
import numpy as np # type: ignore
from tvm_ffi import get_global_func, register_global_func
@@ -327,13 +328,13 @@ def print_with_counter_func(counter: int, total: int) -> Callable:
*,
original_mod: IRModule = None,
scheduled_mod: IRModule = None,
- inputs: List[np.ndarray] = None,
- original_res: List[np.ndarray] = None,
- scheduled_res: List[np.ndarray] = None,
- original_run_secs: List[float] = None,
- scheduled_run_secs: List[float] = None,
- exception: Exception = None,
- trace: str = None,
+ inputs: Optional[List[np.ndarray]] = None,
+ original_res: Optional[List[np.ndarray]] = None,
+ scheduled_res: Optional[List[np.ndarray]] = None,
+ original_run_secs: Optional[List[float]] = None,
+ scheduled_run_secs: Optional[List[float]] = None,
+ exception: Optional[Exception] = None,
+ trace: Optional[str] = None,
) -> None:
"""Print the validation result."""
status = f"Progress {counter: 6d} / {total: 6d} (estimated) checked, result: {result:>10}, "
diff --git a/python/tvm/s_tir/meta_schedule/tune_context.py b/python/tvm/s_tir/meta_schedule/tune_context.py
index 8c13ae7906..81f2ada1be 100644
--- a/python/tvm/s_tir/meta_schedule/tune_context.py
+++ b/python/tvm/s_tir/meta_schedule/tune_context.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Meta Schedule tuning context."""
from typing import TYPE_CHECKING, List, Optional, Union
diff --git a/python/tvm/s_tir/tensor_intrin/arm_cpu.py b/python/tvm/s_tir/tensor_intrin/arm_cpu.py
index 7e036d1ad4..15c1eed0df 100644
--- a/python/tvm/s_tir/tensor_intrin/arm_cpu.py
+++ b/python/tvm/s_tir/tensor_intrin/arm_cpu.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name,missing-function-docstring,unused-import
+# ruff: noqa: E501, F401
"""Intrinsics for ARM tensorization."""
from tvm import tir
diff --git a/python/tvm/s_tir/tensor_intrin/cuda.py b/python/tvm/s_tir/tensor_intrin/cuda.py
index cb18a163b4..ddbabcc4ce 100644
--- a/python/tvm/s_tir/tensor_intrin/cuda.py
+++ b/python/tvm/s_tir/tensor_intrin/cuda.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name,missing-function-docstring,unused-variable
+# ruff: noqa: E731
"""Intrinsics for tensorization on NVIDIA GPU."""
from typing import Dict, Literal, Optional, Tuple
diff --git a/python/tvm/s_tir/tensor_intrin/riscv_cpu.py b/python/tvm/s_tir/tensor_intrin/riscv_cpu.py
index f63719aa01..01389875b0 100644
--- a/python/tvm/s_tir/tensor_intrin/riscv_cpu.py
+++ b/python/tvm/s_tir/tensor_intrin/riscv_cpu.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name,line-too-long
+# ruff: noqa: E501
"""Intrinsics for RISCV tensorization"""
import logging
diff --git a/python/tvm/script/highlight.py b/python/tvm/script/highlight.py
index 5de972a3ce..37731ca889 100644
--- a/python/tvm/script/highlight.py
+++ b/python/tvm/script/highlight.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821, RUF012
"""Highlight printed TVM script."""
import functools
diff --git a/python/tvm/script/ir_builder/ir/ir.py b/python/tvm/script/ir_builder/ir/ir.py
index aaadb280bb..995201971b 100644
--- a/python/tvm/script/ir_builder/ir/ir.py
+++ b/python/tvm/script/ir_builder/ir/ir.py
@@ -180,7 +180,7 @@ def vdevice(target=None, vdevice_id: int = 0, memory_scope: str = "global") -> V
return VDevice(target, vdevice_id, memory_scope) # type: ignore[attr-defined] # pylint: disable=no-member
-def lookup_vdevice(target_kind: str = None, device_index: int = -1) -> VDevice:
+def lookup_vdevice(target_kind: Optional[str] = None, device_index: int = -1) -> VDevice:
"""Retrieve a virtual device from the globalinfo vdevice list.
Parameters
----------
diff --git a/python/tvm/script/ir_builder/relax/distributed/ir.py b/python/tvm/script/ir_builder/relax/distributed/ir.py
index b11b5588fd..b7d1a01570 100644
--- a/python/tvm/script/ir_builder/relax/distributed/ir.py
+++ b/python/tvm/script/ir_builder/relax/distributed/ir.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=redefined-builtin, wrong-import-order, no-member, invalid-name, unused-import
+# ruff: noqa: F401
"""IRBuilder for distributed Relax dialect"""
diff --git a/python/tvm/script/ir_builder/tir/external_kernel.py b/python/tvm/script/ir_builder/tir/external_kernel.py
index bc6ca834c0..b5fe0b6537 100644
--- a/python/tvm/script/ir_builder/tir/external_kernel.py
+++ b/python/tvm/script/ir_builder/tir/external_kernel.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""External kernel integration fro TIR"""
import json
diff --git a/python/tvm/script/ir_builder/tir/ir.py b/python/tvm/script/ir_builder/tir/ir.py
index 2771abbe56..a3b521f955 100644
--- a/python/tvm/script/ir_builder/tir/ir.py
+++ b/python/tvm/script/ir_builder/tir/ir.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""IRBuilder for TIR"""
import contextlib
@@ -119,13 +120,13 @@ def buffer(
shape: Union[List[PrimExpr], Tuple[PrimExpr], PrimExpr, Integral],
dtype: str = "float32",
data: Var = None,
- strides: List[PrimExpr] = None,
+ strides: Optional[List[PrimExpr]] = None,
elem_offset: PrimExpr = None,
scope: str = "global",
align: int = 0,
offset_factor: int = 0,
buffer_type: str = "",
- axis_separators: List[int] = None,
+ axis_separators: Optional[List[int]] = None,
) -> Buffer:
"""The buffer declaration function.
@@ -271,13 +272,13 @@ def match_buffer(
shape: Union[List[PrimExpr], Tuple[PrimExpr], PrimExpr, Integral] = None,
dtype: str = "float32",
data: Var = None,
- strides: List[PrimExpr] = None,
+ strides: Optional[List[PrimExpr]] = None,
elem_offset: PrimExpr = None,
scope: str = "global",
align: int = -1,
offset_factor: int = 0,
buffer_type: str = "default",
- axis_separators: List[int] = None,
+ axis_separators: Optional[List[int]] = None,
) -> Buffer:
"""The buffer match function.
@@ -470,13 +471,13 @@ def alloc_buffer(
shape: Union[List[PrimExpr], Tuple[PrimExpr], PrimExpr, Integral],
dtype: str = "float32",
data: Var = None,
- strides: List[PrimExpr] = None,
+ strides: Optional[List[PrimExpr]] = None,
elem_offset: PrimExpr = None,
scope: str = "global",
align: int = -1,
offset_factor: int = 0,
buffer_type: str = "default",
- axis_separators: List[int] = None,
+ axis_separators: Optional[List[int]] = None,
) -> Buffer:
"""The buffer alllocation function.
@@ -711,7 +712,7 @@ def serial(
start: PrimExpr,
stop: PrimExpr = None,
*,
- annotations: Dict[str, Any] = None,
+ annotations: Optional[Dict[str, Any]] = None,
step: Optional[PrimExpr] = None,
) -> frame.ForFrame:
"""The serial For statement.
@@ -748,7 +749,7 @@ def parallel(
start: PrimExpr,
stop: PrimExpr = None,
*,
- annotations: Dict[str, Any] = None,
+ annotations: Optional[Dict[str, Any]] = None,
step: Optional[PrimExpr] = None,
) -> frame.ForFrame:
"""The parallel For statement.
@@ -785,7 +786,7 @@ def vectorized(
start: PrimExpr,
stop: PrimExpr = None,
*,
- annotations: Dict[str, Any] = None,
+ annotations: Optional[Dict[str, Any]] = None,
step: Optional[PrimExpr] = None,
) -> frame.ForFrame:
"""The vectorized For statement.
@@ -822,7 +823,7 @@ def unroll(
start: PrimExpr,
stop: PrimExpr = None,
*,
- annotations: Dict[str, Any] = None,
+ annotations: Optional[Dict[str, Any]] = None,
step: Optional[PrimExpr] = None,
) -> frame.ForFrame:
"""The unrolled For statement.
@@ -858,9 +859,9 @@ def unroll(
def thread_binding(
start: PrimExpr,
stop: PrimExpr = None,
- thread: str = None,
+ thread: Optional[str] = None,
*,
- annotations: Dict[str, Any] = None,
+ annotations: Optional[Dict[str, Any]] = None,
) -> frame.ForFrame:
"""The thread-binding For statement.
@@ -977,7 +978,7 @@ def Let( # pylint: disable=invalid-name
) -> PrimExpr:
"""Create a Let expression binding"""
assert len(where) == 1, "T.Let only allows `where` to have exactly one element"
- var, value = list(where.items())[0] # pylint: disable=redefined-outer-name
+ var, value = next(iter(where.items())) # pylint: disable=redefined-outer-name
return tir.Let(var, value, expr)
diff --git a/python/tvm/script/ir_builder/tir/triton.py b/python/tvm/script/ir_builder/tir/triton.py
index 1b54526e24..386f5fe90e 100644
--- a/python/tvm/script/ir_builder/tir/triton.py
+++ b/python/tvm/script/ir_builder/tir/triton.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""Triton kernel integration with TIR"""
from typing import Any, Dict, List, Tuple, Union
diff --git a/python/tvm/script/parser/_core.py b/python/tvm/script/parser/_core.py
index 76d485aef6..b1d29d0623 100644
--- a/python/tvm/script/parser/_core.py
+++ b/python/tvm/script/parser/_core.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the Licens.
+# ruff: noqa: F401
"""The core parser infra"""
# pylint: disable=unused-import
diff --git a/python/tvm/script/parser/core/diagnostics.py b/python/tvm/script/parser/core/diagnostics.py
index 4df2d193fe..7d2b5cb668 100644
--- a/python/tvm/script/parser/core/diagnostics.py
+++ b/python/tvm/script/parser/core/diagnostics.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""TVM Script Parser Source and diagnostics"""
import inspect
diff --git a/python/tvm/script/parser/core/doc.py b/python/tvm/script/parser/core/doc.py
index 74174f0667..9a0680395c 100644
--- a/python/tvm/script/parser/core/doc.py
+++ b/python/tvm/script/parser/core/doc.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722, F403
"""TVM Script Parser doc AST"""
import ast
diff --git a/python/tvm/script/parser/core/doc_core.py b/python/tvm/script/parser/core/doc_core.py
index a4966d4dc4..aa05629d5c 100644
--- a/python/tvm/script/parser/core/doc_core.py
+++ b/python/tvm/script/parser/core/doc_core.py
@@ -17,6 +17,7 @@
# pylint: disable=redefined-outer-name,missing-docstring,invalid-name
# pylint: disable=useless-super-delegation,redefined-builtin
# pylint: disable=too-few-public-methods,too-many-arguments
+# ruff: noqa: RUF012
# minimal python version is 3.9
diff --git a/python/tvm/script/parser/core/entry.py b/python/tvm/script/parser/core/entry.py
index 6b4fca115f..c25db1e5c1 100644
--- a/python/tvm/script/parser/core/entry.py
+++ b/python/tvm/script/parser/core/entry.py
@@ -17,7 +17,7 @@
"""The entry point of TVM parser."""
import inspect
-from typing import Any, Dict, Union
+from typing import Any, Dict, Optional, Union
import tvm
@@ -56,7 +56,7 @@ def _default_globals() -> Dict[str, Any]:
return extra_vars
-def scan_macro(program: Union[Any, str], extra_vars: Dict[str, Any] = None) -> Any:
+def scan_macro(program: Union[Any, str], extra_vars: Optional[Dict[str, Any]] = None) -> Any:
"""Generate the AST, and the source code for __repr__."""
# The AST will be converted into TIR at the time of expansion.
source = Source(program)
@@ -66,7 +66,7 @@ def scan_macro(program: Union[Any, str], extra_vars: Dict[str, Any] = None) -> A
def parse(
program: Union[doc.AST, Any, str],
- extra_vars: Dict[str, Any] = None,
+ extra_vars: Optional[Dict[str, Any]] = None,
check_well_formed: bool = True,
) -> Any:
"""Register a method for a operand type, AST operator node and operand index.
diff --git a/python/tvm/script/parser/relax/__init__.py b/python/tvm/script/parser/relax/__init__.py
index ced5da1ace..ddac5342ee 100644
--- a/python/tvm/script/parser/relax/__init__.py
+++ b/python/tvm/script/parser/relax/__init__.py
@@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""Initial impl of relax parser for sugars"""
from typing import TYPE_CHECKING
diff --git a/python/tvm/script/parser/relax/dist.py b/python/tvm/script/parser/relax/dist.py
index 941f282f39..d4848eb80d 100644
--- a/python/tvm/script/parser/relax/dist.py
+++ b/python/tvm/script/parser/relax/dist.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=redefined-builtin,missing-docstring, invalid-name, unused-import, redefined-outer-name
+# ruff: noqa: F401
from typing import Any, Dict, List, Optional, Set, Union
diff --git a/python/tvm/script/parser/tir/__init__.py b/python/tvm/script/parser/tir/__init__.py
index fa0b7d8f55..559998970f 100644
--- a/python/tvm/script/parser/tir/__init__.py
+++ b/python/tvm/script/parser/tir/__init__.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""The tir parser"""
from typing import TYPE_CHECKING
diff --git a/python/tvm/script/parser/tir/parser.py b/python/tvm/script/parser/tir/parser.py
index 6e4ee1bc29..2d98111949 100644
--- a/python/tvm/script/parser/tir/parser.py
+++ b/python/tvm/script/parser/tir/parser.py
@@ -173,7 +173,7 @@ def range_sugar(
stop: PrimExpr = None,
step: Optional[PrimExpr] = None,
*,
- annotations: Dict[str, Any] = None,
+ annotations: Optional[Dict[str, Any]] = None,
) -> T.frame.ForFrame:
"""The sugar for python range builtin."""
diff --git a/python/tvm/script/relax.py b/python/tvm/script/relax.py
index 0a8e338e8e..5afeb12449 100644
--- a/python/tvm/script/relax.py
+++ b/python/tvm/script/relax.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F403
"""TVM Script APIs of TVM Python Package for Relax"""
from .parser.relax import * # pylint: disable=redefined-builtin,unused-wildcard-import,wildcard-import
diff --git a/python/tvm/script/tir.py b/python/tvm/script/tir.py
index 7df5529a5b..8c4057e6ac 100644
--- a/python/tvm/script/tir.py
+++ b/python/tvm/script/tir.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F403
"""TVM Script APIs of TVM Python Package for TIR"""
from .parser.tir import * # pylint: disable=redefined-builtin,unused-wildcard-import,wildcard-import
diff --git a/python/tvm/target/datatype.py b/python/tvm/target/datatype.py
index 6807550cf0..3715aaf070 100644
--- a/python/tvm/target/datatype.py
+++ b/python/tvm/target/datatype.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""Bring Your Own Datatypes custom datatype framework
TODO(@gussmith23 @hypercubestart) link to BYODT docs when they exist"""
diff --git a/python/tvm/target/intrin.py b/python/tvm/target/intrin.py
index 7e100b1cbe..a79f13acc4 100644
--- a/python/tvm/target/intrin.py
+++ b/python/tvm/target/intrin.py
@@ -45,7 +45,7 @@ def _rule_float_suffix(op):
prefix = name[4:]
if op.dtype == "float32":
- return call_pure_extern(op.dtype, "%sf" % prefix, *op.args)
+ return call_pure_extern(op.dtype, f"{prefix}f", *op.args)
if op.dtype == "float64":
return call_pure_extern(op.dtype, prefix, *op.args)
return op
diff --git a/python/tvm/target/virtual_device.py b/python/tvm/target/virtual_device.py
index e509c56707..37b888196b 100644
--- a/python/tvm/target/virtual_device.py
+++ b/python/tvm/target/virtual_device.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""Python bindings for creating VirtualDevices."""
import tvm_ffi
diff --git a/python/tvm/te/operation.py b/python/tvm/te/operation.py
index a06ee0845e..e1823c3176 100644
--- a/python/tvm/te/operation.py
+++ b/python/tvm/te/operation.py
@@ -291,15 +291,13 @@ def extern(
in_buffers = [in_buffers] if not isinstance(in_buffers, list) else in_buffers
if len(inputs) != len(in_buffers):
raise RuntimeError(
- "Number of inputs and in_buffers mismatch: %d vs %d."
- % (len(inputs), len(in_buffers))
+ f"Number of inputs and in_buffers mismatch: {len(inputs)} vs {len(in_buffers)}."
)
if out_buffers is not None:
out_buffers = [out_buffers] if not isinstance(out_buffers, list) else out_buffers
if len(shape) != len(out_buffers):
raise RuntimeError(
- "Number of outputs and out_buffers mismatch: %d vs %d."
- % (len(shape), len(out_buffers))
+ f"Number of outputs and out_buffers mismatch: {len(shape)} vs {len(out_buffers)}."
)
input_placeholders = in_buffers or []
output_placeholders = out_buffers or []
diff --git a/python/tvm/testing/popen_pool.py b/python/tvm/testing/popen_pool.py
index 24ad40ae21..1e943867f3 100644
--- a/python/tvm/testing/popen_pool.py
+++ b/python/tvm/testing/popen_pool.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, missing-function-docstring
+# ruff: noqa: F821
"""Common functions for popen_pool test cases"""
import tvm_ffi
diff --git a/python/tvm/testing/utils.py b/python/tvm/testing/utils.py
index b1a2d94845..e640801d54 100644
--- a/python/tvm/testing/utils.py
+++ b/python/tvm/testing/utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, RUF005, RUF012
# pylint: disable=invalid-name,unnecessary-comprehension,redefined-outer-name
"""TVM testing utilities
@@ -428,9 +429,9 @@ def _get_targets(target_names=None):
return _get_targets(["llvm"])
raise TVMError(
- "None of the following targets are supported by this build of TVM: %s."
+ f"None of the following targets are supported by this build of TVM: {target_names}."
" Try setting TVM_TEST_TARGETS to a supported target."
- " Cannot default to llvm, as it is not enabled." % target_names
+ " Cannot default to llvm, as it is not enabled."
)
return targets
diff --git a/python/tvm/tir/functor.py b/python/tvm/tir/functor.py
index c4ac8d5893..a047fddb97 100644
--- a/python/tvm/tir/functor.py
+++ b/python/tvm/tir/functor.py
@@ -15,9 +15,10 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, arguments-differ
+# ruff: noqa: RUF012
"""The expression and statement functor of TIR."""
-from typing import Callable
+from typing import Callable, Optional
import tvm_ffi
@@ -156,56 +157,56 @@ class _PyStmtExprVisitor(tvm_ffi.core.Object):
def __init__(
self,
- f_visit_stmt: Callable = None,
- f_visit_expr: Callable = None,
+ f_visit_stmt: Optional[Callable] = None,
+ f_visit_expr: Optional[Callable] = None,
# Stmt
- f_visit_let_stmt: Callable = None,
- f_visit_attr_stmt: Callable = None,
- f_visit_if_then_else: Callable = None,
- f_visit_for: Callable = None,
- f_visit_while: Callable = None,
- f_visit_allocate: Callable = None,
- f_visit_decl_buffer: Callable = None,
- f_visit_buffer_store: Callable = None,
- f_visit_assert_stmt: Callable = None,
- f_visit_seq_stmt: Callable = None,
- f_visit_evaluate: Callable = None,
- f_visit_block: Callable = None,
- f_visit_sblock_realize: Callable = None,
+ f_visit_let_stmt: Optional[Callable] = None,
+ f_visit_attr_stmt: Optional[Callable] = None,
+ f_visit_if_then_else: Optional[Callable] = None,
+ f_visit_for: Optional[Callable] = None,
+ f_visit_while: Optional[Callable] = None,
+ f_visit_allocate: Optional[Callable] = None,
+ f_visit_decl_buffer: Optional[Callable] = None,
+ f_visit_buffer_store: Optional[Callable] = None,
+ f_visit_assert_stmt: Optional[Callable] = None,
+ f_visit_seq_stmt: Optional[Callable] = None,
+ f_visit_evaluate: Optional[Callable] = None,
+ f_visit_block: Optional[Callable] = None,
+ f_visit_sblock_realize: Optional[Callable] = None,
# PrimExpr
- f_visit_var: Callable = None,
- f_visit_size_var: Callable = None,
- f_visit_buffer_load: Callable = None,
- f_visit_producer_load: Callable = None,
- f_visit_let: Callable = None,
- f_visit_call: Callable = None,
- f_visit_add: Callable = None,
- f_visit_sub: Callable = None,
- f_visit_mul: Callable = None,
- f_visit_div: Callable = None,
- f_visit_mod: Callable = None,
- f_visit_floor_div: Callable = None,
- f_visit_floor_mod: Callable = None,
- f_visit_min: Callable = None,
- f_visit_max: Callable = None,
- f_visit_eq: Callable = None,
- f_visit_ne: Callable = None,
- f_visit_lt: Callable = None,
- f_visit_le: Callable = None,
- f_visit_gt: Callable = None,
- f_visit_ge: Callable = None,
- f_visit_and: Callable = None,
- f_visit_or: Callable = None,
- f_visit_reduce: Callable = None,
- f_visit_cast: Callable = None,
- f_visit_not: Callable = None,
- f_visit_select: Callable = None,
- f_visit_ramp: Callable = None,
- f_visit_broadcast: Callable = None,
- f_visit_shuffle: Callable = None,
- f_visit_int_imm: Callable = None,
- f_visit_float_imm: Callable = None,
- f_visit_string_imm: Callable = None,
+ f_visit_var: Optional[Callable] = None,
+ f_visit_size_var: Optional[Callable] = None,
+ f_visit_buffer_load: Optional[Callable] = None,
+ f_visit_producer_load: Optional[Callable] = None,
+ f_visit_let: Optional[Callable] = None,
+ f_visit_call: Optional[Callable] = None,
+ f_visit_add: Optional[Callable] = None,
+ f_visit_sub: Optional[Callable] = None,
+ f_visit_mul: Optional[Callable] = None,
+ f_visit_div: Optional[Callable] = None,
+ f_visit_mod: Optional[Callable] = None,
+ f_visit_floor_div: Optional[Callable] = None,
+ f_visit_floor_mod: Optional[Callable] = None,
+ f_visit_min: Optional[Callable] = None,
+ f_visit_max: Optional[Callable] = None,
+ f_visit_eq: Optional[Callable] = None,
+ f_visit_ne: Optional[Callable] = None,
+ f_visit_lt: Optional[Callable] = None,
+ f_visit_le: Optional[Callable] = None,
+ f_visit_gt: Optional[Callable] = None,
+ f_visit_ge: Optional[Callable] = None,
+ f_visit_and: Optional[Callable] = None,
+ f_visit_or: Optional[Callable] = None,
+ f_visit_reduce: Optional[Callable] = None,
+ f_visit_cast: Optional[Callable] = None,
+ f_visit_not: Optional[Callable] = None,
+ f_visit_select: Optional[Callable] = None,
+ f_visit_ramp: Optional[Callable] = None,
+ f_visit_broadcast: Optional[Callable] = None,
+ f_visit_shuffle: Optional[Callable] = None,
+ f_visit_int_imm: Optional[Callable] = None,
+ f_visit_float_imm: Optional[Callable] = None,
+ f_visit_string_imm: Optional[Callable] = None,
) -> None:
"""Constructor."""
self.__init_handle_by_constructor__(
@@ -958,56 +959,56 @@ class _PyStmtExprMutator(tvm_ffi.core.Object):
def __init__(
self,
- f_visit_stmt: Callable = None,
- f_visit_expr: Callable = None,
+ f_visit_stmt: Optional[Callable] = None,
+ f_visit_expr: Optional[Callable] = None,
# Stmt
- f_visit_let_stmt: Callable = None,
- f_visit_attr_stmt: Callable = None,
- f_visit_if_then_else: Callable = None,
- f_visit_for: Callable = None,
- f_visit_while: Callable = None,
- f_visit_allocate: Callable = None,
- f_visit_decl_buffer: Callable = None,
- f_visit_buffer_store: Callable = None,
- f_visit_assert_stmt: Callable = None,
- f_visit_seq_stmt: Callable = None,
- f_visit_evaluate: Callable = None,
- f_visit_block: Callable = None,
- f_visit_sblock_realize: Callable = None,
+ f_visit_let_stmt: Optional[Callable] = None,
+ f_visit_attr_stmt: Optional[Callable] = None,
+ f_visit_if_then_else: Optional[Callable] = None,
+ f_visit_for: Optional[Callable] = None,
+ f_visit_while: Optional[Callable] = None,
+ f_visit_allocate: Optional[Callable] = None,
+ f_visit_decl_buffer: Optional[Callable] = None,
+ f_visit_buffer_store: Optional[Callable] = None,
+ f_visit_assert_stmt: Optional[Callable] = None,
+ f_visit_seq_stmt: Optional[Callable] = None,
+ f_visit_evaluate: Optional[Callable] = None,
+ f_visit_block: Optional[Callable] = None,
+ f_visit_sblock_realize: Optional[Callable] = None,
# PrimExpr
- f_visit_var: Callable = None,
- f_visit_size_var: Callable = None,
- f_visit_buffer_load: Callable = None,
- f_visit_producer_load: Callable = None,
- f_visit_let: Callable = None,
- f_visit_call: Callable = None,
- f_visit_add: Callable = None,
- f_visit_sub: Callable = None,
- f_visit_mul: Callable = None,
- f_visit_div: Callable = None,
- f_visit_mod: Callable = None,
- f_visit_floor_div: Callable = None,
- f_visit_floor_mod: Callable = None,
- f_visit_min: Callable = None,
- f_visit_max: Callable = None,
- f_visit_eq: Callable = None,
- f_visit_ne: Callable = None,
- f_visit_lt: Callable = None,
- f_visit_le: Callable = None,
- f_visit_gt: Callable = None,
- f_visit_ge: Callable = None,
- f_visit_and: Callable = None,
- f_visit_or: Callable = None,
- f_visit_reduce: Callable = None,
- f_visit_cast: Callable = None,
- f_visit_not: Callable = None,
- f_visit_select: Callable = None,
- f_visit_ramp: Callable = None,
- f_visit_broadcast: Callable = None,
- f_visit_shuffle: Callable = None,
- f_visit_int_imm: Callable = None,
- f_visit_float_imm: Callable = None,
- f_visit_string_imm: Callable = None,
+ f_visit_var: Optional[Callable] = None,
+ f_visit_size_var: Optional[Callable] = None,
+ f_visit_buffer_load: Optional[Callable] = None,
+ f_visit_producer_load: Optional[Callable] = None,
+ f_visit_let: Optional[Callable] = None,
+ f_visit_call: Optional[Callable] = None,
+ f_visit_add: Optional[Callable] = None,
+ f_visit_sub: Optional[Callable] = None,
+ f_visit_mul: Optional[Callable] = None,
+ f_visit_div: Optional[Callable] = None,
+ f_visit_mod: Optional[Callable] = None,
+ f_visit_floor_div: Optional[Callable] = None,
+ f_visit_floor_mod: Optional[Callable] = None,
+ f_visit_min: Optional[Callable] = None,
+ f_visit_max: Optional[Callable] = None,
+ f_visit_eq: Optional[Callable] = None,
+ f_visit_ne: Optional[Callable] = None,
+ f_visit_lt: Optional[Callable] = None,
+ f_visit_le: Optional[Callable] = None,
+ f_visit_gt: Optional[Callable] = None,
+ f_visit_ge: Optional[Callable] = None,
+ f_visit_and: Optional[Callable] = None,
+ f_visit_or: Optional[Callable] = None,
+ f_visit_reduce: Optional[Callable] = None,
+ f_visit_cast: Optional[Callable] = None,
+ f_visit_not: Optional[Callable] = None,
+ f_visit_select: Optional[Callable] = None,
+ f_visit_ramp: Optional[Callable] = None,
+ f_visit_broadcast: Optional[Callable] = None,
+ f_visit_shuffle: Optional[Callable] = None,
+ f_visit_int_imm: Optional[Callable] = None,
+ f_visit_float_imm: Optional[Callable] = None,
+ f_visit_string_imm: Optional[Callable] = None,
) -> None:
"""Constructor."""
self.__init_handle_by_constructor__(
diff --git a/python/tvm/tir/pipeline.py b/python/tvm/tir/pipeline.py
index 28c5151938..c74b6ffde4 100644
--- a/python/tvm/tir/pipeline.py
+++ b/python/tvm/tir/pipeline.py
@@ -18,6 +18,8 @@
# pylint: disable=invalid-name
"""The TIR backend compilation pipeline."""
+from typing import Optional
+
import tvm
from tvm import tir
@@ -47,7 +49,7 @@ def finalize_device_passes(): # pylint: disable=unused-argument
PIPELINE_MAP = {}
-def get_tir_pipeline(name: str = None, **kwargs) -> tvm.transform.Pass:
+def get_tir_pipeline(name: Optional[str] = None, **kwargs) -> tvm.transform.Pass:
"""Get pre-build pipeline by name
Parameters
diff --git a/python/tvm/tir/transform/function_pass.py b/python/tvm/tir/transform/function_pass.py
index 86951628f2..fc3aee0c2a 100644
--- a/python/tvm/tir/transform/function_pass.py
+++ b/python/tvm/tir/transform/function_pass.py
@@ -69,7 +69,7 @@ def _wrap_class_function_pass(pass_cls, pass_info):
def prim_func_pass(
pass_func=None,
- opt_level: int = None,
+ opt_level: Optional[int] = None,
name: Optional[str] = None,
required: Optional[List[str]] = None,
traceable=False,
diff --git a/python/tvm/topi/einsum.py b/python/tvm/topi/einsum.py
index 6e0003d855..2f8adb2677 100644
--- a/python/tvm/topi/einsum.py
+++ b/python/tvm/topi/einsum.py
@@ -28,7 +28,7 @@ def einsum(subscripts, *operand):
subscripts : string
Specifies the subscripts for summation as comma separated list of subscript labels.
An implicit (classical Einstein summation) calculation is performed unless the
- explicit indicator ‘->’ is included as well as subscript labels of the precise
+ explicit indicator '->' is included as well as subscript labels of the precise
output form.
a_tuple : tuple of tvm.te.Tensor
diff --git a/python/tvm/topi/gpu/sort.py b/python/tvm/topi/gpu/sort.py
index 2a37d695b9..bff6e251b5 100644
--- a/python/tvm/topi/gpu/sort.py
+++ b/python/tvm/topi/gpu/sort.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, no-member, too-many-locals, too-many-arguments, too-many-statements, singleton-comparison, unused-argument, no-else-return
+# ruff: noqa: RUF005
"""Sort related operators"""
import tvm
diff --git a/python/tvm/topi/image/resize.py b/python/tvm/topi/image/resize.py
index edfc055e39..fdd13ecc01 100644
--- a/python/tvm/topi/image/resize.py
+++ b/python/tvm/topi/image/resize.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E741, F821
"""TVM operator input resize compute."""
import tvm
diff --git a/python/tvm/topi/nn/batch_matmul.py b/python/tvm/topi/nn/batch_matmul.py
index 986356f80a..eff3060cb0 100644
--- a/python/tvm/topi/nn/batch_matmul.py
+++ b/python/tvm/topi/nn/batch_matmul.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731
"""Batch matrix multiplication"""
# pylint: disable=invalid-name
diff --git a/python/tvm/topi/nn/conv2d.py b/python/tvm/topi/nn/conv2d.py
index 005db00c0d..4a3c017c90 100644
--- a/python/tvm/topi/nn/conv2d.py
+++ b/python/tvm/topi/nn/conv2d.py
@@ -16,6 +16,7 @@
# under the License.
# pylint: disable=invalid-name, unused-variable, too-many-locals
# pylint: disable=unused-argument, redefined-builtin
+# ruff: noqa: F841, RUF005
"""Conv2D operators"""
from __future__ import absolute_import as _abs
diff --git a/python/tvm/topi/nn/conv2d_transpose.py b/python/tvm/topi/nn/conv2d_transpose.py
index 4f119f7eeb..d7c256105b 100644
--- a/python/tvm/topi/nn/conv2d_transpose.py
+++ b/python/tvm/topi/nn/conv2d_transpose.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-variable, unused-argument
+# ruff: noqa: F821
"""Transposed 2D convolution operators (sometimes called Deconvolution)."""
import collections
diff --git a/python/tvm/topi/nn/correlation.py b/python/tvm/topi/nn/correlation.py
index 433e20a041..dcc885fba4 100644
--- a/python/tvm/topi/nn/correlation.py
+++ b/python/tvm/topi/nn/correlation.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731
"""Correlation operators"""
from tvm import te
diff --git a/python/tvm/topi/nn/dense.py b/python/tvm/topi/nn/dense.py
index 1c2e77e84f..d3700e569d 100644
--- a/python/tvm/topi/nn/dense.py
+++ b/python/tvm/topi/nn/dense.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name,unused-argument
+# ruff: noqa: E741, F821
"""TVM operator fully connected compute."""
import tvm
diff --git a/python/tvm/topi/nn/depthwise_conv2d.py b/python/tvm/topi/nn/depthwise_conv2d.py
index de3b08d139..89ce8ed1e2 100644
--- a/python/tvm/topi/nn/depthwise_conv2d.py
+++ b/python/tvm/topi/nn/depthwise_conv2d.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-variable, too-many-locals, unused-argument
+# ruff: noqa: F841
"""Depthwise convolution operators"""
from __future__ import absolute_import as _abs
diff --git a/python/tvm/topi/nn/fifo_buffer.py b/python/tvm/topi/nn/fifo_buffer.py
index e9521cd51a..dd185c17c2 100644
--- a/python/tvm/topi/nn/fifo_buffer.py
+++ b/python/tvm/topi/nn/fifo_buffer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""FIFO buffer op"""
diff --git a/python/tvm/topi/nn/lstm.py b/python/tvm/topi/nn/lstm.py
index ff784605f6..cceeb7a844 100644
--- a/python/tvm/topi/nn/lstm.py
+++ b/python/tvm/topi/nn/lstm.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E731
"""General LSTM implementation using TE scan."""
from tvm import te, tir
diff --git a/python/tvm/topi/nn/pixel_shuffle.py b/python/tvm/topi/nn/pixel_shuffle.py
index ecbfd92e20..ccfa133557 100644
--- a/python/tvm/topi/nn/pixel_shuffle.py
+++ b/python/tvm/topi/nn/pixel_shuffle.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""TVM operator pixel shuffle compute."""
import tvm
diff --git a/python/tvm/topi/nn/softmax.py b/python/tvm/topi/nn/softmax.py
index f08ddce034..acdd3a99dc 100644
--- a/python/tvm/topi/nn/softmax.py
+++ b/python/tvm/topi/nn/softmax.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, pointless-exception-statement
+# ruff: noqa: RUF005
"""TVM operator for softmax and log_softmax compute."""
import tvm
diff --git a/python/tvm/topi/nn/winograd_util.py b/python/tvm/topi/nn/winograd_util.py
index 7afd7e39c7..f872f79c28 100644
--- a/python/tvm/topi/nn/winograd_util.py
+++ b/python/tvm/topi/nn/winograd_util.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
#
+# ruff: noqa: E731
"""Utility functions for implementing Winograd convolutions
[*] Fast Algorithms for Convolutional Neural Networks
Andrew Lavin, Scott Gray
diff --git a/python/tvm/topi/scatter.py b/python/tvm/topi/scatter.py
index e767cb5de7..ab10869070 100644
--- a/python/tvm/topi/scatter.py
+++ b/python/tvm/topi/scatter.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E741
"""ScatterND operator"""
from tvm import te, tir # hide redefinition of min and max
diff --git a/python/tvm/topi/testing/adaptive_pool_python.py b/python/tvm/topi/testing/adaptive_pool_python.py
index 023110d680..1909e73d0a 100644
--- a/python/tvm/topi/testing/adaptive_pool_python.py
+++ b/python/tvm/topi/testing/adaptive_pool_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-argument, unused-variable
+# ruff: noqa: E741, RUF005
"""adaptive pool in python"""
import numpy as np
diff --git a/python/tvm/topi/testing/conv2d_nchw_python.py b/python/tvm/topi/testing/conv2d_nchw_python.py
index 441f8cb2cd..91362dfbbd 100644
--- a/python/tvm/topi/testing/conv2d_nchw_python.py
+++ b/python/tvm/topi/testing/conv2d_nchw_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals, too-many-branches
+# ruff: noqa: F841
"""Convolution in python"""
import numpy as np
diff --git a/python/tvm/topi/testing/conv3d_transpose_ncdhw_python.py b/python/tvm/topi/testing/conv3d_transpose_ncdhw_python.py
index b8db518202..4fa9bde655 100644
--- a/python/tvm/topi/testing/conv3d_transpose_ncdhw_python.py
+++ b/python/tvm/topi/testing/conv3d_transpose_ncdhw_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals, too-many-branches
+# ruff: noqa: F841
"""Convolution 3D transpose in python"""
import numpy as np
diff --git a/python/tvm/topi/testing/correlation_nchw_python.py b/python/tvm/topi/testing/correlation_nchw_python.py
index e57764c59f..3631d17fea 100644
--- a/python/tvm/topi/testing/correlation_nchw_python.py
+++ b/python/tvm/topi/testing/correlation_nchw_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals
+# ruff: noqa: E731
"""Convolution 3D in python"""
import numpy as np
diff --git a/python/tvm/topi/testing/deformable_conv2d_python.py b/python/tvm/topi/testing/deformable_conv2d_python.py
index 154e3426ae..59df406b86 100644
--- a/python/tvm/topi/testing/deformable_conv2d_python.py
+++ b/python/tvm/topi/testing/deformable_conv2d_python.py
@@ -84,8 +84,8 @@ def deformable_conv2d_nchw_python(
dilation_h, dilation_w = dilation
def _bilinear(n, c, h, w):
- y_low = int(math.floor(h))
- x_low = int(math.floor(w))
+ y_low = math.floor(h)
+ x_low = math.floor(w)
y_high = y_low + 1
x_high = x_low + 1
diff --git a/python/tvm/topi/testing/gather_nd_python.py b/python/tvm/topi/testing/gather_nd_python.py
index a130cc7436..2b52aaea4a 100644
--- a/python/tvm/topi/testing/gather_nd_python.py
+++ b/python/tvm/topi/testing/gather_nd_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals
+# ruff: noqa: RUF005
"""gather_nd in python"""
import numpy as np
diff --git a/python/tvm/topi/testing/grid_sample_python.py b/python/tvm/topi/testing/grid_sample_python.py
index e7b612eedf..22010ae02b 100644
--- a/python/tvm/topi/testing/grid_sample_python.py
+++ b/python/tvm/topi/testing/grid_sample_python.py
@@ -124,8 +124,8 @@ def grid_sample_2d(
for _h in range(out_height):
for _w in range(out_width):
y, x = _compute_source_index(_b, _h, _w)
- y0 = int(math.floor(y))
- x0 = int(math.floor(x))
+ y0 = math.floor(y)
+ x0 = math.floor(x)
y1 = y0 + 1
x1 = x0 + 1
@@ -205,8 +205,8 @@ def grid_sample_2d(
y = grid[_b, 1, _h, _w]
x = grid[_b, 0, _h, _w]
y, x = _unnormalize(y, x)
- y_floor = int(math.floor(y))
- x_floor = int(math.floor(x))
+ y_floor = math.floor(y)
+ x_floor = math.floor(x)
y_fraction = y - y_floor
x_fraction = x - x_floor
@@ -331,9 +331,9 @@ def grid_sample_3d(
for _h in range(out_height):
for _w in range(out_width):
z, y, x = _compute_source_index(_b, _d, _h, _w)
- z0 = int(math.floor(z))
- y0 = int(math.floor(y))
- x0 = int(math.floor(x))
+ z0 = math.floor(z)
+ y0 = math.floor(y)
+ x0 = math.floor(x)
z1 = z0 + 1
y1 = y0 + 1
x1 = x0 + 1
diff --git a/python/tvm/topi/testing/lrn_python.py b/python/tvm/topi/testing/lrn_python.py
index 6f9067294f..8856943bd6 100644
--- a/python/tvm/topi/testing/lrn_python.py
+++ b/python/tvm/topi/testing/lrn_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals
+# ruff: noqa: E741
"""LRN in python"""
from itertools import product
diff --git a/python/tvm/topi/testing/lstm_python.py b/python/tvm/topi/testing/lstm_python.py
index 783c9642bb..f445575b02 100644
--- a/python/tvm/topi/testing/lstm_python.py
+++ b/python/tvm/topi/testing/lstm_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E741
"""LSTM reference implementation using numpy."""
import numpy as np
diff --git a/python/tvm/topi/testing/nll_loss.py b/python/tvm/topi/testing/nll_loss.py
index 2167a25c32..2e72961bb4 100644
--- a/python/tvm/topi/testing/nll_loss.py
+++ b/python/tvm/topi/testing/nll_loss.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF005
"""NLLLoss in python"""
import numpy as np
diff --git a/python/tvm/topi/testing/poolnd_python.py b/python/tvm/topi/testing/poolnd_python.py
index 8fe4d2ab50..39e77a1500 100644
--- a/python/tvm/topi/testing/poolnd_python.py
+++ b/python/tvm/topi/testing/poolnd_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-argument, unused-variable
+# ruff: noqa: RUF005
"""Ground truth max and average pooling operators in python."""
import itertools
diff --git a/python/tvm/topi/testing/resize_python.py b/python/tvm/topi/testing/resize_python.py
index 9b15b77f78..5bdc182a05 100644
--- a/python/tvm/topi/testing/resize_python.py
+++ b/python/tvm/topi/testing/resize_python.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals
+# ruff: noqa: E741, F841, RUF005
"""Upsampling in python"""
import math
@@ -45,9 +46,9 @@ def get_index(x, image_width, target_width, coordinate_transformation_mode):
in_x = get_inx(x, image_width, target_width, coordinate_transformation_mode)
if coordinate_transformation_mode == "align_corners":
# round prefer ceil
- out = int(math.floor(in_x + 0.5))
+ out = math.floor(in_x + 0.5)
else:
- out = int(math.floor(in_x))
+ out = math.floor(in_x)
out = max(min(out, image_width - 1), 0)
return out
@@ -55,7 +56,7 @@ def get_index(x, image_width, target_width, coordinate_transformation_mode):
def resize3d_nearest(arr, scale, coordinate_transformation_mode):
"""Populate the array by scale factor"""
d, h, w = arr.shape
- out_d, out_h, out_w = [int(round(i * s)) for i, s in zip(arr.shape, scale)]
+ out_d, out_h, out_w = [round(i * s) for i, s in zip(arr.shape, scale)]
out = np.empty((out_d, out_h, out_w))
for z in range(out_d):
for y in range(out_h):
@@ -71,7 +72,7 @@ def resize3d_linear(data_in, scale, coordinate_transformation_mode):
"""Trilinear 3d scaling using python"""
dtype = data_in.dtype
d, h, w = data_in.shape
- new_d, new_h, new_w = [int(round(i * s)) for i, s in zip(data_in.shape, scale)]
+ new_d, new_h, new_w = [round(i * s) for i, s in zip(data_in.shape, scale)]
data_out = np.ones((new_d, new_h, new_w))
indexes = np.mgrid[0:2, 0:2, 0:2]
@@ -116,7 +117,7 @@ def resize3d_cubic(data_in, scale, coordinate_transformation_mode):
"""Tricubic 3d scaling using python"""
dtype = data_in.dtype
d, h, w = data_in.shape
- new_d, new_h, new_w = [int(round(i * s)) for i, s in zip(data_in.shape, scale)]
+ new_d, new_h, new_w = [round(i * s) for i, s in zip(data_in.shape, scale)]
data_out = np.ones((new_d, new_h, new_w))
def _cubic_spline_weights(t, alpha=-0.5):
@@ -177,9 +178,9 @@ def resize3d_ncdhw(
oshape = (
ishape[0],
ishape[1],
- int(round(ishape[2] * scale[0])),
- int(round(ishape[3] * scale[1])),
- int(round(ishape[4] * scale[2])),
+ round(ishape[2] * scale[0]),
+ round(ishape[3] * scale[1]),
+ round(ishape[4] * scale[2]),
)
output_np = np.zeros(oshape, dtype=data.dtype)
diff --git a/python/tvm/topi/testing/roi_align_python.py b/python/tvm/topi/testing/roi_align_python.py
index 73b1b81093..9fc72074e4 100644
--- a/python/tvm/topi/testing/roi_align_python.py
+++ b/python/tvm/topi/testing/roi_align_python.py
@@ -29,8 +29,8 @@ def _bilinear(a_np, n, c, y, x, height, width, layout):
y = min(max(y, 0), height - 1)
x = min(max(x, 0), width - 1)
- y_low = int(math.floor(y))
- x_low = int(math.floor(x))
+ y_low = math.floor(y)
+ x_low = math.floor(x)
y_high = y_low + 1
x_high = x_low + 1
@@ -81,8 +81,8 @@ def roi_align_common(
if sample_ratio > 0:
roi_bin_grid_h = roi_bin_grid_w = int(sample_ratio)
else:
- roi_bin_grid_h = int(math.ceil(roi_h / pooled_size_h))
- roi_bin_grid_w = int(math.ceil(roi_w / pooled_size_w))
+ roi_bin_grid_h = math.ceil(roi_h / pooled_size_h)
+ roi_bin_grid_w = math.ceil(roi_w / pooled_size_w)
count = roi_bin_grid_h * roi_bin_grid_w
diff --git a/python/tvm/topi/testing/roi_pool_python.py b/python/tvm/topi/testing/roi_pool_python.py
index 28b3e7a739..0f7120b466 100644
--- a/python/tvm/topi/testing/roi_pool_python.py
+++ b/python/tvm/topi/testing/roi_pool_python.py
@@ -36,10 +36,10 @@ def roi_pool_nchw_python(a_np, rois_np, pooled_size, spatial_scale):
for i in range(num_roi):
roi = rois_np[i]
batch_index = int(roi[0])
- roi_start_w = int(round(roi[1] * spatial_scale))
- roi_start_h = int(round(roi[2] * spatial_scale))
- roi_end_w = int(round(roi[3] * spatial_scale))
- roi_end_h = int(round(roi[4] * spatial_scale))
+ roi_start_w = round(roi[1] * spatial_scale)
+ roi_start_h = round(roi[2] * spatial_scale)
+ roi_end_w = round(roi[3] * spatial_scale)
+ roi_end_h = round(roi[4] * spatial_scale)
roi_h = max(roi_end_h - roi_start_h + 1, 1)
roi_w = max(roi_end_w - roi_start_w + 1, 1)
@@ -48,10 +48,10 @@ def roi_pool_nchw_python(a_np, rois_np, pooled_size, spatial_scale):
for ph in range(pooled_size_h):
for pw in range(pooled_size_w):
- hstart = int(math.floor(ph * bin_h))
- wstart = int(math.floor(pw * bin_w))
- hend = int(math.ceil((ph + 1) * bin_h))
- wend = int(math.ceil((pw + 1) * bin_w))
+ hstart = math.floor(ph * bin_h)
+ wstart = math.floor(pw * bin_w)
+ hend = math.ceil((ph + 1) * bin_h)
+ wend = math.ceil((pw + 1) * bin_w)
hstart = min(max(hstart + roi_start_h, 0), height)
hend = min(max(hend + roi_start_h, 0), height)
wstart = min(max(wstart + roi_start_w, 0), width)
diff --git a/python/tvm/topi/transform.py b/python/tvm/topi/transform.py
index 7e5ead2f58..ec6242098d 100644
--- a/python/tvm/topi/transform.py
+++ b/python/tvm/topi/transform.py
@@ -1064,11 +1064,11 @@ def trilu(data, k, upper):
def index_tensor(data, indices):
- """Advanced‑tensor indexing (NumPy/PyTorch‐style).
+ """Advanced-tensor indexing (NumPy/PyTorch-style).
- Given k index tensors ``indices = (I0, I1, …, Ik‑1)`` this
+ Given k index tensors ``indices = (I0, I1, …, Ik-1)`` this
operator selects elements from ``data`` as if one had written
- ``data[I0, I1, …, Ik‑1]`` in NumPy/PyTorch:
+ ``data[I0, I1, …, Ik-1]`` in NumPy/PyTorch:
* All index tensors must have an integer dtype.
* Their shapes are broadcast together to a common shape ``B`` in
@@ -1076,7 +1076,7 @@ def index_tensor(data, indices):
* The result shape is ``B + data.shape[k:]`` (i.e. the broadcast
shape followed by the remaining axes of ``data`` that are *not*
indexed).
- * ``k`` must not exceed ``data.ndim``; otherwise a compile‑time
+ * ``k`` must not exceed ``data.ndim``; otherwise a compile-time
error is raised.
Parameters
diff --git a/python/tvm/topi/utils.py b/python/tvm/topi/utils.py
index a9ebdd214b..72e5a44799 100644
--- a/python/tvm/topi/utils.py
+++ b/python/tvm/topi/utils.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: RUF005
"""Common topi utilities"""
from __future__ import absolute_import as _abs
diff --git a/python/tvm/topi/vision/nms_util.py b/python/tvm/topi/vision/nms_util.py
index 1cb3089547..054762f1a1 100644
--- a/python/tvm/topi/vision/nms_util.py
+++ b/python/tvm/topi/vision/nms_util.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name
+# ruff: noqa: E741
"""Common utilities used in Non-maximum suppression operators"""
import tvm
diff --git a/tests/lint/check_asf_header.py b/tests/lint/check_asf_header.py
index 9b34b28fd0..c2e02f1db6 100644
--- a/tests/lint/check_asf_header.py
+++ b/tests/lint/check_asf_header.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""Helper tool to check and fix ASF headers in source files tracked by git.
Ported from tvm-ffi. Replaces the previous RAT-based check_asf_header.sh
diff --git a/tests/lint/check_cmake_options.py b/tests/lint/check_cmake_options.py
index 21617e7d27..ab0ebc0b86 100644
--- a/tests/lint/check_cmake_options.py
+++ b/tests/lint/check_cmake_options.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import argparse
import re
diff --git a/tests/lint/check_file_type.py b/tests/lint/check_file_type.py
index 2c2d50ea9a..b7feb3f87e 100644
--- a/tests/lint/check_file_type.py
+++ b/tests/lint/check_file_type.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""Helper tool to check file types that are allowed to checkin."""
import subprocess
diff --git a/tests/python/all-platform-minimal-test/test_minimal_target_codegen_llvm.py b/tests/python/all-platform-minimal-test/test_minimal_target_codegen_llvm.py
index ed62862d83..19a11e4582 100644
--- a/tests/python/all-platform-minimal-test/test_minimal_target_codegen_llvm.py
+++ b/tests/python/all-platform-minimal-test/test_minimal_target_codegen_llvm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""LLVM enablement tests."""
import ctypes
diff --git a/tests/python/all-platform-minimal-test/test_runtime_packed_func.py b/tests/python/all-platform-minimal-test/test_runtime_packed_func.py
index 9451cd209d..8e2406b851 100644
--- a/tests/python/all-platform-minimal-test/test_runtime_packed_func.py
+++ b/tests/python/all-platform-minimal-test/test_runtime_packed_func.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821
"""Test packed function FFI."""
import gc
diff --git a/tests/python/arith/test_arith_canonical_simplify.py b/tests/python/arith/test_arith_canonical_simplify.py
index de43e43775..4ff8af6b8b 100644
--- a/tests/python/arith/test_arith_canonical_simplify.py
+++ b/tests/python/arith/test_arith_canonical_simplify.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731, F841
import tvm
import tvm.testing
from tvm import te, tir
diff --git a/tests/python/arith/test_arith_const_int_bound.py b/tests/python/arith/test_arith_const_int_bound.py
index 3d3cc6e5e7..7ac4983d07 100644
--- a/tests/python/arith/test_arith_const_int_bound.py
+++ b/tests/python/arith/test_arith_const_int_bound.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
import contextlib
diff --git a/tests/python/arith/test_arith_deduce_bound.py b/tests/python/arith/test_arith_deduce_bound.py
index 72108b8260..43dd044855 100644
--- a/tests/python/arith/test_arith_deduce_bound.py
+++ b/tests/python/arith/test_arith_deduce_bound.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
import pytest
import tvm
diff --git a/tests/python/arith/test_arith_detect_linear_equation.py b/tests/python/arith/test_arith_detect_linear_equation.py
index d7902047ca..e20ab51569 100644
--- a/tests/python/arith/test_arith_detect_linear_equation.py
+++ b/tests/python/arith/test_arith_detect_linear_equation.py
@@ -48,7 +48,7 @@ def test_basic():
def test_multivariate():
- v = [tvm.tir.Var("v%d" % i, "int32") for i in range(4)]
+ v = [tvm.tir.Var(f"v{i}", "int32") for i in range(4)]
b = tvm.tir.Var("b", "int32")
m = tvm.arith.detect_linear_equation(v[0] * (b + 4) + v[0] + v[1] * 8, v)
diff --git a/tests/python/arith/test_arith_intset.py b/tests/python/arith/test_arith_intset.py
index 3eb4da227f..0832a397cf 100644
--- a/tests/python/arith/test_arith_intset.py
+++ b/tests/python/arith/test_arith_intset.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
from tvm import tir
diff --git a/tests/python/arith/test_arith_iter_affine_map.py b/tests/python/arith/test_arith_iter_affine_map.py
index 6e691765d3..28bc94db3b 100644
--- a/tests/python/arith/test_arith_iter_affine_map.py
+++ b/tests/python/arith/test_arith_iter_affine_map.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
from tvm.script import tir as T
diff --git a/tests/python/arith/test_arith_modular_set.py b/tests/python/arith/test_arith_modular_set.py
index ef7b0593d0..a103c2faee 100644
--- a/tests/python/arith/test_arith_modular_set.py
+++ b/tests/python/arith/test_arith_modular_set.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
diff --git a/tests/python/arith/test_arith_narrow_predicate_expression.py b/tests/python/arith/test_arith_narrow_predicate_expression.py
index 795de99963..16a0b85489 100644
--- a/tests/python/arith/test_arith_narrow_predicate_expression.py
+++ b/tests/python/arith/test_arith_narrow_predicate_expression.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/arith/test_arith_rewrite_simplify.py b/tests/python/arith/test_arith_rewrite_simplify.py
index 556d663342..2dc27e5785 100644
--- a/tests/python/arith/test_arith_rewrite_simplify.py
+++ b/tests/python/arith/test_arith_rewrite_simplify.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
import inspect
diff --git a/tests/python/arith/test_arith_solve_linear_equations.py b/tests/python/arith/test_arith_solve_linear_equations.py
index 1641a1834c..067738f280 100644
--- a/tests/python/arith/test_arith_solve_linear_equations.py
+++ b/tests/python/arith/test_arith_solve_linear_equations.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import random
import sys
diff --git a/tests/python/ci/test_ci.py b/tests/python/ci/test_ci.py
index bc617b95c2..41b3f5d275 100644
--- a/tests/python/ci/test_ci.py
+++ b/tests/python/ci/test_ci.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, RUF005
"""Test various CI scripts and GitHub Actions workflows"""
import json
diff --git a/tests/python/ci/test_tvmbot.py b/tests/python/ci/test_tvmbot.py
index 83a0ab7f0e..e89edbfd95 100644
--- a/tests/python/ci/test_tvmbot.py
+++ b/tests/python/ci/test_tvmbot.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""
Test the @tvm-bot merge code
"""
diff --git a/tests/python/ci/test_utils.py b/tests/python/ci/test_utils.py
index 5ef07c2e6f..63143f7734 100644
--- a/tests/python/ci/test_utils.py
+++ b/tests/python/ci/test_utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
"""
Constants used in various CI tests
"""
diff --git a/tests/python/codegen/test_gpu_codegen_allreduce.py b/tests/python/codegen/test_gpu_codegen_allreduce.py
index 734901dc4a..4ffa7b765d 100644
--- a/tests/python/codegen/test_gpu_codegen_allreduce.py
+++ b/tests/python/codegen/test_gpu_codegen_allreduce.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
import numpy as np
import pytest
import tvm_ffi
diff --git a/tests/python/codegen/test_target_codegen.py b/tests/python/codegen/test_target_codegen.py
index 837ac29764..cb7aa065f3 100644
--- a/tests/python/codegen/test_target_codegen.py
+++ b/tests/python/codegen/test_target_codegen.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
import pytest
diff --git a/tests/python/codegen/test_target_codegen_blob.py b/tests/python/codegen/test_target_codegen_blob.py
index 7b85b23eb7..4a8e2dfdf9 100644
--- a/tests/python/codegen/test_target_codegen_blob.py
+++ b/tests/python/codegen/test_target_codegen_blob.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821, F841
import ctypes
@@ -33,7 +34,7 @@ def test_cuda_multi_lib():
dev = tvm.cuda(0)
for device in ["llvm", "cuda"]:
if not tvm.testing.device_enabled(device):
- print("skip because %s is not enabled..." % device)
+ print(f"skip because {device} is not enabled...")
return
@tvm.script.ir_module
diff --git a/tests/python/codegen/test_target_codegen_cross_llvm.py b/tests/python/codegen/test_target_codegen_cross_llvm.py
index af0b0bfe9a..8d1d45cd04 100644
--- a/tests/python/codegen/test_target_codegen_cross_llvm.py
+++ b/tests/python/codegen/test_target_codegen_cross_llvm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
"""Test cross compilation"""
import os
@@ -62,7 +63,7 @@ def test_llvm_add_pipeline():
def build_arm():
target = {"kind": "llvm", "mtriple": "armv7-none-linux-gnueabihf"}
if not tvm.runtime.enabled("llvm"):
- print("Skip because %s is not enabled.." % target)
+ print(f"Skip because {target} is not enabled..")
return
temp = utils.tempdir()
f = tvm.tir.build(AddModule, target=target)
diff --git a/tests/python/codegen/test_target_codegen_cuda.py b/tests/python/codegen/test_target_codegen_cuda.py
index fd58b59659..b451c69383 100644
--- a/tests/python/codegen/test_target_codegen_cuda.py
+++ b/tests/python/codegen/test_target_codegen_cuda.py
@@ -1,4 +1,5 @@
# Licensed to the Apache Software Foundation (ASF) under one
+# ruff: noqa: E501, E741, F401, F841
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -64,7 +65,7 @@ def test_cuda_vectorize_add():
if dtype == "int8" and not have_int8(tvm.cuda(0).compute_version):
print("skip because gpu does not support int8")
return
- vec_dtype = "%sx%d" % (dtype, lanes)
+ vec_dtype = f"{dtype}x{lanes}"
one = tvm.tir.const(1, vec_dtype)
num_blocks = (n + num_thread - 1) // num_thread
@@ -127,7 +128,7 @@ def test_cuda_bf16_vectorize_add():
return u32.view("<f4")
def check_cuda(n, lanes):
- vec_dtype = "bfloat16x%d" % lanes
+ vec_dtype = f"bfloat16x{lanes}"
num_blocks = n // num_thread
one = tvm.tir.Broadcast(tvm.tir.const(1, "bfloat16"), lanes)
@@ -172,7 +173,7 @@ def test_cuda_multiply_add():
if dtype == "int8" and not have_int8(tvm.cuda(0).compute_version):
print("skip because gpu does not support int8")
return
- vec_dtype = "%sx%d" % (dtype, lanes)
+ vec_dtype = f"{dtype}x{lanes}"
num_blocks = n // num_thread
@I.ir_module
@@ -217,7 +218,7 @@ def test_cuda_vectorize_load():
def check_cuda(dtype, n, lanes):
dev = tvm.cuda(0)
- vec_dtype = "%sx%d" % (dtype, lanes)
+ vec_dtype = f"{dtype}x{lanes}"
num_blocks = n // num_thread
@I.ir_module
diff --git a/tests/python/codegen/test_target_codegen_cuda_fp8.py b/tests/python/codegen/test_target_codegen_cuda_fp8.py
index ad70bf11ab..56bcab61a4 100644
--- a/tests/python/codegen/test_target_codegen_cuda_fp8.py
+++ b/tests/python/codegen/test_target_codegen_cuda_fp8.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821, F841
from itertools import product
from typing import List, Tuple
diff --git a/tests/python/codegen/test_target_codegen_extern.py b/tests/python/codegen/test_target_codegen_extern.py
index 4105847952..efe043452d 100644
--- a/tests/python/codegen/test_target_codegen_extern.py
+++ b/tests/python/codegen/test_target_codegen_extern.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
import tvm
diff --git a/tests/python/codegen/test_target_codegen_llvm.py b/tests/python/codegen/test_target_codegen_llvm.py
index fce091587e..06d1baac05 100644
--- a/tests/python/codegen/test_target_codegen_llvm.py
+++ b/tests/python/codegen/test_target_codegen_llvm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E731, E741, F841
import math
import re
diff --git a/tests/python/codegen/test_target_codegen_opencl.py b/tests/python/codegen/test_target_codegen_opencl.py
index e9d7fb6368..92a7992ec1 100644
--- a/tests/python/codegen/test_target_codegen_opencl.py
+++ b/tests/python/codegen/test_target_codegen_opencl.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import re
import tvm
diff --git a/tests/python/codegen/test_target_codegen_riscv.py b/tests/python/codegen/test_target_codegen_riscv.py
index c83953d51f..e4fe54303f 100644
--- a/tests/python/codegen/test_target_codegen_riscv.py
+++ b/tests/python/codegen/test_target_codegen_riscv.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
import pytest
import tvm
diff --git a/tests/python/codegen/test_target_codegen_rocm.py b/tests/python/codegen/test_target_codegen_rocm.py
index 61d718c65d..6148bf3443 100644
--- a/tests/python/codegen/test_target_codegen_rocm.py
+++ b/tests/python/codegen/test_target_codegen_rocm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
import tvm
@@ -75,7 +76,7 @@ def test_rocm_copy():
@tvm.testing.requires_rocm
def test_rocm_vectorize_add():
def check_rocm(dtype, n, lanes):
- vec_dtype = "%sx%d" % (dtype, lanes)
+ vec_dtype = f"{dtype}x{lanes}"
num_blocks = n // 4
@I.ir_module
diff --git a/tests/python/codegen/test_target_codegen_vulkan.py b/tests/python/codegen/test_target_codegen_vulkan.py
index 50e4a63410..96e3d7240d 100644
--- a/tests/python/codegen/test_target_codegen_vulkan.py
+++ b/tests/python/codegen/test_target_codegen_vulkan.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import re
diff --git a/tests/python/codegen/test_target_codegen_x86.py b/tests/python/codegen/test_target_codegen_x86.py
index 33929218cc..483fafe8ff 100644
--- a/tests/python/codegen/test_target_codegen_x86.py
+++ b/tests/python/codegen/test_target_codegen_x86.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
import platform
import re
diff --git a/tests/python/contrib/test_android/test_meta_schedule.py b/tests/python/contrib/test_android/test_meta_schedule.py
index 6eacd16cf7..f3a2d9eb11 100644
--- a/tests/python/contrib/test_android/test_meta_schedule.py
+++ b/tests/python/contrib/test_android/test_meta_schedule.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Test rpc based launcher for Android"""
diff --git a/tests/python/contrib/test_cblas.py b/tests/python/contrib/test_cblas.py
index 6176019c69..4431742cbd 100644
--- a/tests/python/contrib/test_cblas.py
+++ b/tests/python/contrib/test_cblas.py
@@ -56,7 +56,7 @@ def verify_matmul_add(
def verify(target="llvm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func(lib.__name__ + ".matmul", True):
print("skip because extern function is not available")
@@ -146,7 +146,7 @@ def verify_quantized_matmul_add(matrix_m, matrix_l, matrix_n, transa=False, tran
def verify(target="llvm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func("tvm.contrib.mkl.matmul_u8s8s32", True):
print("skip because extern function is not available")
@@ -231,7 +231,7 @@ def verify_batch_matmul(
def verify(target="llvm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func(lib.__name__ + ".matmul", True):
print("skip because extern function is not available")
diff --git a/tests/python/contrib/test_coreml_runtime.py b/tests/python/contrib/test_coreml_runtime.py
index e1155ecc90..4aa99f9f8f 100644
--- a/tests/python/contrib/test_coreml_runtime.py
+++ b/tests/python/contrib/test_coreml_runtime.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import os
import numpy as np
diff --git a/tests/python/contrib/test_edgetpu_runtime.py b/tests/python/contrib/test_edgetpu_runtime.py
index 83e3f6276a..e1324cfc92 100644
--- a/tests/python/contrib/test_edgetpu_runtime.py
+++ b/tests/python/contrib/test_edgetpu_runtime.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821
import os
import numpy as np
diff --git a/tests/python/contrib/test_hexagon/benchmark_util.py b/tests/python/contrib/test_hexagon/benchmark_util.py
index 2574a8cd1e..26eea5d8a1 100644
--- a/tests/python/contrib/test_hexagon/benchmark_util.py
+++ b/tests/python/contrib/test_hexagon/benchmark_util.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF012
"""Utility functions used for benchmarks"""
diff --git a/tests/python/contrib/test_hexagon/pytest_util.py b/tests/python/contrib/test_hexagon/pytest_util.py
index 97ccc238fe..d3ff86a79d 100644
--- a/tests/python/contrib/test_hexagon/pytest_util.py
+++ b/tests/python/contrib/test_hexagon/pytest_util.py
@@ -23,7 +23,7 @@ from typing import List, Optional, Union
import numpy as np
-def get_test_id(*test_params, test_param_descs: List[Optional[str]] = None) -> str:
+def get_test_id(*test_params, test_param_descs: Optional[List[Optional[str]]] = None) -> str:
"""
An opinionated alternative to pytest's default algorithm for generating a
test's ID string. Intended to make it easier for human readers to
diff --git a/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py b/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
index af0dcfcf1f..b34e9c03a5 100644
--- a/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
+++ b/tests/python/contrib/test_hexagon/test_async_dma_pipeline.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""Test different strategies for loading data into vtcm before running HVX workloads."""
diff --git a/tests/python/contrib/test_hexagon/test_benchmark_maxpool2d.py b/tests/python/contrib/test_hexagon/test_benchmark_maxpool2d.py
index a41527e07a..ba53ba7af2 100644
--- a/tests/python/contrib/test_hexagon/test_benchmark_maxpool2d.py
+++ b/tests/python/contrib/test_hexagon/test_benchmark_maxpool2d.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, RUF012
"""
This module serves two purposes:
diff --git a/tests/python/contrib/test_hexagon/test_fixed_point_conversion.py b/tests/python/contrib/test_hexagon/test_fixed_point_conversion.py
index 2eb7531d58..c1bc517be7 100644
--- a/tests/python/contrib/test_hexagon/test_fixed_point_conversion.py
+++ b/tests/python/contrib/test_hexagon/test_fixed_point_conversion.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
"""
Test float to fixed-point conversion. We do it by constructing a numpy array with the
diff --git a/tests/python/contrib/test_hexagon/test_meta_schedule.py b/tests/python/contrib/test_hexagon/test_meta_schedule.py
index 1b7ab4ac4d..c498dacfbd 100644
--- a/tests/python/contrib/test_hexagon/test_meta_schedule.py
+++ b/tests/python/contrib/test_hexagon/test_meta_schedule.py
@@ -186,7 +186,7 @@ def verify_dense(sch, target, m_size, n_size, k_size, hexagon_session):
evaluator = mod.time_evaluator(mod.entry_name, dev, number=10)
gflops = (n_size * m_size * k_size) * 2 / 1e9
time_ms = evaluator(a, b, c).mean * 1e3
- print("%f ms, %f GOPS" % (time_ms, gflops / (time_ms / 1e3)))
+ print(f"{time_ms:f} ms, {gflops / (time_ms / 1e3):f} GOPS")
@tvm.testing.requires_hexagon
diff --git a/tests/python/contrib/test_hexagon/test_relax_integration.py b/tests/python/contrib/test_hexagon/test_relax_integration.py
index 688ea5ba3e..806ba58c59 100644
--- a/tests/python/contrib/test_hexagon/test_relax_integration.py
+++ b/tests/python/contrib/test_hexagon/test_relax_integration.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821
"""Relax hexagon test."""
import numpy as np
diff --git a/tests/python/contrib/test_hexagon/test_sigmoid.py b/tests/python/contrib/test_hexagon/test_sigmoid.py
index da6048c93c..ce5fba81dc 100644
--- a/tests/python/contrib/test_hexagon/test_sigmoid.py
+++ b/tests/python/contrib/test_hexagon/test_sigmoid.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
"""Sigmoid operator tests."""
import numpy as np
diff --git a/tests/python/contrib/test_hexagon/test_software_pipeline_async.py b/tests/python/contrib/test_hexagon/test_software_pipeline_async.py
index dfbfe5de28..270fc65b37 100644
--- a/tests/python/contrib/test_hexagon/test_software_pipeline_async.py
+++ b/tests/python/contrib/test_hexagon/test_software_pipeline_async.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Async software pipeline tests."""
import numpy as np
diff --git a/tests/python/contrib/test_hexagon/test_vtcm.py b/tests/python/contrib/test_hexagon/test_vtcm.py
index 13b4c00d20..56d9555fff 100644
--- a/tests/python/contrib/test_hexagon/test_vtcm.py
+++ b/tests/python/contrib/test_hexagon/test_vtcm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""VTCM Tests"""
import pytest
diff --git a/tests/python/contrib/test_hipblas.py b/tests/python/contrib/test_hipblas.py
index d285dd4549..baecb21384 100644
--- a/tests/python/contrib/test_hipblas.py
+++ b/tests/python/contrib/test_hipblas.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
import numpy as np
import tvm
diff --git a/tests/python/contrib/test_mps.py b/tests/python/contrib/test_mps.py
index 8c5b4746d6..418e4677f3 100644
--- a/tests/python/contrib/test_mps.py
+++ b/tests/python/contrib/test_mps.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741, F821
import numpy as np
import tvm
diff --git a/tests/python/contrib/test_msc/test_pipeline.py b/tests/python/contrib/test_msc/test_pipeline.py
index 88bac32798..e7d44fe90d 100644
--- a/tests/python/contrib/test_msc/test_pipeline.py
+++ b/tests/python/contrib/test_msc/test_pipeline.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""Test Pipeline in MSC."""
diff --git a/tests/python/contrib/test_msc/test_runner.py b/tests/python/contrib/test_msc/test_runner.py
index 175c14e6d1..0b53d00517 100644
--- a/tests/python/contrib/test_msc/test_runner.py
+++ b/tests/python/contrib/test_msc/test_runner.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""Test Runners in MSC."""
diff --git a/tests/python/contrib/test_msc/test_tools.py b/tests/python/contrib/test_msc/test_tools.py
index f7e284966d..59315b605d 100644
--- a/tests/python/contrib/test_msc/test_tools.py
+++ b/tests/python/contrib/test_msc/test_tools.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""Test Tools in MSC."""
diff --git a/tests/python/contrib/test_msc/test_transform.py b/tests/python/contrib/test_msc/test_transform.py
index 97a448c822..8c1c269bb8 100644
--- a/tests/python/contrib/test_msc/test_transform.py
+++ b/tests/python/contrib/test_msc/test_transform.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""Test MSC basic Pass."""
diff --git a/tests/python/contrib/test_popen_pool.py b/tests/python/contrib/test_popen_pool.py
index 7b38f3dfce..25a43b2c1b 100644
--- a/tests/python/contrib/test_popen_pool.py
+++ b/tests/python/contrib/test_popen_pool.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
"""Test PopenPoolExecutor."""
import os
diff --git a/tests/python/contrib/test_random.py b/tests/python/contrib/test_random.py
index acae6ed995..5457bab6f9 100644
--- a/tests/python/contrib/test_random.py
+++ b/tests/python/contrib/test_random.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E722
"""Configure pytest"""
# pylint: disable=invalid-name
@@ -35,7 +36,7 @@ def test_randint():
def verify(target="llvm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func("tvm.contrib.random.randint", True):
print("skip because extern function is not available")
@@ -60,7 +61,7 @@ def test_uniform():
def verify(target="llvm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func("tvm.contrib.random.uniform", True):
print("skip because extern function is not available")
@@ -85,7 +86,7 @@ def test_normal():
def verify(target="llvm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func("tvm.contrib.random.normal", True):
print("skip because extern function is not available")
diff --git a/tests/python/contrib/test_rocblas.py b/tests/python/contrib/test_rocblas.py
index efd77cffbc..250b9533b2 100644
--- a/tests/python/contrib/test_rocblas.py
+++ b/tests/python/contrib/test_rocblas.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""Configure pytest"""
# pylint: disable=invalid-name
@@ -68,7 +69,7 @@ def verify_batch_matmul(batch, m, k, n, lib, transa=False, transb=False, dtype="
def verify(target="rocm"):
if not tvm.testing.device_enabled(target):
- print("skip because %s is not enabled..." % target)
+ print(f"skip because {target} is not enabled...")
return
if not tvm.get_global_func(lib.__name__ + ".batch_matmul", True):
print("skip because extern function is not available")
diff --git a/tests/python/contrib/test_rpc_proxy.py b/tests/python/contrib/test_rpc_proxy.py
index 2dfff0a324..7395de6c84 100644
--- a/tests/python/contrib/test_rpc_proxy.py
+++ b/tests/python/contrib/test_rpc_proxy.py
@@ -48,7 +48,7 @@ def rpc_proxy_check():
return
server = multiprocessing.Process(
- target=proxy.websocket_proxy_server, args=("ws://localhost:%d/ws" % web_port, "x1")
+ target=proxy.websocket_proxy_server, args=(f"ws://localhost:{web_port}/ws", "x1")
)
# Need to make sure that the connection start after proxy comes up
time.sleep(0.1)
diff --git a/tests/python/contrib/test_sort.py b/tests/python/contrib/test_sort.py
index 9bcdce7cec..019af981f6 100644
--- a/tests/python/contrib/test_sort.py
+++ b/tests/python/contrib/test_sort.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""Configure pytest"""
# pylint: disable=invalid-name
diff --git a/tests/python/contrib/test_tir_triton_integration.py b/tests/python/contrib/test_tir_triton_integration.py
index 9ad613a98c..4a59d52bed 100644
--- a/tests/python/contrib/test_tir_triton_integration.py
+++ b/tests/python/contrib/test_tir_triton_integration.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import sys
import numpy as np
diff --git a/tests/python/contrib/test_util.py b/tests/python/contrib/test_util.py
index 4bfd8e863a..fa7fe2c562 100644
--- a/tests/python/contrib/test_util.py
+++ b/tests/python/contrib/test_util.py
@@ -26,7 +26,7 @@ from tvm.contrib import utils
def validate_debug_dir_path(temp_dir, expected_basename):
"""Validate the dir path of debugging"""
dirname, basename = os.path.split(temp_dir.temp_dir)
- assert basename == expected_basename, "unexpected basename: %s" % (basename,)
+ assert basename == expected_basename, f"unexpected basename: {basename}"
parent_dir = os.path.basename(dirname)
create_time = datetime.datetime.strptime(parent_dir.split("___", 1)[0], "%Y-%m-%dT%H-%M-%S")
diff --git a/tests/python/disco/test_loader.py b/tests/python/disco/test_loader.py
index 4d92ea357f..2d5bf130f7 100644
--- a/tests/python/disco/test_loader.py
+++ b/tests/python/disco/test_loader.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
"""Test sharded loader"""
# pylint: disable=missing-docstring
diff --git a/tests/python/disco/test_nvshmem.py b/tests/python/disco/test_nvshmem.py
index 45ab898ee8..7aa72fbef9 100644
--- a/tests/python/disco/test_nvshmem.py
+++ b/tests/python/disco/test_nvshmem.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
"""Basic tests for a Disco nvshmem support"""
# pylint: disable=missing-docstring
@@ -71,7 +72,7 @@ class SocketSessionTester:
cmd = "tvm.exec.disco_remote_socket_session"
self.remote_nodes = []
- for _ in range(num_nodes - 1):
+ for _i in range(num_nodes - 1):
self.remote_nodes.append(
subprocess.Popen(
[
diff --git a/tests/python/disco/test_session.py b/tests/python/disco/test_session.py
index 8d326ee993..b490cd0b04 100644
--- a/tests/python/disco/test_session.py
+++ b/tests/python/disco/test_session.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Basic tests for a Disco session"""
# pylint: disable=missing-docstring
@@ -83,7 +84,7 @@ class SocketSessionTester:
cmd = "tvm.exec.disco_remote_socket_session"
self.remote_nodes = []
- for _ in range(num_nodes - 1):
+ for _i in range(num_nodes - 1):
self.remote_nodes.append(
subprocess.Popen(
[
diff --git a/tests/python/ir/test_datatype_nv_fp4.py b/tests/python/ir/test_datatype_nv_fp4.py
index d237176e6c..da3098c4ae 100644
--- a/tests/python/ir/test_datatype_nv_fp4.py
+++ b/tests/python/ir/test_datatype_nv_fp4.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import numpy as np
import tvm
diff --git a/tests/python/ir/test_datatype_nv_fp8.py b/tests/python/ir/test_datatype_nv_fp8.py
index 9cc5ec6e6c..7e6b30d020 100644
--- a/tests/python/ir/test_datatype_nv_fp8.py
+++ b/tests/python/ir/test_datatype_nv_fp8.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401
import numpy as np
import tvm
diff --git a/tests/python/ir/test_dtype.py b/tests/python/ir/test_dtype.py
index 003bd3da10..158a9373de 100644
--- a/tests/python/ir/test_dtype.py
+++ b/tests/python/ir/test_dtype.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""Test data type related API"""
import pytest
diff --git a/tests/python/ir/test_ir_attrs.py b/tests/python/ir/test_ir_attrs.py
index 7c7400eab3..0d4fdcfb38 100644
--- a/tests/python/ir/test_ir_attrs.py
+++ b/tests/python/ir/test_ir_attrs.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
import tvm
diff --git a/tests/python/ir/test_ir_container.py b/tests/python/ir/test_ir_container.py
index 229125471c..6ece81e65a 100644
--- a/tests/python/ir/test_ir_container.py
+++ b/tests/python/ir/test_ir_container.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E712, F401
import numpy as np
import pytest
import tvm_ffi
diff --git a/tests/python/ir/test_ir_type.py b/tests/python/ir/test_ir_type.py
index c718c2289d..9170f33f6d 100644
--- a/tests/python/ir/test_ir_type.py
+++ b/tests/python/ir/test_ir_type.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E711, F401, F821
"""Test type nodes in the IR"""
import tvm
diff --git a/tests/python/ir/test_node_reflection.py b/tests/python/ir/test_node_reflection.py
index 8fca2cc862..8223f29348 100644
--- a/tests/python/ir/test_node_reflection.py
+++ b/tests/python/ir/test_node_reflection.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E712, F401, F841
import sys
import numpy as np
diff --git a/tests/python/ir/test_pass_instrument.py b/tests/python/ir/test_pass_instrument.py
index 36441f8049..96ff239c41 100644
--- a/tests/python/ir/test_pass_instrument.py
+++ b/tests/python/ir/test_pass_instrument.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
"""Instrument test cases."""
import tvm
diff --git a/tests/python/ir/test_roundtrip_runtime_module.py b/tests/python/ir/test_roundtrip_runtime_module.py
index fd25532eae..33bd1c11d1 100644
--- a/tests/python/ir/test_roundtrip_runtime_module.py
+++ b/tests/python/ir/test_roundtrip_runtime_module.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Test roundtrip of runtime modules"""
# pylint: disable=missing-docstring
diff --git a/tests/python/nightly/test_nnapi/conftest.py b/tests/python/nightly/test_nnapi/conftest.py
index 35fe0b4ecd..9c83c67c9f 100644
--- a/tests/python/nightly/test_nnapi/conftest.py
+++ b/tests/python/nightly/test_nnapi/conftest.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import os
diff --git a/tests/python/nightly/test_nnapi/infrastructure.py b/tests/python/nightly/test_nnapi/infrastructure.py
index 3833c2f673..ac3ddcd84e 100644
--- a/tests/python/nightly/test_nnapi/infrastructure.py
+++ b/tests/python/nightly/test_nnapi/infrastructure.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
import numpy as np
diff --git a/tests/python/nightly/test_nnapi/test_from_exported_to_cuda.py b/tests/python/nightly/test_nnapi/test_from_exported_to_cuda.py
index c7a991caef..37c7673aa0 100644
--- a/tests/python/nightly/test_nnapi/test_from_exported_to_cuda.py
+++ b/tests/python/nightly/test_nnapi/test_from_exported_to_cuda.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401
import numpy as np
import torch
diff --git a/tests/python/nightly/test_nnapi/test_ops.py b/tests/python/nightly/test_nnapi/test_ops.py
index b1c51466a7..3944b00012 100644
--- a/tests/python/nightly/test_nnapi/test_ops.py
+++ b/tests/python/nightly/test_nnapi/test_ops.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""NNAPI integration operator tests."""
from typing import List
diff --git a/tests/python/relax/adreno/test_transform_annotate_custom_scope.py b/tests/python/relax/adreno/test_transform_annotate_custom_scope.py
index f52e8d7edf..2352c5bd67 100644
--- a/tests/python/relax/adreno/test_transform_annotate_custom_scope.py
+++ b/tests/python/relax/adreno/test_transform_annotate_custom_scope.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/adreno/test_transform_fold_vdevice_scope_change.py b/tests/python/relax/adreno/test_transform_fold_vdevice_scope_change.py
index 72832c83cb..e85299d2f3 100644
--- a/tests/python/relax/adreno/test_transform_fold_vdevice_scope_change.py
+++ b/tests/python/relax/adreno/test_transform_fold_vdevice_scope_change.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/relax/backend/clml/conftest.py b/tests/python/relax/backend/clml/conftest.py
index e0d2e3da94..c4dede7e8a 100644
--- a/tests/python/relax/backend/clml/conftest.py
+++ b/tests/python/relax/backend/clml/conftest.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
import os
import sys
diff --git a/tests/python/relax/backend/clml/mod_utils.py b/tests/python/relax/backend/clml/mod_utils.py
index eb206c92a2..b24e3575c3 100644
--- a/tests/python/relax/backend/clml/mod_utils.py
+++ b/tests/python/relax/backend/clml/mod_utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
"""CLML integration operator tests."""
import json
diff --git a/tests/python/relax/backend/clml/test_clml_codegen.py b/tests/python/relax/backend/clml/test_clml_codegen.py
index 138b736128..2f20c41b4f 100644
--- a/tests/python/relax/backend/clml/test_clml_codegen.py
+++ b/tests/python/relax/backend/clml/test_clml_codegen.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
"""CLML integration operator tests."""
import json
diff --git a/tests/python/relax/backend/clml/test_op_exec_clml_codegen.py b/tests/python/relax/backend/clml/test_op_exec_clml_codegen.py
index ec206bd978..3ed142ba3b 100644
--- a/tests/python/relax/backend/clml/test_op_exec_clml_codegen.py
+++ b/tests/python/relax/backend/clml/test_op_exec_clml_codegen.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
"""CLML integration operator tests."""
import json
diff --git a/tests/python/relax/backend/clml/utils.py b/tests/python/relax/backend/clml/utils.py
index b93c7810a2..1dd9c4cccf 100644
--- a/tests/python/relax/backend/clml/utils.py
+++ b/tests/python/relax/backend/clml/utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F811, F841
"""Run utils for CLML integration operator tests"""
import copy
diff --git a/tests/python/relax/distributed/test_distributed_dtensor_sinfo.py b/tests/python/relax/distributed/test_distributed_dtensor_sinfo.py
index 1c87880325..795b365c01 100644
--- a/tests/python/relax/distributed/test_distributed_dtensor_sinfo.py
+++ b/tests/python/relax/distributed/test_distributed_dtensor_sinfo.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import pytest
diff --git a/tests/python/relax/distributed/test_distributed_transform_lower_distir.py b/tests/python/relax/distributed/test_distributed_transform_lower_distir.py
index a8a9690e20..5cde0d86cc 100644
--- a/tests/python/relax/distributed/test_distributed_transform_lower_distir.py
+++ b/tests/python/relax/distributed/test_distributed_transform_lower_distir.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
# type: ignore
import tvm
diff --git a/tests/python/relax/distributed/test_distributed_transform_lower_global_to_local_view.py b/tests/python/relax/distributed/test_distributed_transform_lower_global_to_local_view.py
index 7b193f946b..0af564405b 100644
--- a/tests/python/relax/distributed/test_distributed_transform_lower_global_to_local_view.py
+++ b/tests/python/relax/distributed/test_distributed_transform_lower_global_to_local_view.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
# type: ignore
import tvm
diff --git a/tests/python/relax/distributed/test_distributed_transform_propagate_sharding.py b/tests/python/relax/distributed/test_distributed_transform_propagate_sharding.py
index 5ca0fd946d..ea797d1584 100644
--- a/tests/python/relax/distributed/test_distributed_transform_propagate_sharding.py
+++ b/tests/python/relax/distributed/test_distributed_transform_propagate_sharding.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
# type: ignore
diff --git a/tests/python/relax/distributed/test_distributed_tvmscript_parser.py b/tests/python/relax/distributed/test_distributed_tvmscript_parser.py
index c4d6b76517..7deef9c7d3 100644
--- a/tests/python/relax/distributed/test_distributed_tvmscript_parser.py
+++ b/tests/python/relax/distributed/test_distributed_tvmscript_parser.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
from typing import Optional, Union
diff --git a/tests/python/relax/distributed/test_distributed_tvmscript_printer.py b/tests/python/relax/distributed/test_distributed_tvmscript_printer.py
index 15cdb801a0..47daadb314 100644
--- a/tests/python/relax/distributed/test_distributed_tvmscript_printer.py
+++ b/tests/python/relax/distributed/test_distributed_tvmscript_printer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import tvm.testing
from tvm.ir import Range
diff --git a/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer.py b/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer.py
index aef1848d41..2bf58576a8 100644
--- a/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer.py
+++ b/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E741, F401
import enum
import itertools
from typing import Dict, List, Optional, Tuple, Union
diff --git a/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer_kernel.py b/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer_kernel.py
index 56842de8c2..e55971acfb 100644
--- a/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer_kernel.py
+++ b/tests/python/relax/nvshmem/test_runtime_builtin_kv_cache_transfer_kernel.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import numpy as np
import pytest
diff --git a/tests/python/relax/test_analysis.py b/tests/python/relax/test_analysis.py
index 08d0ad24d9..f9747b2844 100644
--- a/tests/python/relax/test_analysis.py
+++ b/tests/python/relax/test_analysis.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F811, F841
from typing import List, Set, Union
diff --git a/tests/python/relax/test_analysis_computable_at_compile_time.py b/tests/python/relax/test_analysis_computable_at_compile_time.py
index 9c323ffeff..d1160642b1 100644
--- a/tests/python/relax/test_analysis_computable_at_compile_time.py
+++ b/tests/python/relax/test_analysis_computable_at_compile_time.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
from typing import List
diff --git a/tests/python/relax/test_analysis_contains_impure_call.py b/tests/python/relax/test_analysis_contains_impure_call.py
index f82022fd94..51de60544d 100644
--- a/tests/python/relax/test_analysis_contains_impure_call.py
+++ b/tests/python/relax/test_analysis_contains_impure_call.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_analysis_estimate_memory_usage.py b/tests/python/relax/test_analysis_estimate_memory_usage.py
index 2ab9c61797..5f65b0670f 100644
--- a/tests/python/relax/test_analysis_estimate_memory_usage.py
+++ b/tests/python/relax/test_analysis_estimate_memory_usage.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_analysis_struct_info_analysis.py b/tests/python/relax/test_analysis_struct_info_analysis.py
index c9e44775de..b539a4c32a 100644
--- a/tests/python/relax/test_analysis_struct_info_analysis.py
+++ b/tests/python/relax/test_analysis_struct_info_analysis.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731, F401, F841
"""Tests analysis functions of struct info"""
@@ -355,7 +356,7 @@ def _check_derive(ctx, finfo, args_sinfo, ret):
rx.expr._update_struct_info(gv, finfo)
args = []
for i, sinfo in enumerate(args_sinfo):
- arg = rx.Var("arg%i" % i, sinfo)
+ arg = rx.Var(f"arg{i}", sinfo)
args.append(arg)
call = rx.Call(gv, args)
derived_ret = rx.analysis.derive_call_ret_struct_info(finfo, call, ctx)
diff --git a/tests/python/relax/test_analysis_suggest_layout_transforms.py b/tests/python/relax/test_analysis_suggest_layout_transforms.py
index eeee1b4be4..e09cc9c580 100644
--- a/tests/python/relax/test_analysis_suggest_layout_transforms.py
+++ b/tests/python/relax/test_analysis_suggest_layout_transforms.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
import pytest
diff --git a/tests/python/relax/test_analysis_well_formed.py b/tests/python/relax/test_analysis_well_formed.py
index 73aac39f88..9ce65efe48 100644
--- a/tests/python/relax/test_analysis_well_formed.py
+++ b/tests/python/relax/test_analysis_well_formed.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F811, RUF005
import pytest
diff --git a/tests/python/relax/test_ast_printer.py b/tests/python/relax/test_ast_printer.py
index fd4f62a4a0..d6e496c3f1 100644
--- a/tests/python/relax/test_ast_printer.py
+++ b/tests/python/relax/test_ast_printer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F811, F841
import re
from functools import partial
from typing import Dict
diff --git a/tests/python/relax/test_backend_dispatch_sampling.py b/tests/python/relax/test_backend_dispatch_sampling.py
index f06a6a66b9..1b61d85d79 100644
--- a/tests/python/relax/test_backend_dispatch_sampling.py
+++ b/tests/python/relax/test_backend_dispatch_sampling.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring
+# ruff: noqa: E501
import tvm
import tvm.script
diff --git a/tests/python/relax/test_backend_dispatch_sort_scan.py b/tests/python/relax/test_backend_dispatch_sort_scan.py
index 9f3e961231..dd5a65b8ec 100644
--- a/tests/python/relax/test_backend_dispatch_sort_scan.py
+++ b/tests/python/relax/test_backend_dispatch_sort_scan.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
import pytest
diff --git a/tests/python/relax/test_backend_transform_shape_lower.py b/tests/python/relax/test_backend_transform_shape_lower.py
index 95d0f2bf3f..2f5cef99d8 100644
--- a/tests/python/relax/test_backend_transform_shape_lower.py
+++ b/tests/python/relax/test_backend_transform_shape_lower.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm.script
import tvm.testing
diff --git a/tests/python/relax/test_base_py_module.py b/tests/python/relax/test_base_py_module.py
index e8b7d790fc..a13c6be9a2 100644
--- a/tests/python/relax/test_base_py_module.py
+++ b/tests/python/relax/test_base_py_module.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""
Test BasePyModule core functionality.
diff --git a/tests/python/relax/test_base_py_module_printer.py b/tests/python/relax/test_base_py_module_printer.py
index a6816ab02b..951b56ab35 100644
--- a/tests/python/relax/test_base_py_module_printer.py
+++ b/tests/python/relax/test_base_py_module_printer.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring, invalid-name, unused-argument
+# ruff: noqa: F401, F841
import pytest
diff --git a/tests/python/relax/test_base_py_module_symbolic_shape.py b/tests/python/relax/test_base_py_module_symbolic_shape.py
index 6a6e825600..fd6331b5cb 100644
--- a/tests/python/relax/test_base_py_module_symbolic_shape.py
+++ b/tests/python/relax/test_base_py_module_symbolic_shape.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
import numpy as np
import pytest
diff --git a/tests/python/relax/test_bind_symbolic_vars.py b/tests/python/relax/test_bind_symbolic_vars.py
index b82ae3e134..1113410eaf 100644
--- a/tests/python/relax/test_bind_symbolic_vars.py
+++ b/tests/python/relax/test_bind_symbolic_vars.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
import pytest
diff --git a/tests/python/relax/test_binding_rewrite.py b/tests/python/relax/test_binding_rewrite.py
index 1f106122e4..b7faad31da 100644
--- a/tests/python/relax/test_binding_rewrite.py
+++ b/tests/python/relax/test_binding_rewrite.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
diff --git a/tests/python/relax/test_blockbuilder_core.py b/tests/python/relax/test_blockbuilder_core.py
index 93359488e6..6bfdf8ad27 100644
--- a/tests/python/relax/test_blockbuilder_core.py
+++ b/tests/python/relax/test_blockbuilder_core.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
"""Block builder unit test"""
# The test here do not depend on tvmscript to cover most basic features
diff --git a/tests/python/relax/test_codegen_cublas.py b/tests/python/relax/test_codegen_cublas.py
index 37a60455eb..b736f790fd 100644
--- a/tests/python/relax/test_codegen_cublas.py
+++ b/tests/python/relax/test_codegen_cublas.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
import numpy as np
import pytest
diff --git a/tests/python/relax/test_codegen_cudnn.py b/tests/python/relax/test_codegen_cudnn.py
index d40a3c9256..e5c28a76e9 100644
--- a/tests/python/relax/test_codegen_cudnn.py
+++ b/tests/python/relax/test_codegen_cudnn.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821, F841
import numpy as np
import pytest
diff --git a/tests/python/relax/test_codegen_cutlass.py b/tests/python/relax/test_codegen_cutlass.py
index a25239c4e5..acc1aace82 100644
--- a/tests/python/relax/test_codegen_cutlass.py
+++ b/tests/python/relax/test_codegen_cutlass.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841, RUF005
import numpy as np
import pytest
diff --git a/tests/python/relax/test_codegen_tensorrt.py b/tests/python/relax/test_codegen_tensorrt.py
index 9279fa0311..b8bae635b3 100644
--- a/tests/python/relax/test_codegen_tensorrt.py
+++ b/tests/python/relax/test_codegen_tensorrt.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
import numpy as np
import pytest
diff --git a/tests/python/relax/test_contrib_vllm.py b/tests/python/relax/test_contrib_vllm.py
index 3355e5fab4..d5b5002482 100644
--- a/tests/python/relax/test_contrib_vllm.py
+++ b/tests/python/relax/test_contrib_vllm.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
import numpy as np
import pytest
diff --git a/tests/python/relax/test_dataflow_inplace.py b/tests/python/relax/test_dataflow_inplace.py
index a713160c50..7fcc0e48e7 100644
--- a/tests/python/relax/test_dataflow_inplace.py
+++ b/tests/python/relax/test_dataflow_inplace.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
from typing import List, Set, Tuple
diff --git a/tests/python/relax/test_dataflow_pattern.py b/tests/python/relax/test_dataflow_pattern.py
index 1d2a6e4676..11d3094ef4 100644
--- a/tests/python/relax/test_dataflow_pattern.py
+++ b/tests/python/relax/test_dataflow_pattern.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F403, F405, F841
import functools
import math
diff --git a/tests/python/relax/test_dataflow_rewriter.py b/tests/python/relax/test_dataflow_rewriter.py
index cd4fa6d41f..e591ee4dc4 100644
--- a/tests/python/relax/test_dataflow_rewriter.py
+++ b/tests/python/relax/test_dataflow_rewriter.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
diff --git a/tests/python/relax/test_dlpack_integration.py b/tests/python/relax/test_dlpack_integration.py
index 3614be3d80..4c038678b5 100644
--- a/tests/python/relax/test_dlpack_integration.py
+++ b/tests/python/relax/test_dlpack_integration.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F811, F841
"""
Test DLPack integration between PyTorch and TVM.
diff --git a/tests/python/relax/test_e2e_op_dynamic.py b/tests/python/relax/test_e2e_op_dynamic.py
index 280d2a1d91..a3637ad7ac 100644
--- a/tests/python/relax/test_e2e_op_dynamic.py
+++ b/tests/python/relax/test_e2e_op_dynamic.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
import numpy as np
import pytest
diff --git a/tests/python/relax/test_eliminate_pad_branch_using_buffer_assumption.py b/tests/python/relax/test_eliminate_pad_branch_using_buffer_assumption.py
index 11e7bf59c8..ecc96a6cbf 100644
--- a/tests/python/relax/test_eliminate_pad_branch_using_buffer_assumption.py
+++ b/tests/python/relax/test_eliminate_pad_branch_using_buffer_assumption.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring, unused-variable
+# ruff: noqa: F841
# The test attempts to eliminate redundant pad branch and overcompute the value for elementwise ops.
# This helps to expose more opportunities to vectorize the code.
diff --git a/tests/python/relax/test_expr.py b/tests/python/relax/test_expr.py
index 1c39aec94f..4c64013061 100644
--- a/tests/python/relax/test_expr.py
+++ b/tests/python/relax/test_expr.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F811
import numpy as np
import pytest
diff --git a/tests/python/relax/test_expr_args_converter.py b/tests/python/relax/test_expr_args_converter.py
index 3eb5b20dfe..5e8cfd434d 100644
--- a/tests/python/relax/test_expr_args_converter.py
+++ b/tests/python/relax/test_expr_args_converter.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731
from typing import Any, Callable, List, Optional, Union
diff --git a/tests/python/relax/test_expr_functor.py b/tests/python/relax/test_expr_functor.py
index 67f72d96ed..cf6da59e70 100644
--- a/tests/python/relax/test_expr_functor.py
+++ b/tests/python/relax/test_expr_functor.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import pytest
import tvm
diff --git a/tests/python/relax/test_fast_math_transform.py b/tests/python/relax/test_fast_math_transform.py
index 36775b7612..311e1dd36c 100644
--- a/tests/python/relax/test_fast_math_transform.py
+++ b/tests/python/relax/test_fast_math_transform.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Tests to validate relax fast math tranform pass."""
import pytest
diff --git a/tests/python/relax/test_frontend_dynamo.py b/tests/python/relax/test_frontend_dynamo.py
index 47dfd87f57..3e27762eb2 100644
--- a/tests/python/relax/test_frontend_dynamo.py
+++ b/tests/python/relax/test_frontend_dynamo.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F811
import pytest
pytest.importorskip("torch._dynamo")
diff --git a/tests/python/relax/test_frontend_from_exported_program.py b/tests/python/relax/test_frontend_from_exported_program.py
index ea807729d6..0b5cb1f777 100644
--- a/tests/python/relax/test_frontend_from_exported_program.py
+++ b/tests/python/relax/test_frontend_from_exported_program.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
import operator
import numpy as np
diff --git a/tests/python/relax/test_frontend_from_fx.py b/tests/python/relax/test_frontend_from_fx.py
index c527409fac..91ec5223f9 100644
--- a/tests/python/relax/test_frontend_from_fx.py
+++ b/tests/python/relax/test_frontend_from_fx.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import math
import operator
diff --git a/tests/python/relax/test_frontend_nn_extern_module.py b/tests/python/relax/test_frontend_nn_extern_module.py
index 5c2a55b920..d8c59adb31 100644
--- a/tests/python/relax/test_frontend_nn_extern_module.py
+++ b/tests/python/relax/test_frontend_nn_extern_module.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring
+# ruff: noqa: F401
import subprocess
import tempfile
from pathlib import Path
diff --git a/tests/python/relax/test_frontend_nn_modules.py b/tests/python/relax/test_frontend_nn_modules.py
index 09ef8fe99e..80073dcaa6 100644
--- a/tests/python/relax/test_frontend_nn_modules.py
+++ b/tests/python/relax/test_frontend_nn_modules.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
from typing import List, Tuple
import numpy as np
diff --git a/tests/python/relax/test_frontend_nn_op.py b/tests/python/relax/test_frontend_nn_op.py
index 8c9723838c..7675f46fc4 100644
--- a/tests/python/relax/test_frontend_nn_op.py
+++ b/tests/python/relax/test_frontend_nn_op.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring, invalid-name
+# ruff: noqa: E501, F841
import numpy as np
import tvm
diff --git a/tests/python/relax/test_frontend_nn_tensor.py b/tests/python/relax/test_frontend_nn_tensor.py
index bd96626c95..f04fa77051 100644
--- a/tests/python/relax/test_frontend_nn_tensor.py
+++ b/tests/python/relax/test_frontend_nn_tensor.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401
import numpy as np
import pytest
diff --git a/tests/python/relax/test_frontend_onnx.py b/tests/python/relax/test_frontend_onnx.py
index ecaeb05a60..dff9a36aa7 100644
--- a/tests/python/relax/test_frontend_onnx.py
+++ b/tests/python/relax/test_frontend_onnx.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-argument
+# ruff: noqa: E501, F841
"""
ONNX testcases
================
diff --git a/tests/python/relax/test_frontend_stablehlo.py b/tests/python/relax/test_frontend_stablehlo.py
index 4cd12cd4d1..398997fd63 100644
--- a/tests/python/relax/test_frontend_stablehlo.py
+++ b/tests/python/relax/test_frontend_stablehlo.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
# pylint: disable=c-extension-no-member
diff --git a/tests/python/relax/test_group_gemm_flashinfer.py b/tests/python/relax/test_group_gemm_flashinfer.py
index 31bf24dad5..39ae8d5a30 100644
--- a/tests/python/relax/test_group_gemm_flashinfer.py
+++ b/tests/python/relax/test_group_gemm_flashinfer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E722, F401, F841, RUF005
"""Test for FlashInfer GroupedGemm TVM integration"""
diff --git a/tests/python/relax/test_inline_functions.py b/tests/python/relax/test_inline_functions.py
index 976f79420c..73d402e124 100644
--- a/tests/python/relax/test_inline_functions.py
+++ b/tests/python/relax/test_inline_functions.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import pytest
@@ -54,9 +55,9 @@ def test_inline_simple(key_type):
return D
gvar = Before.get_global_var("subroutine")
- if key_type == tvm.ir.GlobalVar:
+ if key_type is tvm.ir.GlobalVar:
key = gvar
- elif key_type == str:
+ elif key_type is str:
key = gvar.name_hint
else:
raise TypeError(f"Unknown key_type: {key_type}")
diff --git a/tests/python/relax/test_meta_schedule_relax_integration.py b/tests/python/relax/test_meta_schedule_relax_integration.py
index 6dd51563e4..76af1473d9 100644
--- a/tests/python/relax/test_meta_schedule_relax_integration.py
+++ b/tests/python/relax/test_meta_schedule_relax_integration.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
"""Integration test for MetaSchedule"""
import tvm
diff --git a/tests/python/relax/test_op_binary.py b/tests/python/relax/test_op_binary.py
index 26bf966a06..25d32249c5 100644
--- a/tests/python/relax/test_op_binary.py
+++ b/tests/python/relax/test_op_binary.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
from typing import Callable
import pytest
diff --git a/tests/python/relax/test_op_ccl.py b/tests/python/relax/test_op_ccl.py
index 5a0512acc6..c114653d32 100644
--- a/tests/python/relax/test_op_ccl.py
+++ b/tests/python/relax/test_op_ccl.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import pytest
import tvm
diff --git a/tests/python/relax/test_op_gradient_numeric.py b/tests/python/relax/test_op_gradient_numeric.py
index 0f2b373dde..4e9e8842ba 100644
--- a/tests/python/relax/test_op_gradient_numeric.py
+++ b/tests/python/relax/test_op_gradient_numeric.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F811, RUF005
from typing import Callable, List, Tuple, Union
import numpy as np
diff --git a/tests/python/relax/test_op_index.py b/tests/python/relax/test_op_index.py
index f5053fd8da..7688cc9f4b 100644
--- a/tests/python/relax/test_op_index.py
+++ b/tests/python/relax/test_op_index.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E741
import numpy as np
import pytest
diff --git a/tests/python/relax/test_op_inspect.py b/tests/python/relax/test_op_inspect.py
index 2e6d81c613..072cfb9289 100644
--- a/tests/python/relax/test_op_inspect.py
+++ b/tests/python/relax/test_op_inspect.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import ctypes
diff --git a/tests/python/relax/test_op_linear_algebra.py b/tests/python/relax/test_op_linear_algebra.py
index dd094fcbb2..a08a27ff5f 100644
--- a/tests/python/relax/test_op_linear_algebra.py
+++ b/tests/python/relax/test_op_linear_algebra.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
import tvm
diff --git a/tests/python/relax/test_op_manipulate.py b/tests/python/relax/test_op_manipulate.py
index c195d4082c..a86a8127b1 100644
--- a/tests/python/relax/test_op_manipulate.py
+++ b/tests/python/relax/test_op_manipulate.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731, F841
import pytest
import tvm
diff --git a/tests/python/relax/test_op_misc.py b/tests/python/relax/test_op_misc.py
index 1507960445..2e652b7c38 100644
--- a/tests/python/relax/test_op_misc.py
+++ b/tests/python/relax/test_op_misc.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
from tvm import relax as rx
@@ -58,7 +59,7 @@ def test_call_tir_with_grad():
)
assert v2.attrs.te_grad_name == "identity_k_grad"
assert isinstance(v2.attrs.te_grad_kwargs, tvm.ir.container.Map)
- val = list(v2.attrs.te_grad_kwargs.items())[0]
+ val = next(iter(v2.attrs.te_grad_kwargs.items()))
assert val[0] == "k" and float(val[1]) == 1.0
diff --git a/tests/python/relax/test_op_nn.py b/tests/python/relax/test_op_nn.py
index 4c419ed0e1..574c7ec3e4 100644
--- a/tests/python/relax/test_op_nn.py
+++ b/tests/python/relax/test_op_nn.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
import tvm
diff --git a/tests/python/relax/test_op_nn_pooling.py b/tests/python/relax/test_op_nn_pooling.py
index efed23ba16..1e69817c0f 100644
--- a/tests/python/relax/test_op_nn_pooling.py
+++ b/tests/python/relax/test_op_nn_pooling.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741, F841
import pytest
import tvm
diff --git a/tests/python/relax/test_optimize_layout_transform.py b/tests/python/relax/test_optimize_layout_transform.py
index 7dd57d0709..046fb789a6 100644
--- a/tests/python/relax/test_optimize_layout_transform.py
+++ b/tests/python/relax/test_optimize_layout_transform.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Tests to validate relax optimize layout tranform pass."""
import numpy as np
diff --git a/tests/python/relax/test_pytorch_integration.py b/tests/python/relax/test_pytorch_integration.py
index 3178404c3c..2eb6dfc9b9 100644
--- a/tests/python/relax/test_pytorch_integration.py
+++ b/tests/python/relax/test_pytorch_integration.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""
Test PyTorch integration with TVM Relax.
diff --git a/tests/python/relax/test_relax_operators.py b/tests/python/relax/test_relax_operators.py
index 2a8fdf40f0..192f89e399 100644
--- a/tests/python/relax/test_relax_operators.py
+++ b/tests/python/relax/test_relax_operators.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
import sys
import tempfile
diff --git a/tests/python/relax/test_relax_to_pyfunc_converter.py b/tests/python/relax/test_relax_to_pyfunc_converter.py
index 50a07bd812..a223ef15c2 100644
--- a/tests/python/relax/test_relax_to_pyfunc_converter.py
+++ b/tests/python/relax/test_relax_to_pyfunc_converter.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""
Comprehensive test cases for Relax to PyFunc converter.
diff --git a/tests/python/relax/test_remove_redundant_reshape.py b/tests/python/relax/test_remove_redundant_reshape.py
index f0f361be33..f5a865940b 100644
--- a/tests/python/relax/test_remove_redundant_reshape.py
+++ b/tests/python/relax/test_remove_redundant_reshape.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""
Test relax transform - Eliminate redundant reshape operations
diff --git a/tests/python/relax/test_runtime_builtin.py b/tests/python/relax/test_runtime_builtin.py
index 3e627a2dbc..65642c4cce 100644
--- a/tests/python/relax/test_runtime_builtin.py
+++ b/tests/python/relax/test_runtime_builtin.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import numpy as np
import pytest
diff --git a/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_cpu.py b/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_cpu.py
index 0e4cbf2cc3..19eacfa67c 100644
--- a/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_cpu.py
+++ b/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_cpu.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E741
import enum
import itertools
from typing import Dict, List, Optional, Tuple, Union
diff --git a/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_flashinfer.py b/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_flashinfer.py
index 211ec4c547..68f9035f23 100644
--- a/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_flashinfer.py
+++ b/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_flashinfer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
from typing import Dict, List, Tuple, Union
import pytest
diff --git a/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_tir.py b/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_tir.py
index e39fe5968a..85714199f6 100644
--- a/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_tir.py
+++ b/tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_tir.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E741
import itertools
from typing import Dict, List, Optional, Tuple, Union
diff --git a/tests/python/relax/test_runtime_sampling_flashinfer.py b/tests/python/relax/test_runtime_sampling_flashinfer.py
index dca29a9880..b29eb7c0a2 100644
--- a/tests/python/relax/test_runtime_sampling_flashinfer.py
+++ b/tests/python/relax/test_runtime_sampling_flashinfer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import random
diff --git a/tests/python/relax/test_testing_nn.py b/tests/python/relax/test_testing_nn.py
index f14de9d83a..036d272031 100644
--- a/tests/python/relax/test_testing_nn.py
+++ b/tests/python/relax/test_testing_nn.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, RUF005
import tvm
import tvm.testing
from tvm import relax
diff --git a/tests/python/relax/test_training_append_loss.py b/tests/python/relax/test_training_append_loss.py
index c245db4696..eff93570a6 100644
--- a/tests/python/relax/test_training_append_loss.py
+++ b/tests/python/relax/test_training_append_loss.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import pytest
import tvm.testing
diff --git a/tests/python/relax/test_training_setup_trainer.py b/tests/python/relax/test_training_setup_trainer.py
index bf1e347771..a9343ca417 100644
--- a/tests/python/relax/test_training_setup_trainer.py
+++ b/tests/python/relax/test_training_setup_trainer.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import pytest
import tvm
diff --git a/tests/python/relax/test_transform.py b/tests/python/relax/test_transform.py
index 09bb34eef6..8beca9ef0c 100644
--- a/tests/python/relax/test_transform.py
+++ b/tests/python/relax/test_transform.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
diff --git a/tests/python/relax/test_transform_alter_op_impl.py b/tests/python/relax/test_transform_alter_op_impl.py
index 05e744ee79..39c278575a 100644
--- a/tests/python/relax/test_transform_alter_op_impl.py
+++ b/tests/python/relax/test_transform_alter_op_impl.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E731, F401, F841
import pytest
diff --git a/tests/python/relax/test_transform_attach_attr_layout_free_buffers.py b/tests/python/relax/test_transform_attach_attr_layout_free_buffers.py
index 6bc4f499d9..36be33f159 100644
--- a/tests/python/relax/test_transform_attach_attr_layout_free_buffers.py
+++ b/tests/python/relax/test_transform_attach_attr_layout_free_buffers.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import numpy as np
import tvm.testing
diff --git a/tests/python/relax/test_transform_attach_global_symbol.py b/tests/python/relax/test_transform_attach_global_symbol.py
index 4cc619aff0..ad6800d55f 100644
--- a/tests/python/relax/test_transform_attach_global_symbol.py
+++ b/tests/python/relax/test_transform_attach_global_symbol.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
import pytest
diff --git a/tests/python/relax/test_transform_bind_params.py b/tests/python/relax/test_transform_bind_params.py
index 47b48e8048..6742a01749 100644
--- a/tests/python/relax/test_transform_bind_params.py
+++ b/tests/python/relax/test_transform_bind_params.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
diff --git a/tests/python/relax/test_transform_bundle_model_params.py b/tests/python/relax/test_transform_bundle_model_params.py
index bf0fd65b51..942c99976c 100644
--- a/tests/python/relax/test_transform_bundle_model_params.py
+++ b/tests/python/relax/test_transform_bundle_model_params.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_canonicalize_bindings.py b/tests/python/relax/test_transform_canonicalize_bindings.py
index f68be2ce25..d341625e9b 100644
--- a/tests/python/relax/test_transform_canonicalize_bindings.py
+++ b/tests/python/relax/test_transform_canonicalize_bindings.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741, F841
import pytest
diff --git a/tests/python/relax/test_transform_codegen_pass.py b/tests/python/relax/test_transform_codegen_pass.py
index 5097a5c064..6e5bbdd729 100644
--- a/tests/python/relax/test_transform_codegen_pass.py
+++ b/tests/python/relax/test_transform_codegen_pass.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, RUF005
import os
import tempfile
diff --git a/tests/python/relax/test_transform_combine_parallel_matmul.py b/tests/python/relax/test_transform_combine_parallel_matmul.py
index c54b1fdf08..2b14aa335b 100644
--- a/tests/python/relax/test_transform_combine_parallel_matmul.py
+++ b/tests/python/relax/test_transform_combine_parallel_matmul.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731, F401, F841
import tvm.testing
from tvm import relax, tir
from tvm.relax.transform import CombineParallelMatmul
diff --git a/tests/python/relax/test_transform_convert_dataflow.py b/tests/python/relax/test_transform_convert_dataflow.py
index 642c0747b6..da50a6bad4 100644
--- a/tests/python/relax/test_transform_convert_dataflow.py
+++ b/tests/python/relax/test_transform_convert_dataflow.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
from tvm import relax
diff --git a/tests/python/relax/test_transform_convert_layout.py b/tests/python/relax/test_transform_convert_layout.py
index bef49f4551..29871b550e 100644
--- a/tests/python/relax/test_transform_convert_layout.py
+++ b/tests/python/relax/test_transform_convert_layout.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_cse.py b/tests/python/relax/test_transform_cse.py
index 9674f7b127..ac3894e00e 100644
--- a/tests/python/relax/test_transform_cse.py
+++ b/tests/python/relax/test_transform_cse.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""Test eliminate common subexpr pass"""
import numpy as np
diff --git a/tests/python/relax/test_transform_dead_code_elimination.py b/tests/python/relax/test_transform_dead_code_elimination.py
index d5c0f4b1d0..db9f194bd2 100644
--- a/tests/python/relax/test_transform_dead_code_elimination.py
+++ b/tests/python/relax/test_transform_dead_code_elimination.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
import pytest
diff --git a/tests/python/relax/test_transform_decompose_ops.py b/tests/python/relax/test_transform_decompose_ops.py
index 2d2ea631e4..599a1d28f2 100644
--- a/tests/python/relax/test_transform_decompose_ops.py
+++ b/tests/python/relax/test_transform_decompose_ops.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
from typing import Union
diff --git a/tests/python/relax/test_transform_expand_tuple_args.py b/tests/python/relax/test_transform_expand_tuple_args.py
index 35b99872c8..f5389cacb6 100644
--- a/tests/python/relax/test_transform_expand_tuple_args.py
+++ b/tests/python/relax/test_transform_expand_tuple_args.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_few_shot_tuning.py b/tests/python/relax/test_transform_few_shot_tuning.py
index 10f6a0a79f..4d79a9c40d 100644
--- a/tests/python/relax/test_transform_few_shot_tuning.py
+++ b/tests/python/relax/test_transform_few_shot_tuning.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name,,missing-function-docstring
+# ruff: noqa: E501, F403
from typing import List, Tuple
import numpy as np
diff --git a/tests/python/relax/test_transform_fold_batch_norm_to_conv2d.py b/tests/python/relax/test_transform_fold_batch_norm_to_conv2d.py
index 284ab8018d..be2dcace3b 100644
--- a/tests/python/relax/test_transform_fold_batch_norm_to_conv2d.py
+++ b/tests/python/relax/test_transform_fold_batch_norm_to_conv2d.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import numpy as np
import pytest
diff --git a/tests/python/relax/test_transform_fold_constant.py b/tests/python/relax/test_transform_fold_constant.py
index f581053464..d529fd5ff6 100644
--- a/tests/python/relax/test_transform_fold_constant.py
+++ b/tests/python/relax/test_transform_fold_constant.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
import tvm
diff --git a/tests/python/relax/test_transform_fuse_ops.py b/tests/python/relax/test_transform_fuse_ops.py
index 5a0f61a53c..e7dbe98b02 100644
--- a/tests/python/relax/test_transform_fuse_ops.py
+++ b/tests/python/relax/test_transform_fuse_ops.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_fuse_ops_by_pattern.py b/tests/python/relax/test_transform_fuse_ops_by_pattern.py
index f1b7c28081..b684e43e6b 100644
--- a/tests/python/relax/test_transform_fuse_ops_by_pattern.py
+++ b/tests/python/relax/test_transform_fuse_ops_by_pattern.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E741, F841
import numpy as np
import pytest
diff --git a/tests/python/relax/test_transform_gradient.py b/tests/python/relax/test_transform_gradient.py
index b976f0a359..8b440666d0 100644
--- a/tests/python/relax/test_transform_gradient.py
+++ b/tests/python/relax/test_transform_gradient.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import numpy as np
import pytest
diff --git a/tests/python/relax/test_transform_gradient_checkpoint.py b/tests/python/relax/test_transform_gradient_checkpoint.py
index 9cb4aa1a16..7797f6d8f6 100644
--- a/tests/python/relax/test_transform_gradient_checkpoint.py
+++ b/tests/python/relax/test_transform_gradient_checkpoint.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F811
"""Unit tests for gradient with checkpointing."""
import tvm
diff --git a/tests/python/relax/test_transform_gradient_numeric.py b/tests/python/relax/test_transform_gradient_numeric.py
index 4dc65c29ac..ad4b88e5f8 100644
--- a/tests/python/relax/test_transform_gradient_numeric.py
+++ b/tests/python/relax/test_transform_gradient_numeric.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E741
import numpy as np
import tvm
diff --git a/tests/python/relax/test_transform_gradient_te_register.py b/tests/python/relax/test_transform_gradient_te_register.py
index f518db52b8..db42ddbbf3 100644
--- a/tests/python/relax/test_transform_gradient_te_register.py
+++ b/tests/python/relax/test_transform_gradient_te_register.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
"""Unit tests for registering tir gradient functions in the gradient pass."""
import pytest
diff --git a/tests/python/relax/test_transform_inline_private_functions.py b/tests/python/relax/test_transform_inline_private_functions.py
index 21321ebc0a..41302d53c9 100644
--- a/tests/python/relax/test_transform_inline_private_functions.py
+++ b/tests/python/relax/test_transform_inline_private_functions.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import pytest
diff --git a/tests/python/relax/test_transform_lambda_lift.py b/tests/python/relax/test_transform_lambda_lift.py
index 3db263d239..7fdca378d6 100644
--- a/tests/python/relax/test_transform_lambda_lift.py
+++ b/tests/python/relax/test_transform_lambda_lift.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.script
diff --git a/tests/python/relax/test_transform_lazy_transform_params.py b/tests/python/relax/test_transform_lazy_transform_params.py
index abd095f5e1..51fe14618a 100644
--- a/tests/python/relax/test_transform_lazy_transform_params.py
+++ b/tests/python/relax/test_transform_lazy_transform_params.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
import tvm
diff --git a/tests/python/relax/test_transform_legalize_ops.py b/tests/python/relax/test_transform_legalize_ops.py
index c58ccd8ad1..d238bc8e0a 100644
--- a/tests/python/relax/test_transform_legalize_ops.py
+++ b/tests/python/relax/test_transform_legalize_ops.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import pytest
diff --git a/tests/python/relax/test_transform_legalize_ops_binary.py b/tests/python/relax/test_transform_legalize_ops_binary.py
index a94a431700..eea0409280 100644
--- a/tests/python/relax/test_transform_legalize_ops_binary.py
+++ b/tests/python/relax/test_transform_legalize_ops_binary.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_ccl.py b/tests/python/relax/test_transform_legalize_ops_ccl.py
index 3e763b0b63..8009d84775 100644
--- a/tests/python/relax/test_transform_legalize_ops_ccl.py
+++ b/tests/python/relax/test_transform_legalize_ops_ccl.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_create_datatype.py b/tests/python/relax/test_transform_legalize_ops_create_datatype.py
index b289d4a48d..5f367e5f98 100644
--- a/tests/python/relax/test_transform_legalize_ops_create_datatype.py
+++ b/tests/python/relax/test_transform_legalize_ops_create_datatype.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_distributed.py b/tests/python/relax/test_transform_legalize_ops_distributed.py
index fbec6f2b07..04f3ce36bc 100644
--- a/tests/python/relax/test_transform_legalize_ops_distributed.py
+++ b/tests/python/relax/test_transform_legalize_ops_distributed.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_grad.py b/tests/python/relax/test_transform_legalize_ops_grad.py
index 3762f45e58..b9dc773ef8 100644
--- a/tests/python/relax/test_transform_legalize_ops_grad.py
+++ b/tests/python/relax/test_transform_legalize_ops_grad.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
from tvm.relax.transform import LegalizeOps
diff --git a/tests/python/relax/test_transform_legalize_ops_image.py b/tests/python/relax/test_transform_legalize_ops_image.py
index 99140986ea..b89ace7aa2 100644
--- a/tests/python/relax/test_transform_legalize_ops_image.py
+++ b/tests/python/relax/test_transform_legalize_ops_image.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_index_linear_algebra.py b/tests/python/relax/test_transform_legalize_ops_index_linear_algebra.py
index dc43f84f07..b24106faa1 100644
--- a/tests/python/relax/test_transform_legalize_ops_index_linear_algebra.py
+++ b/tests/python/relax/test_transform_legalize_ops_index_linear_algebra.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_manipulate.py b/tests/python/relax/test_transform_legalize_ops_manipulate.py
index cce683bd4b..da2467a98f 100644
--- a/tests/python/relax/test_transform_legalize_ops_manipulate.py
+++ b/tests/python/relax/test_transform_legalize_ops_manipulate.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, E731, F841
import tvm
import tvm.testing
from tvm import relax
diff --git a/tests/python/relax/test_transform_legalize_ops_nn.py b/tests/python/relax/test_transform_legalize_ops_nn.py
index f1ba7105ae..f11b74800e 100644
--- a/tests/python/relax/test_transform_legalize_ops_nn.py
+++ b/tests/python/relax/test_transform_legalize_ops_nn.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F821, F841
import pytest
diff --git a/tests/python/relax/test_transform_legalize_ops_search_statistical.py b/tests/python/relax/test_transform_legalize_ops_search_statistical.py
index 17df337f28..b90e024bb9 100644
--- a/tests/python/relax/test_transform_legalize_ops_search_statistical.py
+++ b/tests/python/relax/test_transform_legalize_ops_search_statistical.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_legalize_ops_unary.py b/tests/python/relax/test_transform_legalize_ops_unary.py
index 3963c7bf2f..c5fd494468 100644
--- a/tests/python/relax/test_transform_legalize_ops_unary.py
+++ b/tests/python/relax/test_transform_legalize_ops_unary.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
from typing import Callable
diff --git a/tests/python/relax/test_transform_lift_transform_params.py b/tests/python/relax/test_transform_lift_transform_params.py
index 3812687284..4d99912aea 100644
--- a/tests/python/relax/test_transform_lift_transform_params.py
+++ b/tests/python/relax/test_transform_lift_transform_params.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
import numpy as np
import pytest
diff --git a/tests/python/relax/test_transform_meta_schedule_apply_database.py b/tests/python/relax/test_transform_meta_schedule_apply_database.py
index c19d1e9e65..857a09b587 100644
--- a/tests/python/relax/test_transform_meta_schedule_apply_database.py
+++ b/tests/python/relax/test_transform_meta_schedule_apply_database.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_meta_schedule_tuning.py b/tests/python/relax/test_transform_meta_schedule_tuning.py
index af3820d306..7e36260ab0 100644
--- a/tests/python/relax/test_transform_meta_schedule_tuning.py
+++ b/tests/python/relax/test_transform_meta_schedule_tuning.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tempfile
diff --git a/tests/python/relax/test_transform_normalize.py b/tests/python/relax/test_transform_normalize.py
index d66d211ceb..0fb3908269 100644
--- a/tests/python/relax/test_transform_normalize.py
+++ b/tests/python/relax/test_transform_normalize.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import pytest
import tvm
diff --git a/tests/python/relax/test_transform_normalize_global_var.py b/tests/python/relax/test_transform_normalize_global_var.py
index 8a04490335..34f6c3acd6 100644
--- a/tests/python/relax/test_transform_normalize_global_var.py
+++ b/tests/python/relax/test_transform_normalize_global_var.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import pytest
import tvm
diff --git a/tests/python/relax/test_transform_operator_specific_normalization.py b/tests/python/relax/test_transform_operator_specific_normalization.py
index fd55cb298e..2b5d9d4ee2 100644
--- a/tests/python/relax/test_transform_operator_specific_normalization.py
+++ b/tests/python/relax/test_transform_operator_specific_normalization.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""Test FNormalize usage"""
diff --git a/tests/python/relax/test_transform_realize_vdevice.py b/tests/python/relax/test_transform_realize_vdevice.py
index c027709541..ba90213e35 100644
--- a/tests/python/relax/test_transform_realize_vdevice.py
+++ b/tests/python/relax/test_transform_realize_vdevice.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""Test eliminate common subexpr pass"""
import tvm
diff --git a/tests/python/relax/test_transform_remove_unused_outputs.py b/tests/python/relax/test_transform_remove_unused_outputs.py
index f17376f300..ab3ea89a94 100644
--- a/tests/python/relax/test_transform_remove_unused_outputs.py
+++ b/tests/python/relax/test_transform_remove_unused_outputs.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_reorder_take_after_matmul.py b/tests/python/relax/test_transform_reorder_take_after_matmul.py
index 3218200897..da36c39ffd 100644
--- a/tests/python/relax/test_transform_reorder_take_after_matmul.py
+++ b/tests/python/relax/test_transform_reorder_take_after_matmul.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import inspect
diff --git a/tests/python/relax/test_transform_rewrite_cuda_graph.py b/tests/python/relax/test_transform_rewrite_cuda_graph.py
index a2cdd43871..7c25c1b1ab 100644
--- a/tests/python/relax/test_transform_rewrite_cuda_graph.py
+++ b/tests/python/relax/test_transform_rewrite_cuda_graph.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import pytest
diff --git a/tests/python/relax/test_transform_rewrite_dataflow_reshape.py b/tests/python/relax/test_transform_rewrite_dataflow_reshape.py
index 54610d245e..7d77796f74 100644
--- a/tests/python/relax/test_transform_rewrite_dataflow_reshape.py
+++ b/tests/python/relax/test_transform_rewrite_dataflow_reshape.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_specialize_primfunc_based_on_callsite.py b/tests/python/relax/test_transform_specialize_primfunc_based_on_callsite.py
index 707d494b23..68f33e6c41 100644
--- a/tests/python/relax/test_transform_specialize_primfunc_based_on_callsite.py
+++ b/tests/python/relax/test_transform_specialize_primfunc_based_on_callsite.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F401, F821
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_static_plan_block_memory.py b/tests/python/relax/test_transform_static_plan_block_memory.py
index ce5c32d756..d0e7c96649 100644
--- a/tests/python/relax/test_transform_static_plan_block_memory.py
+++ b/tests/python/relax/test_transform_static_plan_block_memory.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501, F841
import pytest
diff --git a/tests/python/relax/test_transform_topological_sort.py b/tests/python/relax/test_transform_topological_sort.py
index eefb0a5762..14a0c5889c 100644
--- a/tests/python/relax/test_transform_topological_sort.py
+++ b/tests/python/relax/test_transform_topological_sort.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_transform_update_vdevice.py b/tests/python/relax/test_transform_update_vdevice.py
index 027bf28683..b240536fc1 100644
--- a/tests/python/relax/test_transform_update_vdevice.py
+++ b/tests/python/relax/test_transform_update_vdevice.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_tvmscript_ir_builder.py b/tests/python/relax/test_tvmscript_ir_builder.py
index cd36a5ed53..0f92534eaa 100644
--- a/tests/python/relax/test_tvmscript_ir_builder.py
+++ b/tests/python/relax/test_tvmscript_ir_builder.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import tvm
import tvm.testing
from tvm import relax, tir, topi
diff --git a/tests/python/relax/test_tvmscript_parser.py b/tests/python/relax/test_tvmscript_parser.py
index 9a1283ff91..860f10e197 100644
--- a/tests/python/relax/test_tvmscript_parser.py
+++ b/tests/python/relax/test_tvmscript_parser.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821, F841
import sys
from typing import Optional, Union
diff --git a/tests/python/relax/test_tvmscript_parser_op_manipulate.py b/tests/python/relax/test_tvmscript_parser_op_manipulate.py
index 33387c4e9a..ef30270c0d 100644
--- a/tests/python/relax/test_tvmscript_parser_op_manipulate.py
+++ b/tests/python/relax/test_tvmscript_parser_op_manipulate.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E731
from typing import Optional, Union
diff --git a/tests/python/relax/test_tvmscript_printer_relax.py b/tests/python/relax/test_tvmscript_printer_relax.py
index 52f935a894..6b6a4a90be 100644
--- a/tests/python/relax/test_tvmscript_printer_relax.py
+++ b/tests/python/relax/test_tvmscript_printer_relax.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=missing-docstring
+# ruff: noqa: E501, F841
import tvm
import tvm.testing
diff --git a/tests/python/relax/test_tvmscript_pyfunc.py b/tests/python/relax/test_tvmscript_pyfunc.py
index e011f8272f..601c8dd4f4 100644
--- a/tests/python/relax/test_tvmscript_pyfunc.py
+++ b/tests/python/relax/test_tvmscript_pyfunc.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
"""
Test TVMScript @I.pyfunc decorator functionality.
diff --git a/tests/python/relax/test_utils.py b/tests/python/relax/test_utils.py
index 207afdbc90..064c9f0474 100644
--- a/tests/python/relax/test_utils.py
+++ b/tests/python/relax/test_utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import re
diff --git a/tests/python/relax/test_vm_build.py b/tests/python/relax/test_vm_build.py
index 451d89673c..c0840f188a 100644
--- a/tests/python/relax/test_vm_build.py
+++ b/tests/python/relax/test_vm_build.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import ctypes
from typing import Callable, Tuple
diff --git a/tests/python/relax/test_vm_callback_function.py b/tests/python/relax/test_vm_callback_function.py
index b73ec3d333..a5851b9387 100644
--- a/tests/python/relax/test_vm_callback_function.py
+++ b/tests/python/relax/test_vm_callback_function.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
import numpy as np
diff --git a/tests/python/relax/test_vm_codegen_only.py b/tests/python/relax/test_vm_codegen_only.py
index c7d5fb11b6..f94ba675b3 100644
--- a/tests/python/relax/test_vm_codegen_only.py
+++ b/tests/python/relax/test_vm_codegen_only.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""Test last-stage of codegen VM.
Restrictions: all shape lowered, explicit allocation.
diff --git a/tests/python/relax/test_vm_cuda_graph.py b/tests/python/relax/test_vm_cuda_graph.py
index e787b171a6..91e7adb8aa 100644
--- a/tests/python/relax/test_vm_cuda_graph.py
+++ b/tests/python/relax/test_vm_cuda_graph.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E501
import numpy as np
import pytest
diff --git a/tests/python/relax/test_vm_instrument.py b/tests/python/relax/test_vm_instrument.py
index c5b51ce717..90ebd404a6 100644
--- a/tests/python/relax/test_vm_instrument.py
+++ b/tests/python/relax/test_vm_instrument.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
import numpy as np
import tvm
diff --git a/tests/python/relax/test_vm_profiler.py b/tests/python/relax/test_vm_profiler.py
index 2ac5fb9e5b..c661bbe5da 100644
--- a/tests/python/relax/test_vm_profiler.py
+++ b/tests/python/relax/test_vm_profiler.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: RUF005
import numpy as np
import tvm
diff --git a/tests/python/relax/texture/adreno_utils.py b/tests/python/relax/texture/adreno_utils.py
index d6ff24d6ff..8907791231 100644
--- a/tests/python/relax/texture/adreno_utils.py
+++ b/tests/python/relax/texture/adreno_utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import os
diff --git a/tests/python/relax/texture/test_network.py b/tests/python/relax/texture/test_network.py
index 74a6efaae4..4091194cc1 100644
--- a/tests/python/relax/texture/test_network.py
+++ b/tests/python/relax/texture/test_network.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
import copy
import json
diff --git a/tests/python/relax/texture/test_ops.py b/tests/python/relax/texture/test_ops.py
index 100eecb1dc..8108eb3c78 100644
--- a/tests/python/relax/texture/test_ops.py
+++ b/tests/python/relax/texture/test_ops.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F841
from adreno_utils import verify
diff --git a/tests/python/relax/texture/test_texture_nd.py b/tests/python/relax/texture/test_texture_nd.py
index cde1831591..ce1a28f2de 100644
--- a/tests/python/relax/texture/test_texture_nd.py
+++ b/tests/python/relax/texture/test_texture_nd.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401, F821, F841
import os
import tempfile
diff --git a/tests/python/runtime/test_rpc_base.py b/tests/python/runtime/test_rpc_base.py
index 6ac92357b9..3d54730084 100644
--- a/tests/python/runtime/test_rpc_base.py
+++ b/tests/python/runtime/test_rpc_base.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F821
import random
import pytest
diff --git a/tests/python/runtime/test_runtime_container.py b/tests/python/runtime/test_runtime_container.py
index e21c42bfba..83f7183831 100644
--- a/tests/python/runtime/test_runtime_container.py
+++ b/tests/python/runtime/test_runtime_container.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: E712, F401
import pickle
import random
diff --git a/tests/python/runtime/test_runtime_error.py b/tests/python/runtime/test_runtime_error.py
index b063a1d7db..f65f0fe006 100644
--- a/tests/python/runtime/test_runtime_error.py
+++ b/tests/python/runtime/test_runtime_error.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F841
"""Test runtime error handling"""
import functools
diff --git a/tests/python/runtime/test_runtime_measure.py b/tests/python/runtime/test_runtime_measure.py
index 96226fa41c..9e52e48d59 100644
--- a/tests/python/runtime/test_runtime_measure.py
+++ b/tests/python/runtime/test_runtime_measure.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+# ruff: noqa: F401
import ctypes
import time
diff --git a/tests/python/runtime/test_runtime_module_load.py b/tests/python/runtime/test_runtime_module_load.py
index bf743dbd80..6910ad8d4b 100644
--- a/tests/python/runtime/test_runtime_module_load.py
+++ b/tests/python/runtime/test_runtime_module_load.py
@@ -113,7 +113,7 @@ def test_device_module_dump():
def check_device(device):
dev = tvm.device(device, 0)
if not tvm.testing.device_enabled(device):
- print("Skip because %s is not enabled" % device)
+ print(f"Skip because {device} is not enabled")
return
temp = utils.tempdir()
f = tvm.compile(sch.mod, target=device)
@@ -139,7 +139,7 @@ def test_device_module_dump():
def check_c(device):
dev = tvm.device(device, 0)
if not tvm.testing.device_enabled(device):
- print("Skip because %s is not enabled" % device)
+ print(f"Skip because {device} is not enabled")
return
f = tvm.compile(sch.mod, target=tvm.target.Target(device, host="c"))
a = tvm.runtime.tensor(np.random.uniform(size=1024).astype(A.dtype), dev)
diff --git a/tests/python/runtime/test_runtime_nd_array.py b/tests/python/runtime/test_runtime_nd_array.py
... 2521 lines suppressed ...