Mousius commented on a change in pull request #30: URL: https://github.com/apache/tvm-rfcs/pull/30#discussion_r714015215
########## File path: rfcs/0030-tvmc-comand-line-configuration-files.md ########## @@ -0,0 +1,119 @@ +- 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. + +# 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. + +# Reference-level explanation +[reference-level-explanation]: #reference-level-explanation + +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` + +Because these results are additive 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 being based on an `llvm` target or other defaults. Review comment: I changed `additive` to merged, I meant the behaviour was `additive`, in reality the CLI would specify the targets with `--target=c,llvm` that would act on previous `Target` definitions but otherwise remove them. ########## File path: rfcs/0030-tvmc-comand-line-configuration-files.md ########## @@ -0,0 +1,119 @@ +- 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. + +# 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. + +# Reference-level explanation +[reference-level-explanation]: #reference-level-explanation + +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` + +Because these results are additive 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 being based on an `llvm` target or other defaults. + +The configuration files will be loaded using [json5](https://pypi.org/project/json5/) to enable us to add comments and further details to the JSON files. + +# Drawbacks +[drawbacks]: #drawbacks + +Although this presents a simpler interface for new users, the options become more complex for power users who want to mix and match arguments. This is mitigated by specifying simple rules for how these are composed. + +The convention of `--config` being read first then all other arguments is less intuitive than left to right parsing, but fits better with the current `argparse` infrastructure. + +# Rationale and alternatives +[rationale-and-alternatives]: #rationale-and-alternatives Review comment: I linked to the specific `json5` package, the intention is to use JSON similar to other areas of TVM but with some more flexibility in terms of comments etc. As regards YAML, it lacks structure which seems completely out of place for a configuration format which doesn't change very often. -- 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]
