From 6377c7e9d30d7f4e9453a27eac15e8897705029a Mon Sep 17 00:00:00 2001 From: driazati Date: Wed, 22 Jun 2022 15:09:49 -0700 Subject: [PATCH] [ci] Redirect sphinx-gallery URLs to S3 --- gallery/how_to/compile_models/from_coreml.py | 6 ++ gallery/how_to/compile_models/from_darknet.py | 6 ++ gallery/how_to/compile_models/from_keras.py | 6 ++ gallery/how_to/compile_models/from_mxnet.py | 6 ++ gallery/how_to/compile_models/from_oneflow.py | 6 ++ gallery/how_to/compile_models/from_onnx.py | 6 ++ gallery/how_to/compile_models/from_paddle.py | 6 ++ gallery/how_to/compile_models/from_pytorch.py | 6 ++ .../how_to/compile_models/from_tensorflow.py | 6 ++ gallery/how_to/compile_models/from_tflite.py | 6 ++ .../deploy_models/deploy_model_on_android.py | 6 ++ .../deploy_models/deploy_model_on_rasp.py | 6 ++ .../deploy_object_detection_pytorch.py | 6 ++ .../deploy_models/deploy_prequantized.py | 6 ++ .../deploy_prequantized_tflite.py | 6 ++ .../how_to/deploy_models/deploy_quantized.py | 6 ++ gallery/how_to/deploy_models/deploy_sparse.py | 6 ++ .../deploy_models/deploy_ssd_gluoncv.py | 6 ++ .../extend_tvm/bring_your_own_datatypes.py | 6 ++ .../extend_tvm/low_level_custom_pass.py | 6 ++ gallery/how_to/extend_tvm/use_pass_infra.py | 6 ++ .../how_to/extend_tvm/use_pass_instrument.py | 6 ++ .../optimize_operators/opt_conv_cuda.py | 6 ++ .../optimize_operators/opt_conv_tensorcore.py | 6 ++ gallery/how_to/optimize_operators/opt_gemm.py | 6 ++ .../tune_conv2d_layer_cuda.py | 6 ++ .../tune_network_arm.py | 6 ++ .../tune_network_cuda.py | 6 ++ .../tune_network_mali.py | 6 ++ .../tune_network_x86.py | 6 ++ .../tune_sparse_x86.py | 6 ++ .../tune_with_autotvm/tune_conv2d_cuda.py | 6 ++ .../tune_with_autotvm/tune_relay_arm.py | 6 ++ .../tune_with_autotvm/tune_relay_cuda.py | 6 ++ .../tune_relay_mobile_gpu.py | 6 ++ .../tune_with_autotvm/tune_relay_x86.py | 6 ++ .../work_with_microtvm/micro_autotune.py | 6 ++ .../how_to/work_with_microtvm/micro_ethosu.py | 6 ++ .../work_with_microtvm/micro_reference_vm.py | 6 ++ .../how_to/work_with_microtvm/micro_tflite.py | 6 ++ gallery/how_to/work_with_relay/build_gcn.py | 6 ++ .../work_with_relay/using_external_lib.py | 6 ++ .../how_to/work_with_relay/using_relay_viz.py | 6 ++ .../how_to/work_with_schedules/extern_op.py | 6 ++ .../how_to/work_with_schedules/intrin_math.py | 8 +- .../how_to/work_with_schedules/reduction.py | 6 ++ gallery/how_to/work_with_schedules/scan.py | 6 ++ .../schedule_primitives.py | 6 ++ gallery/how_to/work_with_schedules/tedd.py | 6 ++ .../how_to/work_with_schedules/tensorize.py | 6 ++ .../work_with_schedules/tuple_inputs.py | 6 ++ gallery/tutorial/auto_scheduler_matmul_x86.py | 6 ++ gallery/tutorial/autotvm_matmul_x86.py | 6 ++ gallery/tutorial/autotvm_relay_x86.py | 6 ++ gallery/tutorial/cross_compilation_and_rpc.py | 6 ++ gallery/tutorial/install.py | 6 ++ gallery/tutorial/intro_topi.py | 6 ++ gallery/tutorial/introduction.py | 6 ++ gallery/tutorial/relay_quick_start.py | 6 ++ gallery/tutorial/tensor_expr_get_started.py | 6 ++ gallery/tutorial/tensor_ir_blitz_course.py | 6 ++ gallery/tutorial/tvmc_command_line_driver.py | 6 ++ gallery/tutorial/tvmc_python.py | 6 ++ python/tvm/testing/utils.py | 47 ++++++++++ tests/lint/check_request_hook.py | 92 +++++++++++++++++++ tests/scripts/request_hook/request_hook.py | 61 ++++++++++++ tests/scripts/task_lint.sh | 3 + 67 files changed, 582 insertions(+), 1 deletion(-) create mode 100644 tests/lint/check_request_hook.py create mode 100644 tests/scripts/request_hook/request_hook.py diff --git a/gallery/how_to/compile_models/from_coreml.py b/gallery/how_to/compile_models/from_coreml.py index 98d1969f3639d..96d2967947f6e 100644 --- a/gallery/how_to/compile_models/from_coreml.py +++ b/gallery/how_to/compile_models/from_coreml.py @@ -34,6 +34,12 @@ or please refer to official site https://github.com/apple/coremltools """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import tvm.relay as relay diff --git a/gallery/how_to/compile_models/from_darknet.py b/gallery/how_to/compile_models/from_darknet.py index 232058641ab00..c12a9e7e1574b 100644 --- a/gallery/how_to/compile_models/from_darknet.py +++ b/gallery/how_to/compile_models/from_darknet.py @@ -31,6 +31,12 @@ pip install opencv-python """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + # numpy and matplotlib import numpy as np import matplotlib.pyplot as plt diff --git a/gallery/how_to/compile_models/from_keras.py b/gallery/how_to/compile_models/from_keras.py index 1db27799fe4c1..895a601ada0ad 100644 --- a/gallery/how_to/compile_models/from_keras.py +++ b/gallery/how_to/compile_models/from_keras.py @@ -34,6 +34,12 @@ or please refer to official site https://keras.io/#installation """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import tvm.relay as relay diff --git a/gallery/how_to/compile_models/from_mxnet.py b/gallery/how_to/compile_models/from_mxnet.py index 027e9e6eb757c..38084618628fd 100644 --- a/gallery/how_to/compile_models/from_mxnet.py +++ b/gallery/how_to/compile_models/from_mxnet.py @@ -35,6 +35,12 @@ or please refer to official installation guide. https://mxnet.apache.org/versions/master/install/index.html """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore # some standard imports import mxnet as mx import tvm diff --git a/gallery/how_to/compile_models/from_oneflow.py b/gallery/how_to/compile_models/from_oneflow.py index f92f0b0f1e220..eb27c4b3e34b7 100644 --- a/gallery/how_to/compile_models/from_oneflow.py +++ b/gallery/how_to/compile_models/from_oneflow.py @@ -35,6 +35,12 @@ Currently, TVM supports OneFlow 0.7.0. Other versions may be unstable. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import os, math from matplotlib import pyplot as plt import numpy as np diff --git a/gallery/how_to/compile_models/from_onnx.py b/gallery/how_to/compile_models/from_onnx.py index 586c811aa627a..f0256bc7d3ae5 100644 --- a/gallery/how_to/compile_models/from_onnx.py +++ b/gallery/how_to/compile_models/from_onnx.py @@ -32,6 +32,12 @@ or please refer to official site. https://github.com/onnx/onnx """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import onnx import numpy as np import tvm diff --git a/gallery/how_to/compile_models/from_paddle.py b/gallery/how_to/compile_models/from_paddle.py index 9d67cbcdf9ff5..fecb1c48dafbf 100644 --- a/gallery/how_to/compile_models/from_paddle.py +++ b/gallery/how_to/compile_models/from_paddle.py @@ -30,6 +30,12 @@ or please refer to official site. https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tarfile import paddle import numpy as np diff --git a/gallery/how_to/compile_models/from_pytorch.py b/gallery/how_to/compile_models/from_pytorch.py index e8d0b4998f9e5..98b531fa6d6e3 100644 --- a/gallery/how_to/compile_models/from_pytorch.py +++ b/gallery/how_to/compile_models/from_pytorch.py @@ -41,6 +41,12 @@ be unstable. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import tvm from tvm import relay diff --git a/gallery/how_to/compile_models/from_tensorflow.py b/gallery/how_to/compile_models/from_tensorflow.py index 4563e245c0cf0..9a32397815efb 100644 --- a/gallery/how_to/compile_models/from_tensorflow.py +++ b/gallery/how_to/compile_models/from_tensorflow.py @@ -24,6 +24,12 @@ Please refer to https://www.tensorflow.org/install """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + # tvm, relay import tvm from tvm import te diff --git a/gallery/how_to/compile_models/from_tflite.py b/gallery/how_to/compile_models/from_tflite.py index b720402366542..712269381f840 100644 --- a/gallery/how_to/compile_models/from_tflite.py +++ b/gallery/how_to/compile_models/from_tflite.py @@ -52,6 +52,12 @@ Below you can find an example on how to compile TFLite model using TVM. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore ###################################################################### # Utils for downloading and extracting zip files # ---------------------------------------------- diff --git a/gallery/how_to/deploy_models/deploy_model_on_android.py b/gallery/how_to/deploy_models/deploy_model_on_android.py index c7b610d5d5034..10e108239ee75 100644 --- a/gallery/how_to/deploy_models/deploy_model_on_android.py +++ b/gallery/how_to/deploy_models/deploy_model_on_android.py @@ -25,6 +25,12 @@ This is an example of using Relay to compile a keras model and deploy it on Android device. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import os import numpy as np from PIL import Image diff --git a/gallery/how_to/deploy_models/deploy_model_on_rasp.py b/gallery/how_to/deploy_models/deploy_model_on_rasp.py index de4ed9aff074c..ab5374d93dbf5 100644 --- a/gallery/how_to/deploy_models/deploy_model_on_rasp.py +++ b/gallery/how_to/deploy_models/deploy_model_on_rasp.py @@ -26,6 +26,12 @@ it on Raspberry Pi. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import tvm from tvm import te import tvm.relay as relay diff --git a/gallery/how_to/deploy_models/deploy_object_detection_pytorch.py b/gallery/how_to/deploy_models/deploy_object_detection_pytorch.py index b5b0e4acf1f60..0d8d0f2867a2d 100644 --- a/gallery/how_to/deploy_models/deploy_object_detection_pytorch.py +++ b/gallery/how_to/deploy_models/deploy_object_detection_pytorch.py @@ -40,6 +40,12 @@ be unstable. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import tvm from tvm import relay from tvm import relay diff --git a/gallery/how_to/deploy_models/deploy_prequantized.py b/gallery/how_to/deploy_models/deploy_prequantized.py index caee2b3b415ae..fdb4de289d913 100644 --- a/gallery/how_to/deploy_models/deploy_prequantized.py +++ b/gallery/how_to/deploy_models/deploy_prequantized.py @@ -28,6 +28,12 @@ Once loaded, we can run compiled, quantized models on any hardware TVM supports. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################# # First, necessary imports from PIL import Image diff --git a/gallery/how_to/deploy_models/deploy_prequantized_tflite.py b/gallery/how_to/deploy_models/deploy_prequantized_tflite.py index 830e2ab074662..494b4a9e219b4 100644 --- a/gallery/how_to/deploy_models/deploy_prequantized_tflite.py +++ b/gallery/how_to/deploy_models/deploy_prequantized_tflite.py @@ -42,6 +42,12 @@ """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ############################################################################### # Necessary imports # ----------------- diff --git a/gallery/how_to/deploy_models/deploy_quantized.py b/gallery/how_to/deploy_models/deploy_quantized.py index 2d9275796eb5c..24c7ce3331f54 100644 --- a/gallery/how_to/deploy_models/deploy_quantized.py +++ b/gallery/how_to/deploy_models/deploy_quantized.py @@ -27,6 +27,12 @@ Relay, quantize the Relay model and then perform the inference. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import tvm from tvm import te from tvm import relay diff --git a/gallery/how_to/deploy_models/deploy_sparse.py b/gallery/how_to/deploy_models/deploy_sparse.py index 56a5f1aafd1ce..b9a26e0d30532 100644 --- a/gallery/how_to/deploy_models/deploy_sparse.py +++ b/gallery/how_to/deploy_models/deploy_sparse.py @@ -70,6 +70,12 @@ sparse speed using fake weights to see the benefit of structured sparsity. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ############################################################################### # Load Required Modules # --------------------- diff --git a/gallery/how_to/deploy_models/deploy_ssd_gluoncv.py b/gallery/how_to/deploy_models/deploy_ssd_gluoncv.py index ebe18670c6a38..f39244a2eb037 100644 --- a/gallery/how_to/deploy_models/deploy_ssd_gluoncv.py +++ b/gallery/how_to/deploy_models/deploy_ssd_gluoncv.py @@ -23,6 +23,12 @@ This article is an introductory tutorial to deploy SSD models with TVM. We will use GluonCV pre-trained SSD model and convert it to Relay IR """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te diff --git a/gallery/how_to/extend_tvm/bring_your_own_datatypes.py b/gallery/how_to/extend_tvm/bring_your_own_datatypes.py index 1a48781e24336..479269a224a3f 100644 --- a/gallery/how_to/extend_tvm/bring_your_own_datatypes.py +++ b/gallery/how_to/extend_tvm/bring_your_own_datatypes.py @@ -52,6 +52,12 @@ ctypes.CDLL('my-datatype-lib.so', ctypes.RTLD_GLOBAL) """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################### # A Simple TVM Program # -------------------- diff --git a/gallery/how_to/extend_tvm/low_level_custom_pass.py b/gallery/how_to/extend_tvm/low_level_custom_pass.py index ee96d8220cac3..0f99c72cee9cc 100644 --- a/gallery/how_to/extend_tvm/low_level_custom_pass.py +++ b/gallery/how_to/extend_tvm/low_level_custom_pass.py @@ -40,6 +40,12 @@ take a look at ``python/tvm/build_module.py`` to get some basics. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import numpy as np diff --git a/gallery/how_to/extend_tvm/use_pass_infra.py b/gallery/how_to/extend_tvm/use_pass_infra.py index e38383e69011a..a41a26fc0b1e2 100644 --- a/gallery/how_to/extend_tvm/use_pass_infra.py +++ b/gallery/how_to/extend_tvm/use_pass_infra.py @@ -40,6 +40,12 @@ The same approach can be used for tir as well. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import numpy as np import tvm from tvm import te diff --git a/gallery/how_to/extend_tvm/use_pass_instrument.py b/gallery/how_to/extend_tvm/use_pass_instrument.py index 036aa63e374f0..3079e2f0e7639 100644 --- a/gallery/how_to/extend_tvm/use_pass_instrument.py +++ b/gallery/how_to/extend_tvm/use_pass_instrument.py @@ -33,6 +33,12 @@ This tutorial demonstrates how developers can use ``PassContext`` to instrument passes. Please also refer to the :ref:`pass-infra`. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm import tvm.relay as relay from tvm.relay.testing import resnet diff --git a/gallery/how_to/optimize_operators/opt_conv_cuda.py b/gallery/how_to/optimize_operators/opt_conv_cuda.py index 3d2caa0d31214..e5b452af66a95 100644 --- a/gallery/how_to/optimize_operators/opt_conv_cuda.py +++ b/gallery/how_to/optimize_operators/opt_conv_cuda.py @@ -30,6 +30,12 @@ """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################ # Preparation and Algorithm # ------------------------- diff --git a/gallery/how_to/optimize_operators/opt_conv_tensorcore.py b/gallery/how_to/optimize_operators/opt_conv_tensorcore.py index ccfc7b9743aaa..4cc2b40b7b8c8 100644 --- a/gallery/how_to/optimize_operators/opt_conv_tensorcore.py +++ b/gallery/how_to/optimize_operators/opt_conv_tensorcore.py @@ -27,6 +27,12 @@ """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################ # TensorCore Introduction # ----------------------- diff --git a/gallery/how_to/optimize_operators/opt_gemm.py b/gallery/how_to/optimize_operators/opt_gemm.py index 920d7a87fabf9..d2ec711c2b29a 100644 --- a/gallery/how_to/optimize_operators/opt_gemm.py +++ b/gallery/how_to/optimize_operators/opt_gemm.py @@ -48,6 +48,12 @@ Intel i7-4770HQ CPU. The cache line size should be 64 bytes for all the x86 CPUs. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################################ # Preparation and Baseline # ------------------------ diff --git a/gallery/how_to/tune_with_autoscheduler/tune_conv2d_layer_cuda.py b/gallery/how_to/tune_with_autoscheduler/tune_conv2d_layer_cuda.py index a4f7e22d89c44..5d173e38128eb 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_conv2d_layer_cuda.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_conv2d_layer_cuda.py @@ -37,6 +37,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import os import numpy as np diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py b/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py index 9c5820c991e8a..09a1d0cea5208 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py @@ -46,6 +46,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import numpy as np import os diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py b/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py index b403c0aa84fbb..cc29f27ba22be 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py @@ -44,6 +44,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import numpy as np import tvm diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py b/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py index 2d1e515209528..8ac0b235d72ef 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py @@ -44,6 +44,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import numpy as np import tvm diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py b/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py index 6cb8d6f14cb9b..5a321104c8e42 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py @@ -45,6 +45,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import numpy as np import tvm diff --git a/gallery/how_to/tune_with_autoscheduler/tune_sparse_x86.py b/gallery/how_to/tune_with_autoscheduler/tune_sparse_x86.py index 55ee76ef6c4f0..0a2ddbd1bd817 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_sparse_x86.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_sparse_x86.py @@ -35,6 +35,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import os import numpy as np diff --git a/gallery/how_to/tune_with_autotvm/tune_conv2d_cuda.py b/gallery/how_to/tune_with_autotvm/tune_conv2d_cuda.py index e3072773bf593..95d6dcb0a19c4 100644 --- a/gallery/how_to/tune_with_autotvm/tune_conv2d_cuda.py +++ b/gallery/how_to/tune_with_autotvm/tune_conv2d_cuda.py @@ -28,6 +28,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # Install dependencies # -------------------- diff --git a/gallery/how_to/tune_with_autotvm/tune_relay_arm.py b/gallery/how_to/tune_with_autotvm/tune_relay_arm.py index f072c5ddac935..ab278021d2cad 100644 --- a/gallery/how_to/tune_with_autotvm/tune_relay_arm.py +++ b/gallery/how_to/tune_with_autotvm/tune_relay_arm.py @@ -41,6 +41,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # Install dependencies # -------------------- diff --git a/gallery/how_to/tune_with_autotvm/tune_relay_cuda.py b/gallery/how_to/tune_with_autotvm/tune_relay_cuda.py index b2af2e13f4fe4..459b2798c295a 100644 --- a/gallery/how_to/tune_with_autotvm/tune_relay_cuda.py +++ b/gallery/how_to/tune_with_autotvm/tune_relay_cuda.py @@ -39,6 +39,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # Install dependencies # -------------------- diff --git a/gallery/how_to/tune_with_autotvm/tune_relay_mobile_gpu.py b/gallery/how_to/tune_with_autotvm/tune_relay_mobile_gpu.py index d3f4ec62fafc9..5a4f0c56d2e75 100644 --- a/gallery/how_to/tune_with_autotvm/tune_relay_mobile_gpu.py +++ b/gallery/how_to/tune_with_autotvm/tune_relay_mobile_gpu.py @@ -39,6 +39,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # Install dependencies # -------------------- diff --git a/gallery/how_to/tune_with_autotvm/tune_relay_x86.py b/gallery/how_to/tune_with_autotvm/tune_relay_x86.py index 771220bb33149..6e46fbd8ffc88 100644 --- a/gallery/how_to/tune_with_autotvm/tune_relay_x86.py +++ b/gallery/how_to/tune_with_autotvm/tune_relay_x86.py @@ -28,6 +28,12 @@ get it to run, you will need to wrap the body of this tutorial in a :code:`if __name__ == "__main__":` block. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import os import numpy as np diff --git a/gallery/how_to/work_with_microtvm/micro_autotune.py b/gallery/how_to/work_with_microtvm/micro_autotune.py index 613d92e1413e4..58c52508b7c2a 100644 --- a/gallery/how_to/work_with_microtvm/micro_autotune.py +++ b/gallery/how_to/work_with_microtvm/micro_autotune.py @@ -27,6 +27,12 @@ This tutorial explains how to autotune a model using the C runtime. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import os import json import numpy as np diff --git a/gallery/how_to/work_with_microtvm/micro_ethosu.py b/gallery/how_to/work_with_microtvm/micro_ethosu.py index f55fad71dda10..8e37a0ea5ec4e 100644 --- a/gallery/how_to/work_with_microtvm/micro_ethosu.py +++ b/gallery/how_to/work_with_microtvm/micro_ethosu.py @@ -37,6 +37,12 @@ TVM to offload operators to the Ethos(TM)-U55 where possible. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # Obtaining TVM # ------------- diff --git a/gallery/how_to/work_with_microtvm/micro_reference_vm.py b/gallery/how_to/work_with_microtvm/micro_reference_vm.py index 9eacd9a963e1f..b87a7265649f2 100644 --- a/gallery/how_to/work_with_microtvm/micro_reference_vm.py +++ b/gallery/how_to/work_with_microtvm/micro_reference_vm.py @@ -157,3 +157,9 @@ """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore diff --git a/gallery/how_to/work_with_microtvm/micro_tflite.py b/gallery/how_to/work_with_microtvm/micro_tflite.py index 3d871ba783ad8..dfe33eedac75b 100644 --- a/gallery/how_to/work_with_microtvm/micro_tflite.py +++ b/gallery/how_to/work_with_microtvm/micro_tflite.py @@ -25,6 +25,12 @@ model with Relay. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # .. note:: # If you want to run this tutorial on the microTVM Reference VM, download the Jupyter diff --git a/gallery/how_to/work_with_relay/build_gcn.py b/gallery/how_to/work_with_relay/build_gcn.py index fcffbd77ff86b..8953ffc2e474c 100644 --- a/gallery/how_to/work_with_relay/build_gcn.py +++ b/gallery/how_to/work_with_relay/build_gcn.py @@ -118,6 +118,12 @@ def evaluate(data, logits): num_classes: int dimension of model output (Number of classes) """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore dataset = "cora" g, data = load_dataset(dataset) diff --git a/gallery/how_to/work_with_relay/using_external_lib.py b/gallery/how_to/work_with_relay/using_external_lib.py index 8b6957d1dbf6f..c018ee13c724e 100644 --- a/gallery/how_to/work_with_relay/using_external_lib.py +++ b/gallery/how_to/work_with_relay/using_external_lib.py @@ -31,6 +31,12 @@ To begin with, we import Relay and TVM. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import numpy as np diff --git a/gallery/how_to/work_with_relay/using_relay_viz.py b/gallery/how_to/work_with_relay/using_relay_viz.py index b0132f40b9b51..2e68ce902899c 100644 --- a/gallery/how_to/work_with_relay/using_relay_viz.py +++ b/gallery/how_to/work_with_relay/using_relay_viz.py @@ -35,6 +35,12 @@ For more details, please refer to :py:mod:`tvm.contrib.relay_viz`. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore from typing import ( Dict, Union, diff --git a/gallery/how_to/work_with_schedules/extern_op.py b/gallery/how_to/work_with_schedules/extern_op.py index a0aa5d72450c0..ad741a08d54c5 100644 --- a/gallery/how_to/work_with_schedules/extern_op.py +++ b/gallery/how_to/work_with_schedules/extern_op.py @@ -31,6 +31,12 @@ """ from __future__ import absolute_import, print_function + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import numpy as np diff --git a/gallery/how_to/work_with_schedules/intrin_math.py b/gallery/how_to/work_with_schedules/intrin_math.py index 535563bfb5306..5a8732abd7764 100644 --- a/gallery/how_to/work_with_schedules/intrin_math.py +++ b/gallery/how_to/work_with_schedules/intrin_math.py @@ -29,7 +29,13 @@ the interface via TVM's intrinsic API. """ from __future__ import absolute_import, print_function -import numpy as np + + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignoreimport numpy as np import tvm from tvm import te diff --git a/gallery/how_to/work_with_schedules/reduction.py b/gallery/how_to/work_with_schedules/reduction.py index 164f36dafc798..432e9cd143b18 100644 --- a/gallery/how_to/work_with_schedules/reduction.py +++ b/gallery/how_to/work_with_schedules/reduction.py @@ -27,6 +27,12 @@ """ from __future__ import absolute_import, print_function + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm import tvm.testing from tvm import te diff --git a/gallery/how_to/work_with_schedules/scan.py b/gallery/how_to/work_with_schedules/scan.py index 3f3d7e91ee1c1..d21673acd9e49 100644 --- a/gallery/how_to/work_with_schedules/scan.py +++ b/gallery/how_to/work_with_schedules/scan.py @@ -24,6 +24,12 @@ """ from __future__ import absolute_import, print_function + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm import tvm.testing from tvm import te diff --git a/gallery/how_to/work_with_schedules/schedule_primitives.py b/gallery/how_to/work_with_schedules/schedule_primitives.py index 65fdeda57c3be..af67ed1527a0c 100644 --- a/gallery/how_to/work_with_schedules/schedule_primitives.py +++ b/gallery/how_to/work_with_schedules/schedule_primitives.py @@ -28,6 +28,12 @@ """ from __future__ import absolute_import, print_function + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import numpy as np diff --git a/gallery/how_to/work_with_schedules/tedd.py b/gallery/how_to/work_with_schedules/tedd.py index 34ad43c220da1..7cb24f433587e 100644 --- a/gallery/how_to/work_with_schedules/tedd.py +++ b/gallery/how_to/work_with_schedules/tedd.py @@ -37,6 +37,12 @@ how to use TEDD and how to interpret the rendered graphs. """ + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te from tvm import topi diff --git a/gallery/how_to/work_with_schedules/tensorize.py b/gallery/how_to/work_with_schedules/tensorize.py index 40e68074adc87..45eaf349f37b0 100644 --- a/gallery/how_to/work_with_schedules/tensorize.py +++ b/gallery/how_to/work_with_schedules/tensorize.py @@ -34,6 +34,12 @@ """ from __future__ import absolute_import, print_function + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import tvm.testing diff --git a/gallery/how_to/work_with_schedules/tuple_inputs.py b/gallery/how_to/work_with_schedules/tuple_inputs.py index 73db7b90a7d62..86ec8b2d196b7 100644 --- a/gallery/how_to/work_with_schedules/tuple_inputs.py +++ b/gallery/how_to/work_with_schedules/tuple_inputs.py @@ -27,6 +27,12 @@ """ from __future__ import absolute_import, print_function + +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore import tvm from tvm import te import numpy as np diff --git a/gallery/tutorial/auto_scheduler_matmul_x86.py b/gallery/tutorial/auto_scheduler_matmul_x86.py index b9f89f6723c9b..279987f00d819 100644 --- a/gallery/tutorial/auto_scheduler_matmul_x86.py +++ b/gallery/tutorial/auto_scheduler_matmul_x86.py @@ -38,6 +38,12 @@ __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import os import numpy as np diff --git a/gallery/tutorial/autotvm_matmul_x86.py b/gallery/tutorial/autotvm_matmul_x86.py index b84a6193cde6e..ebdbacb221534 100644 --- a/gallery/tutorial/autotvm_matmul_x86.py +++ b/gallery/tutorial/autotvm_matmul_x86.py @@ -45,6 +45,12 @@ :code:`if __name__ == "__main__":` block. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # Install dependencies # -------------------- diff --git a/gallery/tutorial/autotvm_relay_x86.py b/gallery/tutorial/autotvm_relay_x86.py index 4e5714a6db328..b7dfbe28f462e 100644 --- a/gallery/tutorial/autotvm_relay_x86.py +++ b/gallery/tutorial/autotvm_relay_x86.py @@ -42,6 +42,12 @@ how to use them through the Python API. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # TVM is a deep learning compiler framework, with a number of different modules # available for working with deep learning models and operators. In this diff --git a/gallery/tutorial/cross_compilation_and_rpc.py b/gallery/tutorial/cross_compilation_and_rpc.py index 25208369f74dd..3f74899f7b1de 100644 --- a/gallery/tutorial/cross_compilation_and_rpc.py +++ b/gallery/tutorial/cross_compilation_and_rpc.py @@ -31,6 +31,12 @@ and the Firefly-RK3399 for an OpenCL example. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # Build TVM Runtime on Device # --------------------------- diff --git a/gallery/tutorial/install.py b/gallery/tutorial/install.py index 0eb3ccc94c064..a499b037940cd 100644 --- a/gallery/tutorial/install.py +++ b/gallery/tutorial/install.py @@ -28,6 +28,12 @@ * Installing from third-party binary package. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # Installing From Source # ---------------------- diff --git a/gallery/tutorial/intro_topi.py b/gallery/tutorial/intro_topi.py index 17fa3ff370e54..e10a74c849c03 100644 --- a/gallery/tutorial/intro_topi.py +++ b/gallery/tutorial/intro_topi.py @@ -26,6 +26,12 @@ In this tutorial, we will see how TOPI can save us from writing boilerplate code in TVM. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import tvm import tvm.testing from tvm import te diff --git a/gallery/tutorial/introduction.py b/gallery/tutorial/introduction.py index 5fe4b4e5f775d..908a8e52c751f 100644 --- a/gallery/tutorial/introduction.py +++ b/gallery/tutorial/introduction.py @@ -45,6 +45,12 @@ #. :doc:`Compiling Deep Learning Models for GPUs ` """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # An Overview of TVM and Model Optimization # ========================================= diff --git a/gallery/tutorial/relay_quick_start.py b/gallery/tutorial/relay_quick_start.py index fd7f5aa9d7563..8910817c21177 100644 --- a/gallery/tutorial/relay_quick_start.py +++ b/gallery/tutorial/relay_quick_start.py @@ -26,6 +26,12 @@ Notice that you need to build TVM with cuda and llvm enabled. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ###################################################################### # Overview for Supported Hardware Backend of TVM # ---------------------------------------------- diff --git a/gallery/tutorial/tensor_expr_get_started.py b/gallery/tutorial/tensor_expr_get_started.py index 25ea4e8a55ee5..11186d2f1458d 100644 --- a/gallery/tutorial/tensor_expr_get_started.py +++ b/gallery/tutorial/tensor_expr_get_started.py @@ -39,6 +39,12 @@ features of TVM. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # Example 1: Writing and Scheduling Vector Addition in TE for CPU # --------------------------------------------------------------- diff --git a/gallery/tutorial/tensor_ir_blitz_course.py b/gallery/tutorial/tensor_ir_blitz_course.py index 11edc7ae9f3b9..a62fa3979393e 100644 --- a/gallery/tutorial/tensor_ir_blitz_course.py +++ b/gallery/tutorial/tensor_ir_blitz_course.py @@ -29,6 +29,12 @@ """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + import tvm from tvm.ir.module import IRModule from tvm.script import tir as T diff --git a/gallery/tutorial/tvmc_command_line_driver.py b/gallery/tutorial/tvmc_command_line_driver.py index 48e3703beb75d..ad5b37190c103 100644 --- a/gallery/tutorial/tvmc_command_line_driver.py +++ b/gallery/tutorial/tvmc_command_line_driver.py @@ -41,6 +41,12 @@ capabilities, and set the stage for understanding how TVM works. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # Using TVMC # ---------- diff --git a/gallery/tutorial/tvmc_python.py b/gallery/tutorial/tvmc_python.py index 6efc565f0a391..28b0a97450461 100644 --- a/gallery/tutorial/tvmc_python.py +++ b/gallery/tutorial/tvmc_python.py @@ -36,6 +36,12 @@ Let's start editing the python file in your favorite text editor. """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore + ################################################################################ # Step 0: Imports # ~~~~~~~~~~~~~~~ diff --git a/python/tvm/testing/utils.py b/python/tvm/testing/utils.py index 5a6ded9bcb709..96275e2af66f4 100644 --- a/python/tvm/testing/utils.py +++ b/python/tvm/testing/utils.py @@ -76,6 +76,7 @@ def test_something(): import sys import time +from pathlib import Path from typing import Optional, Callable, Union, List import pytest @@ -93,6 +94,7 @@ def test_something(): SKIP_SLOW_TESTS = os.getenv("SKIP_SLOW_TESTS", "").lower() in {"true", "1", "yes"} +IS_IN_CI = os.getenv("CI", "") == "true" skip_if_wheel_test = pytest.mark.skipif( os.getenv("WHEEL_TEST") is not None, reason="Test not supported in wheel." @@ -1613,6 +1615,51 @@ def is_ampere_or_newer(): return major >= 8 +def install_request_hook(depth: int) -> None: + """Add a wrapper around urllib.request for CI tests""" + if not IS_IN_CI: + return + + # https://sphinx-gallery.github.io/stable/faq.html#why-is-file-not-defined-what-can-i-use + base = None + msg = "" + try: + base = __file__ + msg += f"found file {__file__}\n" + except NameError: + msg += f"no file\n" + + if base is None: + hook_script_dir = Path.cwd().resolve() + msg += "used path.cwd()\n" + else: + hook_script_dir = Path(base).resolve().parent + msg += "used base()\n" + + msg += f"using depth {depth}\n" + if depth <= 0: + raise ValueError(f"depth less than 1 not supported, found: {depth}") + + # Go up the parent directories + while depth > 0: + msg += f"[depth={depth}] dir={hook_script_dir}\n" + hook_script_dir = hook_script_dir.parent + depth -= 1 + + # Ensure the specified dir is valid + hook_script_dir = hook_script_dir / "tests" / "scripts" / "request_hook" + if not hook_script_dir.exists(): + raise RuntimeError(f"Directory {hook_script_dir} does not exist:\n{msg}") + + # Import the hook and start it up (it's not included here directly to avoid + # keeping a database of URLs inside the tvm Python package + sys.path.append(str(hook_script_dir)) + # This import is intentionally delayed since it should only happen in CI + import request_hook # pylint: disable=import-outside-toplevel + + request_hook.init() + + def main(): test_file = inspect.getsourcefile(sys._getframe(1)) sys.exit(pytest.main([test_file] + sys.argv[1:])) diff --git a/tests/lint/check_request_hook.py b/tests/lint/check_request_hook.py new file mode 100644 index 0000000000000..6e5c523d1187d --- /dev/null +++ b/tests/lint/check_request_hook.py @@ -0,0 +1,92 @@ +# 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. + +import argparse +import fnmatch +import re +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parent.parent.parent +EXPECTED = """ +# sphinx_gallery_start_ignore +from tvm import testing + +testing.utils.install_request_hook(depth=3) +# sphinx_gallery_end_ignore +""".rstrip() +IGNORE_PATTERNS = ["*/micro_tvmc.py", "*/micro_train.py"] + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Check that all tutorials/docs override urllib.request.Request" + ) + parser.add_argument( + "--fix", action="store_true", help="Insert expected code into erroring files" + ) + args = parser.parse_args() + + gallery_files = (REPO_ROOT / "gallery").glob("**/*.py") + + errors = [] + for file in gallery_files: + skip = False + for ignored_file in IGNORE_PATTERNS: + if fnmatch.fnmatch(str(file), ignored_file): + skip = True + break + if skip: + continue + + with open(file) as f: + content = f.read() + + if EXPECTED not in content: + errors.append(file) + + if args.fix: + for error in errors: + with open(error) as f: + content = f.read() + + if "from __future__" in content: + # Place after the last __future__ import + new_content = re.sub( + r"((?:from __future__.*?\n)+)", r"\1\n" + EXPECTED, content, flags=re.MULTILINE + ) + else: + # Place after the module doc comment + new_content = re.sub( + r"(\"\"\"(?:.*\n)+\"\"\")", r"\1\n" + EXPECTED, content, flags=re.MULTILINE + ) + + with open(error, "w") as f: + f.write(new_content) + else: + # Don't fix, just check and print an error message + if len(errors) > 0: + print( + f"These {len(errors)} files did not contain the expected text to " + "override urllib.request.Request.\n" + "You can run 'python3 tests/lint/check_request_hook.py --fix' to " + "automatically fix these errors:\n" + f"{EXPECTED}\n\nFiles:\n" + "\n".join([str(error_path) for error_path in errors]) + ) + exit(1) + else: + print("All files successfully override urllib.request.Request") + exit(0) diff --git a/tests/scripts/request_hook/request_hook.py b/tests/scripts/request_hook/request_hook.py new file mode 100644 index 0000000000000..f24f76869e7de --- /dev/null +++ b/tests/scripts/request_hook/request_hook.py @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import urllib.request +import logging + +LOGGER = None + + +# To update this list, run the workflow with the URL to download and the SHA512 of the file +BASE = "https://tvm-ci-resources.s3.us-west-2.amazonaws.com" +URL_MAP = { + "https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/flowvision/classification/ResNet/resnet18.zip": f"{BASE}/oneflow/resnet18.zip", + "https://homes.cs.washington.edu/~cyulin/media/gnn_model/gcn_cora.torch": f"{BASE}/gcn_cora.torch", + "https://homes.cs.washington.edu/~moreau/media/vta/cat.jpg": f"{BASE}/vta_cat.jpg", + "https://people.linaro.org/~tom.gall/sine_model.tflite": f"{BASE}/sine_model.tflite", + "https://pjreddie.com/media/files/yolov3-tiny.weights?raw=true": f"{BASE}/yolov3-tiny.weights", + "https://pjreddie.com/media/files/yolov3.weights": f"{BASE}/yolov3.weights", + "http://data.mxnet.io.s3-website-us-west-1.amazonaws.com/data/val_256_q90.rec": f"{BASE}/mxnet-val_256_q90.rec", + "http://download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224.tgz": f"{BASE}/tf-mobilenet_v1_1.0_224.tgz", + "http://images.cocodataset.org/zips/val2017.zip": f"{BASE}/cocodataset-val2017.zip", + "https://bj.bcebos.com/x2paddle/models/paddle_resnet50.tar": f"{BASE}/bcebos-paddle_resnet50.tar", + "https://data.deepai.org/stanfordcars.zip": f"{BASE}/deepai-stanfordcars.zip", +} + + +class TvmRequestHook(urllib.request.Request): + def __init__(self, url, *args, **kwargs): + LOGGER.info(f"Caught access to {url}") + if url in URL_MAP: + new_url = URL_MAP[url] + LOGGER.info(f"Mapped URL {url} to {new_url}") + else: + new_url = url + super().__init__(new_url, *args, **kwargs) + + +def init(): + global LOGGER + urllib.request.Request = TvmRequestHook + LOGGER = logging.getLogger("tvm_request_hook") + LOGGER.setLevel(logging.DEBUG) + fh = logging.FileHandler("redirected_urls.log") + fh.setLevel(logging.DEBUG) + LOGGER.addHandler(fh) diff --git a/tests/scripts/task_lint.sh b/tests/scripts/task_lint.sh index 80cfc00ff7be4..8401391d20bc7 100755 --- a/tests/scripts/task_lint.sh +++ b/tests/scripts/task_lint.sh @@ -40,6 +40,9 @@ function shard1 { echo "Checking CMake <-> LibInfo options mirroring" python3 tests/lint/check_cmake_options.py + echo "Checking that all sphinx-gallery docs override urllib.request.Request" + python3 tests/lint/check_request_hook.py + echo "black check..." tests/lint/git-black.sh