Skip to content

Commit

Permalink
[docs] Remove empty code blocks
Browse files Browse the repository at this point in the history
This fixes some of the issues highlighted in apache#13668, the parser that
checks to ensure that the hidden import is placed in the right spot was
incorrect, this includes some fixes to get it working for the cases in
that issue.
  • Loading branch information
driazati committed Jan 4, 2023
1 parent 45a8a44 commit bd890bf
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 57 deletions.
3 changes: 1 addition & 2 deletions gallery/how_to/compile_models/from_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
pip install opencv-python
"""

# numpy and matplotlib
# 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
import sys
Expand Down
3 changes: 1 addition & 2 deletions gallery/how_to/compile_models/from_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
Please refer to https://www.tensorflow.org/install
"""

# tvm, relay
# 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
from tvm import relay
Expand Down
5 changes: 3 additions & 2 deletions gallery/how_to/deploy_models/deploy_prequantized.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
Once loaded, we can run compiled, quantized models on any hardware TVM supports.
"""

#################################################################################
# First, necessary imports

# 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

import numpy as np
Expand Down
7 changes: 4 additions & 3 deletions gallery/how_to/deploy_models/deploy_prequantized_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@
"""

###############################################################################
# Necessary imports
# -----------------

# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

###############################################################################
# Necessary imports
# -----------------
import os

import numpy as np
Expand Down
11 changes: 6 additions & 5 deletions gallery/how_to/deploy_models/deploy_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@
sparse speed using fake weights to see the benefit of structured sparsity.
"""

###############################################################################
# Load Required Modules
# ---------------------
# Other than TVM, scipy, the latest transformers, and
# tensorflow 2.2+ are required.

# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

###############################################################################
# Load Required Modules
# ---------------------
# Other than TVM, scipy, the latest transformers, and
# tensorflow 2.2+ are required.
import os
import tvm
import time
Expand Down
11 changes: 6 additions & 5 deletions gallery/how_to/extend_tvm/bring_your_own_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@
ctypes.CDLL('my-datatype-lib.so', ctypes.RTLD_GLOBAL)
"""

######################
# A Simple TVM Program
# --------------------
#
# We'll begin by writing a simple program in TVM; afterwards, we will re-write it to use custom datatypes.

# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

######################
# A Simple TVM Program
# --------------------
#
# We'll begin by writing a simple program in TVM; afterwards, we will re-write it to use custom datatypes.
import tvm
from tvm import relay

Expand Down
13 changes: 6 additions & 7 deletions gallery/how_to/optimize_operators/opt_conv_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
"""

# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

################################################################
# Preparation and Algorithm
# -------------------------
Expand All @@ -44,7 +38,12 @@
# dimensions. The batch size is 256. Convolution filters contain 512 filters
# of size 3 x 3. We use stride size 1 and padding size 1 for the
# convolution. The following code defines the convolution algorithm in TVM.
#

# 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
Expand Down
12 changes: 6 additions & 6 deletions gallery/how_to/optimize_operators/opt_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@
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
# ------------------------
# In this tutorial, we will demo how to use TVM to optimize matrix multiplication.
# Before actually demonstrating, we first define these variables.
# Then we write a baseline implementation, the simplest way to write a matrix multiplication 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
Expand Down
3 changes: 1 addition & 2 deletions gallery/how_to/work_with_pytorch/using_as_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
Using the decorator `as_torch`, users can wrap TVMScript code into a PyTorch nn.Module naturally.
"""

# Import PyTorch, as well as necessary libraries
# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

# Import PyTorch, as well as necessary libraries
import torch
import torch.nn.functional as F
import torch.utils.benchmark as benchmark
Expand Down
3 changes: 1 addition & 2 deletions gallery/how_to/work_with_pytorch/using_optimized_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
To follow this tutorial, PyTorch, as well as TorchVision, should be installed.
"""

# Import PyTorch
# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

# Import PyTorch
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down
12 changes: 6 additions & 6 deletions gallery/tutorial/autotvm_relay_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
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
Expand All @@ -60,6 +54,12 @@
# and post-processing of the image data, the TVM Relay framework, and the TVM
# Graph Executor.

# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

import onnx
from tvm.contrib.download import download_testdata
from PIL import Image
Expand Down
12 changes: 6 additions & 6 deletions gallery/tutorial/relay_quick_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
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
# ----------------------------------------------
Expand All @@ -43,6 +37,12 @@
# In this tutorial, we'll choose cuda and llvm as target backends.
# To begin with, let's import Relay and TVM.

# sphinx_gallery_start_ignore
from tvm import testing

testing.utils.install_request_hook(depth=3)
# sphinx_gallery_end_ignore

import numpy as np

from tvm import relay
Expand Down
12 changes: 6 additions & 6 deletions gallery/tutorial/tensor_expr_get_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
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
# ---------------------------------------------------------------
Expand All @@ -53,6 +47,12 @@
# vector addition, followed by a schedule targeted towards a CPU.
# We begin by initializing a TVM environment.

# 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
Expand Down
10 changes: 7 additions & 3 deletions tests/lint/check_request_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ def find_code_block_line(lines: List[str]) -> Optional[int]:
"""
in_multiline_string = False
in_sphinx_directive = False
in_standalone_comment = True

i = 0
lines = lines[APACHE_HEADER_LINES:]
while i < len(lines):
line = lines[i].strip()
in_comment = False
if '"""' in line:
in_multiline_string = not in_multiline_string
elif "# sphinx_gallery_" in line:
in_sphinx_directive = not in_sphinx_directive
elif line.startswith("#") or in_sphinx_directive or in_multiline_string or line == "":
elif line.startswith("##") or in_sphinx_directive or in_multiline_string or line == "":
in_standalone_comment = False
pass
elif line.startswith("#") and not in_standalone_comment:
pass
else:
return i
return i + APACHE_HEADER_LINES
i += 1

return None
Expand All @@ -69,7 +74,6 @@ def find_code_block_line(lines: List[str]) -> Optional[int]:
args = parser.parse_args()

gallery_files = (REPO_ROOT / "gallery").glob("**/*.py")
# gallery_files = [x for x in gallery_files if "cross_compi" in str(x)]

errors = []
for file in gallery_files:
Expand Down

0 comments on commit bd890bf

Please sign in to comment.