leandron commented on a change in pull request #8253:
URL: https://github.com/apache/tvm/pull/8253#discussion_r651615824



##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -415,3 +415,86 @@ def parse_shape_string(inputs_string):
         shape_dict[name] = shape
 
     return shape_dict
+
+
+def set_config_value(name, value, config_type):
+    """Set a PassContext configuration value according to its value"""
+
+    if config_type == "IntImm":
+        # "Bool" configurations in the PassContext are recognized as
+        # IntImm, so deal with this case here
+        mapping_values = {
+            "false": False,
+            "true": True,
+        }
+
+        if value.isdigit():
+            parsed_value = int(value)
+        else:
+            # if not an int, accept only values on the mapping table, case 
insensitive
+            parsed_value = mapping_values.get(value.lower(), None)
+
+        if parsed_value is None:
+            raise TVMCException(f"Invalid value '{value}' for configuration 
'{name}'. ")
+
+    if config_type == "runtime.String":
+        parsed_value = value

Review comment:
       I did some investigation on this, and wrt to the `distutils` I didn't 
want to add that dependency here, because I think it would be a a bit misplaced.
   
   Also wrt to the `json` approach, I think it would still require more 
validation because the allowed values for that option are "int numbers", "true" 
or "false", and opening that to "json.loads" would add all sorts of json 
passing, then requiring more validation. That's why I added my own mapping 
table.




-- 
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:
[email protected]


Reply via email to