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/02/01 19:46:12 UTC

[GitHub] [tvm] jwfromm commented on a change in pull request #7366: [TVMC] Allow manual shape specification in tvmc

jwfromm commented on a change in pull request #7366:
URL: https://github.com/apache/tvm/pull/7366#discussion_r568093268



##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -136,3 +138,46 @@ def tracker_host_port_from_cli(rpc_tracker_str):
         logger.info("RPC tracker port: %s", rpc_port)
 
     return rpc_hostname, rpc_port
+
+
+def parse_shape_string(inputs):
+    """Parse an input shape dictionary string to a usable dictionary.
+
+    Parameters
+    ----------
+    inputs: str
+        A string of the form "name:num1xnum2x...xnumN,name2:num1xnum2xnum3" that indicates
+        the desired shape for specific model inputs.
+
+    Returns
+    -------
+    shape_dict: dict
+        A dictionary mapping input names to their shape for use in relay frontend converters.
+    """
+    inputs = inputs.replace(" ", "")
+    # Check if the passed input is in the proper format.
+    valid_pattern = re.compile("(\w+:(\d+(x|X))*(\d)+)(,(\w+:(\d+(x|X))*(\d)+))*")
+    result = re.fullmatch(valid_pattern, inputs)

Review comment:
       @comaniac I agree the syntax is a little confusing, but discussed it with Jocelyn and there are some tradeoffs that would be made using a more Python/JSON like syntax. Since we're passing the shapes argument via command line, we cant use spaces or semicolons unless the whole argument is wrapped in quotes. For example, if we used a python like syntax such as `tvmc compile --shapes=data:-1,3,224,224 data2:10,10` the space would prevent argparse from recognizing it as a single argument. We could require quote wrapping but I personally think that is more likely to cause issues than using `x` instead of `,` to separate dimensions. Do you have a recommendation for the input format that you prefer or are you ok with always wrapping in quotes?




----------------------------------------------------------------
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.

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