Mousius commented on a change in pull request #30: URL: https://github.com/apache/tvm-rfcs/pull/30#discussion_r716687900
########## File path: rfcs/0030-tvmc-comand-line-configuration-files.md ########## @@ -0,0 +1,165 @@ +- Feature Name: Command Line Configuration Files +- Start Date: 2021-08-09 +- RFC PR: [apache/tvm-rfcs#30](https://github.com/apache/tvm-rfcs/pull/30) +- GitHub Issue: [apache/tvm#0000](https://github.com/apache/tvm/issues/0000) + +# Summary +[summary]: #summary + +Collecting common configurations for users of TVM and exposing them gracefully in `tvmc` using a `--config` option. The scope of this RFC is to introducing the configuration files, the placement of them and demonstrating usage. + +# Motivation +[motivation]: #motivation + +When a user first approaches TVM, choosing an appropriate configuration can be difficult, this is increasingly true in embedded systems where the configuration is not only a collection of devices but also how those devices are interfaced (see [Arm® Corstone™-300 reference package](https://developer.arm.com/ip-products/subsystem/corstone/corstone-300)). Trying to specify all of this in a target string or via command line arguments would be error prone and tedious. Predefining these in a common format allows users to get started and take the configurations for their own use cases easily. + +# Guide-level explanation +[guide-level-explanation]: #guide-level-explanation + +## TVM Hosted Configurations +Configurations will be stored as [JSON5](https://json5.org/) at `configs/<TYPE>/<NAME>.json`, this top level directory will enable other tooling to load configurations just as easily a `tvmc` and provide easy sign posting for users looking for configurations. + +A user coming to `tvmc` will begin with a default configuration which sets sensible defaults, such that `tvmc compile my_model.tflite` works out of the box. This is enabled by a `configs/host/default.json` which is likely to specify: + +``` +{ + targets: [ + { + kind: "llvm" + } + ] +} +``` + +As a more substantial example, you can imagine an embedded board configuration such as the [Arm® Corstone™-300 reference package](https://developer.arm.com/ip-products/subsystem/corstone/corstone-300), which would exist under `configs/boards/corstone-300.json`: + +```json +{ + "output_format": "mlf", + "executor": { + "kind": "aot", + "unpacked-api": true + }, + "targets": [ + { + "kind": "ethos-u", + "accelerator_config": "ethos-u55-32" + }, + { + "kind": "cmsisnn", + "mattr": "+fp" + }, + { + "kind": "llvm" + } + ] +} +``` + +This would be used if the user simply specifies `--config=corstone-300`, as in the following example: +``` +tvmc compile --config=corstone-300 my_model.tflite +``` + +## User Provided Configurations +The default search path, as illustrated above, is to find a matching `<NAME>.json` to an argument `--config=<NAME>`. A user can instead specify a path in the `--config` argument such as: + +```bash +--config=./my.json +--config=/etc/devices/my_secret_board.json +``` + +By default, TVM will prefer files explicitly specified as a path instead of hosted files. + +## Combination with existing parameters +In the case of `tvmc`, `--config` will work alongside other arguments. Ideally anything specifiable in JSON will be specifiable in the command line to allow users to make small alterations such as: + +``` +tvmc \ + compile \ + --config=corstone-300 \ + --executor-aot-unpacked-api=0 +``` + +Which allows experimentation with different parameters that can then be added to a custom JSON. Complex configurations which aren't easily represented well in CLI arguments may exist and can continue to be represented only in JSON. + +# Reference-level explanation +[reference-level-explanation]: #reference-level-explanation + +To get the `--config` flag, `argparse` can be used as an early pass over the arguments to collect the single configuration file to specify. It's important to note that only one configuration would be + +This will change the behaviour of how `tvmc` utilises `argparse`, it will first translate arguments from `argparse` into an internal dictionary of attributes and then apply those over the top of any specified configuration files. This means the default options for `argparse` are essentially nulled as they won't be aware of configuration files until after the arguments are parsed. The hierarchy is therefore: +1. Arguments parsed by `argparse` +2. Configuration file specified (defaults to `default`) +3. Internal defaults for arguments in `tvmc` + +## Example: merging with new config +Because these results are merged, the underlying defaults remain in `tvmc` rather than in `default.json` to ensure the user doesn't create a resulting configuration which additively makes no sense (for example, being based on an `llvm` target or other defaults). For example, the default in `tvmc` would be: +```json +{ "autotuning_runs": 10 } +``` +Which would then be extended with `--config=default` (`{ "targets": [{ "kind": "llvm" }], "executor": { "kind": "graph", "system-lib": true } }`): Review comment: This is demonstrating a hypothetical configuration layout rather than a concrete layout, in this case I'm using the improvements from [Migrating Target Attributes to IRModule](https://github.com/apache/tvm-rfcs/pull/29) to allow for a more detailed example. In this case it doesn't make a difference as the example is for the merging of portions of the JSON rather than any specific value. -- 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]
