You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/12/31 03:22:28 UTC

[GitHub] [tvm] leeexyz opened a new pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

leeexyz opened a new pull request #9817:
URL: https://github.com/apache/tvm/pull/9817


   Hi All,
   
   Sometimes, we should manipulate the Passes order or add new Passes not only for `Relay Pass` but for `TIR Pass`.  the This PR add the configuration `tir.add_lower_pass` to `--pass-config`. It supports two types of `TIR Pass`, one is the built-in pass in TVM and another one is the external customized pass that is loaded by `importlib`.
   
   Some use cases.
   
   ```bash
   ~/project/apache/tvm$ python -m tvm.driver.tvmc compile --target "llvm"  \
                                                      --output resnet50-v2-7-tvm.tar resnet50.onnx \
                                                      --pass-config "tir.add_lower_pass=1,tir.transform.UnrollLoop,2,tir.transform.UnrollLoop" 
   {'tir.add_lower_pass': [(1, PrimFuncPass(tir.UnrollLoop, opt_level=0)), (2, PrimFuncPass(tir.UnrollLoop, opt_level=0))]}
   ```
   
   ```bash
   ~/project/apache/tvm$ python -m tvm.driver.tvmc compile --target "llvm" \
                                                      --output resnet50-v2-7-tvm.tar resnet50.onnx \
                                                      --pass-config "tir.add_lower_pass=1,tir.transform.UnrollLoop,2,tir.transform.UnrollLoop" \
                                                      --pass-config "tir.add_lower_pass=1,tir.transform.UnrollLoop"
   {'tir.add_lower_pass': [(1, PrimFuncPass(tir.UnrollLoop, opt_level=0)), (2, PrimFuncPass(tir.UnrollLoop, opt_level=0)), (1, PrimFuncPass(tir.UnrollLoop, opt_level=0))]}
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] leeexyz commented on a change in pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

Posted by GitBox <gi...@apache.org>.
leeexyz commented on a change in pull request #9817:
URL: https://github.com/apache/tvm/pull/9817#discussion_r778510775



##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -527,11 +560,44 @@ def get_pass_config_value(name, value, config_type):
             parsed_value = mapping_values.get(value.lower(), None)
 
         if parsed_value is None:
-            raise TVMCException(f"Invalid value '{value}' for configuration '{name}'. ")
+            raise TVMCException(f"Invalid value '{value}' for configuration '{name}'.")
 
-    if config_type == "runtime.String":
+    elif config_type == "runtime.String":
         parsed_value = value
 
+    elif config_type == "Array":
+        if name == "tir.add_lower_pass":

Review comment:
       @leandron Thanks! What about this simplest one. But the help message is kind of messy. It seems argparse has the default width.
   
   ```python
   parser.add_argument(
       "--pass-config",
       action="append",
       metavar=("name=value"),
       help="configurations to be used at compile time. This option can be provided multiple "
       "times, each one to set one configuration value, "
       "e.g. '--pass-config relay.backend.use_auto_scheduler=0', "
       "e.g. '--pass-config tir.add_lower_pass=opt_level0,tir_pass0,opt_level1,tir_pass1'."
   )
   # help message
   --pass-config name=value
                         configurations to be used at compile time. This option
                         can be provided multiple times, each one to set one
                         configuration value, e.g. '--pass-config
                         relay.backend.use_auto_scheduler=0', e.g. '--pass-
                         config tir.add_lower_pass=opt_level0,tir_pass0,opt_lev
                         el1,tir_pass1'.
   ```
   
   My concern is how we can present the help message usefully and elegantly. For `--pass-config`, we want to show it clearly with indents and clarify all the usages.
   
   Currently, we have the following configs.
   
   ```python 
   # Relay pass config
   "relay.backend.use_meta_schedule": {"type": "IntImm"}, 
   "relay.fallback_device_type": {"type": "IntImm"}, 
   "relay.FuseOps.max_depth": {"type": "IntImm"}, 
   "relay.backend.use_auto_scheduler": {"type": "IntImm"}
   # TIR pass config
   "tir.detect_global_barrier": {"type": "IntImm"}, 
   "tir.debug_keep_trivial_loop": {"type": "IntImm"}, 
   "tir.disable_vectorize": {"type": "IntImm"}, 
   "tir.noalias": {"type": "IntImm"}, 
   "tir.instrument_bound_checkers": {"type": "IntImm"}, 
   "tir.is_entry_func": {"type": "IntImm"}, 
   "tir.disable_assert": {"type": "IntImm"}, 
   "tir.add_lower_pass": {"type": "Array"}, 
   # Not support yet
   "tir.LoopPartition": {"type": "tir.transform.LoopPartitionConfig"},
   "tir.UnrollLoop": {"type": "tir.transform.UnrollLoopConfig"},
   "tir.HoistIfThenElse": {"type": "tir.transform.HoistIfThenElseConfig"},
   "tir.InjectDoubleBuffer": {"type": "tir.transform.InjectDoubleBufferConfig"}, 
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] leandron merged pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

Posted by GitBox <gi...@apache.org>.
leandron merged pull request #9817:
URL: https://github.com/apache/tvm/pull/9817


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] leeexyz commented on pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

Posted by GitBox <gi...@apache.org>.
leeexyz commented on pull request #9817:
URL: https://github.com/apache/tvm/pull/9817#issuecomment-1019289781


   cc @leandron @junrushao1994 @comaniac 😊


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] leandron commented on pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

Posted by GitBox <gi...@apache.org>.
leandron commented on pull request #9817:
URL: https://github.com/apache/tvm/pull/9817#issuecomment-1039135305


   Thanks @leeexyz, this is merged now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] leandron commented on a change in pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #9817:
URL: https://github.com/apache/tvm/pull/9817#discussion_r778094126



##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -527,11 +560,44 @@ def get_pass_config_value(name, value, config_type):
             parsed_value = mapping_values.get(value.lower(), None)
 
         if parsed_value is None:
-            raise TVMCException(f"Invalid value '{value}' for configuration '{name}'. ")
+            raise TVMCException(f"Invalid value '{value}' for configuration '{name}'.")
 
-    if config_type == "runtime.String":
+    elif config_type == "runtime.String":
         parsed_value = value
 
+    elif config_type == "Array":
+        if name == "tir.add_lower_pass":

Review comment:
       I think as a feature it is useful and OK to have this. 
   
   Do you mind just updating the help option for `--pass-config` to reflect the usage with `tir.add_lower_pass`?
   
   Help option is here:
   https://github.com/apache/tvm/blob/9cc1df60701d6d46577d028c211bb568225fc4f1/python/tvm/driver/tvmc/compiler.py#L89-L96




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] leeexyz commented on pull request #9817: [TVMC] Add configuration `tir.add_lower_pass` to option `--pass-config`

Posted by GitBox <gi...@apache.org>.
leeexyz commented on pull request #9817:
URL: https://github.com/apache/tvm/pull/9817#issuecomment-1011736679


   @leandron Would you mind helping me review again? :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org