gromero commented on a change in pull request #9229:
URL: https://github.com/apache/tvm/pull/9229#discussion_r735760958



##########
File path: python/tvm/driver/tvmc/runner.py
##########
@@ -97,7 +111,55 @@ def add_run_parser(subparsers):
         help="hostname (required) and port (optional, defaults to 9090) of the 
RPC tracker, "
         "e.g. '192.168.0.100:9999'",
     )
-    parser.add_argument("FILE", help="path to the compiled module file")
+    parser.add_argument(
+        "PATH",
+        help="path to the compiled module file or to the project directory 
(micro devices only).",
+    )
+
+    #
+    # Hack to lookahead if 'run' was selected and make
+    # two dynamic parsers (in micro.py and in runner.py) work.
+    #
+    # print(sys.argv)
+    if "run" in sys.argv:

Review comment:
       That is a tricky one. The tricky thing here is that due to tvmc design - 
that uses a decorator to build a list of functions that will later be called 
explicitly to augment the parser - a call to `parser_known_args()` can not exit 
when the command line doesn't match, i.e. when a command line doesn't even 
satisfies the minimum required syntax so `parser_known_args()` can return, so 
it exists and can't even provide a known/unknown list of options.
   
   If `parser_known_args()` returns to early there won't be a chance of calling 
the second function responsible to build the second dynamic parser (in this 
case parser in micro.py will be called secondly, as per import order in 
`__init__.py`). So when the first call to  `parser_known_args()` returns and 
prints the options missing it will miss the options that would be included by 
the second function responsible to build the second dynamic parser.
   
   The case you've asked about ("what if `run` is e.g. the value of 
--template-dir?") nicely works:
   
   ``gromero@amd:~/git/tvm$ tvmc micro create-project /tmp/x16 
~/scripts/sine.tar template --template-dir 
./apps/microtvm/run_adhoc_template/template_project --project-option 
zephyr_board=stm32f746g_disco project_type=host_driven 
   gromero@amd:~/git/tvm$ ls -l /tmp/x16
   total 108
   -rw-rw-r-- 1 gromero gromero  1404 Oct 25 14:16 boards.json
   -rw-rw-r-- 1 gromero gromero  2245 Oct 25 14:30 CMakeLists.txt
   drwxrwxr-x 4 gromero gromero  4096 Oct 25 14:30 crt
   drwxrwxr-x 2 gromero gromero  4096 Oct 25 14:30 crt_config
   -rw-rw-r-- 1 gromero gromero 25434 Oct 25 14:16 microtvm_api_server.py
   drwx------ 6 gromero gromero  4096 Jul 27 20:07 model
   -rw-rw-r-- 1 gromero gromero 51200 Jul 27 20:07 model.tar
   -rw-rw-r-- 1 gromero gromero   408 Oct 25 14:30 prj.conf
   drwxrwxr-x 2 gromero gromero  4096 Oct 25 14:16 src
   gromero@amd:~/git/tvm$ 
   ```
   
   But the corner case is actually something like:
   ```
   gromero@amd:~/git/tvm$ tvmc micro create-project /tmp/x17 ~/scripts/sine.tar 
template --template-dir ./apps/microtvm/run_adhoc_templatez/template_project -x 
run
   usage: tvmc [-h] [-v] [--version] {tune,compile,run} ...
   tvmc: error: invalid choice: 'micro' (choose from 'tune', 'compile', 'run')
   ```
   Note that 'micro' context is not understood because `parse_known_args()` 
returns before parser in `micro.py` has the chance to augment the parser and 
add the micro context. If I add the dynamic parser in `micro.py` the dynamic 
parser `runner.py` will suffer that "vanishment" instead.
   
   However to me the corner case seems to be a very rare to happen, hence the 
"lookahead" hack. 




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to