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 20:03:26 UTC

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

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



##########
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:
       To be honest, I'm totally fine with quotes in the command line, and we actually use it in TVMC already. For example, when specifying target, you cannot avoid using quotes for targets like `llvm -mcpu=core-axv2`. In fact, although we haven't fully landed the new target, the ultimate goal is to get rid of plain string target format and support JSON format. IMHO, it would be better if the format/syntax are consistent.
   
   Meanwhile, if having quotes in the command line is a concern, it might be worthwhile to consider taking a command line file. See https://docs.python.org/3/library/argparse.html#fromfile-prefix-chars for reference. In this case, we can have:
   
   ```
   # shapes.txt
   --input-shapes
   data:[-1,3,224,224] data2: [10,10]
   ```
   
   ```
   tvmc compile @shapes.txt
   ```
   
   




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