Skip to content

Commit

Permalink
added spaces after the python codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
CircleSpin committed Dec 16, 2021
1 parent cf145ab commit 097c90d
Showing 1 changed file with 51 additions and 30 deletions.
81 changes: 51 additions & 30 deletions gallery/how_to/use_tvms_python_api/tvmc_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
# Step 0: Imports
# ~~~~~~~~~~~~~~~
#
# .. code-block:: python
# .. code-block:: python
#
# from tvm.driver import tvmc
#
#

################################################################################
# Step 1: Load a model
Expand All @@ -55,7 +56,8 @@
# support are: Keras, ONNX, Tensorflow, TFLite, and PyTorch.
#
# .. code-block:: python
# model = tvmc.load('my_model.onnx') #Step 1: Load
#
# model = tvmc.load('my_model.onnx') #Step 1: Load
#
# If you'd like to see the Relay, you can run:
# ``model.summary()``
Expand All @@ -65,10 +67,11 @@
# TVM cannot automatically search for it.
#
# .. code-block:: python
# ### Step 1: Load shape_dict Style
# # shape_dict = {'model_input_name1': [1, 3, 224, 224], 'input2': [1, 2, 3, 4], ...} #example format with random numbers
# # model = tvmc.load(model_path, shape_dict=shape_dict) #Step 1: Load + shape_dict
#
# ### Step 1: Load shape_dict Style
# # shape_dict = {'model_input_name1': [1, 3, 224, 224], 'input2': [1, 2, 3, 4], ...} #example format with random numbers
# # model = tvmc.load(model_path, shape_dict=shape_dict) #Step 1: Load + shape_dict
#
# A suggested way to see the model's input/shape_dict is via `netron <https://netron.app/>`_, . After opening the model,
# click the first node to see the name(s) and shape(s) in the inputs section.

Expand All @@ -89,8 +92,10 @@
# 2. llvm (CPU)
# 3. llvm -mcpu=cascadelake (Intel CPU)
#
# .. code-block:: python
# package = tvmc.compile(model, target="llvm") #Step 2: Compile
# .. code-block:: python
#
# package = tvmc.compile(model, target="llvm") #Step 2: Compile
#
#
# The compilation step returns a package.
#
Expand All @@ -102,8 +107,9 @@
# The compiled package can now be run on the hardware target. The device
# input options are: CPU, Cuda, CL, Metal, and Vulkan.
#
# .. code-block:: python
# result = tvmc.run(package, device="cpu") #Step 3: Run
# .. code-block:: python
#
# result = tvmc.run(package, device="cpu") #Step 3: Run
#
# And you can print the results:
# ``print(results)``
Expand All @@ -120,8 +126,9 @@
#
# The target is the same as compile.
#
# .. code-block:: python
# tvmc.tune(model, target="llvm") #Step 1.5: Optional Tune
# .. code-block:: python
#
# tvmc.tune(model, target="llvm") #Step 1.5: Optional Tune
#
# The terminal output should look like:
# [Task 1/13] Current/Best: 82.00/ 106.29 GFLOPS | Progress: (48/769) | 18.56 s
Expand All @@ -140,8 +147,9 @@
# Save and then start the process in the terminal:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# .. code-block:: python
# python my_tvmc_script.py
# .. code-block:: python
#
# python my_tvmc_script.py
#
# Note: Your fans may become very active
#
Expand All @@ -150,15 +158,18 @@
# Example results:
# ~~~~~~~~~~~~~~~~
#
# .. code-block:: python
# Time elapsed for training: 18.99 s
# Execution time summary:
# mean (ms) max (ms) min (ms) std (ms)
# 25.24 26.12 24.89 0.38
#
# Output Names:
# ['output_0']
# .. code-block:: python
#
# Time elapsed for training: 18.99 s
# Execution time summary:
# mean (ms) max (ms) min (ms) std (ms)
# 25.24 26.12 24.89 0.38
#
#
# Output Names:
# ['output_0']
#


################################################################################
# Additional TVMC Functionalities
Expand All @@ -172,9 +183,11 @@
# To make things faster for later, after loading the model (Step 1) save the Relay version.
# The model will then appear where you saved it for later in the coverted syntax.
#
# .. code-block:: python
# model = tvmc.load('my_model.onnx') #Step 1: Load
# model.save(desired_model_path)
# .. code-block:: python
#
# model = tvmc.load('my_model.onnx') #Step 1: Load
# model.save(desired_model_path)
#
#

################################################################################
Expand All @@ -183,11 +196,13 @@
#
# After the model has been compiled (Step 2) the package also is also saveable.
#
# .. code-block:: python
# tvmc.compile(model, target="llvm", package_path="whatever")
# .. code-block:: python
#
# tvmc.compile(model, target="llvm", package_path="whatever")
#
# new_package = tvmc.TVMCPackage(package_path="whatever")
# result = tvmc.run(new_package) #Step 3: Run
#
# new_package = tvmc.TVMCPackage(package_path="whatever")
# result = tvmc.run(new_package) #Step 3: Run
#

################################################################################
Expand All @@ -198,8 +213,10 @@
# The search space of the schedules is automatically generated unlike
# previously where they needed to be hand written. (Learn more: 1, 2)
#
# .. code-block:: python
# tvmc.tune(model, target="llvm", enable_autoscheduler = True)
# .. code-block:: python
#
# tvmc.tune(model, target="llvm", enable_autoscheduler = True)
#
#

################################################################################
Expand All @@ -210,6 +227,7 @@
#
# Method 1:
# .. code-block:: python
#
# log_file = "hello.json"
#
# # Run tuning
Expand All @@ -222,6 +240,7 @@
#
# Method 2:
# .. code-block:: python
#
# # Run tuning
# tuning_records = tvmc.tune(model, target="llvm")
#
Expand All @@ -240,6 +259,7 @@
# increase the searching time frame:
#
# .. code-block:: python
#
# tvmc.tune(model,trials=10000,timeout=10,)
#

Expand All @@ -255,6 +275,7 @@
# Within the TVMC Script include the following and adjust accordingly:
#
# .. code-block:: python
#
# tvmc.tune(
# model,
# target=target, # Compilation target as string // Device to compile for
Expand Down

0 comments on commit 097c90d

Please sign in to comment.