You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tvm.apache.org by "Leandro Nunes (Arm) via TVM Discuss" <no...@discuss.tvm.ai> on 2020/08/27 17:36:59 UTC

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior


In the context of the [command-line driver PR](https://github.com/apache/incubator-tvm/pull/6302), it was possible to notice some issues in the way different `ModuleNode` subclasses - such as `ONNXSourceModuleNode`, `StackVMModuleNode`, `LLVMModuleNode`, etc. - behave, with regards to `SaveToFile`.

**Example:** `LLVMModuleNode` will fail in case you ask for an unsupported format, and give an error. Other classes like `StackVMModuleNode` will simply ignore the format you ask and give you a create a file (path from `file_name`) with binary serialization of the module.

This RFC intends to get a common understanding on what we should expect (or improve) from `void SaveToFile(file_name, format)`.

**Problem**

Based on the context above, it was possible to identify two related problems:

* P1: Different classes will behave differently for the requested formats
* P2: It is impossible to know beforehand, which formats are supported by each class

**Proposed Solutions**

To solve P2, we can (1) implement a new attribute for the `ModuleNode` class, that reports what are the expected formats that `ModuleNode` supports, as a list of strings, and (2) provide a Python API for the supported formats to be retrieved, as a list.

Addressing P1 then consists of improving `ModuleNode.SaveToFile` then should only accept `format` that are on that supported list, and fail with error in case there is a legitimate issue generating the file or in case the format is not supported.

Some rework will be needed on existing classes to make this uniform among different `ModuleNode` implementations.

**Final Remarks**

I think this is fairly small topic, but wanted to open this discussion as this will affect existing Module implementations.

 cc @comaniac, @tqchen, @ramana-arm





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/ee4abd774bed8527698a0c069c9026f04b5790a790698cbe4875fc56930cfcf7).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by Jared Roesch via TVM Discuss <no...@discuss.tvm.ai>.

I think it makes sense to be stricter. :+1:





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/8) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/d8d4224e5a528b76fa78b677bc18b1d1ccf5c475e2446875bb0cab353ebaf2cf).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by "Leandro Nunes (Arm) via TVM Discuss" <no...@discuss.tvm.ai>.

[quote="tqchen, post:6, topic:7741"]
We can try to make things consistent, by only supporting the correct format, and report error when file format is not supported.
[/quote]

Agreed. That is exactly the point.

The main use for the sake of command line driver is to be able to export files that will help to understand what is going on when using a particular target. That is why it is useful, for example to be able to export the `ll` file when using llvm, for example.





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/7) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/85b2b3b3ac98a6c5c8fc8e09757281ddfc7808d7b6295bb2c359b1a723bdc728).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by tqchen via TVM Discuss <no...@discuss.tvm.ai>.

SaveToFile is more of a low-level API, that is not very consistently defined.

For most multiple module case, we use `mod.export_library` instead.

And the logic is used as follows:
- LLVM/C module use SaveToFile to save the right source code.
- Other modules, use SaveToBinary to serialize the ptx/opencl into the binary segment of the source code.

My take is that given we encourage  `mod.export_library`  in most of the time. We do not have to complicate the SaveToFile API and can keep things.

We can try to make things consistent, by only supporting the correct format, and report error when file format is not supported.

User should always use `mod.export_library` to get a packaged version of the output.





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/6) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/4db5be591810216767c68d1f8f59322cc11b02cb145e102b4f520e9fe7a73d81).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by "Leandro Nunes (Arm) via TVM Discuss" <no...@discuss.tvm.ai>.

I'm thinking about opening this as an issue on GitHub. Are there any other comments? maybe from @jroesch @thierry - feel free to add others.





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/5) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/03b7c691f43a9cafcb9e51d8b8364984f706f7b37230fe1a9eff95640073355b).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by "Leandro Nunes (Arm) via TVM Discuss" <no...@discuss.tvm.ai>.

[quote="zhiics, post:3, topic:7741"]
a `MetadataModule` could contain a DSOModule and one or more CSourceModule/JSONRuntimeModule. It seems a bit hard to save them out as one file for compilation though.
[/quote]

I see what you mean. It might be the case, for some modules, they don't offer any export format, which means in my P2 (above) they would have an empty list as "supported format to export files".





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/4) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/b5fb5fe1dd0a3ae2dbf09616a846eb68a5858021aa2ccfa36389240f9dd5705f).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by Zhi via TVM Discuss <no...@discuss.tvm.ai>.

I think another situation where `SaveToFile` is hard is when we have multiple modules imported. For example, a `MetadataModule` could contain a DSOModule and one or more CSourceModule/JSONRuntimeModule. It seems a bit hard to save them out as one file for compilation though.

I think this is not quite directly related to the problem you solve to but it could complicate the problem.





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/e675d03af5332f0ab346c28a8040d9d861f71f8646153fad2b15e8289120d7de).

[TVM Discuss] [Development/RFC] [RFC] SaveToFile(file_name, format) expected behavior

Posted by "Cody H. Yu via TVM Discuss" <no...@discuss.tvm.ai>.

Also cc @zhiics for comments.





---
[Visit Topic](https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/e99644c2d994b25e4139acd5d6f693c6b835dc79a690d7c569bea3d16b664ac4).