You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tvm.apache.org by Tristan Konolige via Apache TVM Discuss <no...@discuss.tvm.ai> on 2020/09/15 23:15:05 UTC

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script


## Current issue

TVM current has two different hybrid scripts: `te.hybrid.script` and `tvm.hybrid.script`. This leads to confusion as both scripts are similar but share different use cases and properties. This is especially confusing for new users as hybrid script can refer to either of these names. (I have had discussions with people where we were both referring to different hybrid scripts.)

I propose we rename `tvm.hybrid.script` as it is going to be used a lot in the future and is newer than `te.hybrid.script`. I have a couple of possible new names.

- tir.script: this name reflects the current use of `tvm.hybrid.script` as a sugar for TIR.
- tvm.script: this is a similar name to torch's torchscript. Although `tvm.hybrid.script` supports only TIR right now, in the future we would like it to support relay. This generic name covers this use case.
- tvm.script.tir and tvm.script.relay: like tvm.script, but we make the difference between script supporting TIR and script supporting Relay. In the future this may cause an issue if we have a unified script for TIR and Relay (which is a goal of `tvm.hybrid.script`).

Personally I am leaning towards tvm.script as I think it will make the most sense to new users and communicates the end goals we have.

Which options does everyone like? If you don't like any of these, could you propose a new name?

## Disadvantages

Name changing is churn, and can make old docs/discuss posts out of date. But right now there is not that much usage of `tvm.hybrid.script`. Renaming it earlier instead of later will cause fewer issues. We can also mark the `tvm.hybrid.script` identifier as deprecated to allow users time to switch over to the new naming scheme.


The initial `tvm.hybrid.script` PR: https://discuss.tvm.apache.org/t/rfc-hybrid-script-support-for-tir/7516





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/d86c56a60a43d080a9088d34bb2b26d3fcbd34cc7f6051e90e7383162998d611).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Tristan Konolige via Apache TVM Discuss <no...@discuss.tvm.ai>.

I've put up an initial PR here: https://github.com/apache/incubator-tvm/pull/6522.

An issue has come up, what do we name the python module?

## Option 1
We name the module `tvm.tvmscript`.
Example usage:
```python
import tvm

# Can still use this though
@tvm.script # or tvm.script.tir
def my_func():
  pass

@tvm.script # or tvm.script.module
class Mod:
  def my_func():
    pass

string = my_func.asscript()
assert(string == tvm.tvmscript.parse(string))

# can also do
from tvm import tvmscript

assert(string == tvmscript.parse(string))
```

The disadvantage here is that `tvm.tvmscript` repeats tvm twice. But it does make it explicit that the script we are using is tvm script (as opposed to hybrid script).

## Option 2
We name the module `tvm.script`. We still refer to this as "TVM Script" in all documentation, etc.
```python
import tvm

# Can't use tvm.script as it is a namespace
@tvm.script.tvm # or tvm.script.tir (see option 2a)
def my_func():
  pass

@tvm.script.tvm # or tvm.script.module
class Mod:
  def my_func():
    pass

string = my_func.asscript()
assert(string == tvm.script.parse(string))

# can also do
from tvm import script

assert(string == script.parse(string))
```

If we use `tvm.script` as the module name we cannot use the `@tvm.script` decorator. We have two options for the decorator. **Option 2a**: use `@tvm.script.tvm`. **Option 2b**: use `@tvm.script.tir` for functions and `@tvm.script.module` for modules.

The disadvantage here is that the name `script` can be confusing when used unqualified (when using from imports). Pytorch uses this approach, but they only have a single script in their package.


Let me know which you like best. (Hopefully this isn't too much bike shedding).





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/11) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/b98f41f6ca11984e6c712008179bf9f6112402188baa3e13b4243e55eef9de53).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Siyuan Feng via Apache TVM Discuss <no...@discuss.tvm.ai>.

`tvm.script` would be a great name





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/6) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/63d5caad4e5d4e7c91889b28c54a8fed5b398209ec9766ed0b7ef169c5c419eb).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

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

There are some tradeoffs, for example, given the type system is shared across relay and tir. We might in the future have things like

```python
@tvm.script
class MixedModule:
    MyStruct = ADT[Integer, Integer]    

    def relay_func(x: ty.Tensor):
         return relay.call_tir_dest_passing(tir_func, x)
   
     def tir_func(x: ty.handle)
```

So parsing might need to go beyond the function level. Additionally, we might also need to serialize the meta-data.

Conceptually, the basic unit in the transformation is an IRModule, and it would be nice to have a decorator on a module to support that(although it is also important to decorate a function as well)





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/10) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/0c58b2e7035961096d386e0de277ccb32e4b27c85ffe8211779171bc54b29449).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Tristan Konolige via Apache TVM Discuss <no...@discuss.tvm.ai>.

How about this for mixed TIR and Relay:

    class MixedModule:
         @relay.script
         def relay_func(x: ty.Tensor):
              return relay.call_tir_dest_passing(tir_func, x)
   
         @tir.script
         def tir_func(x: ty.handle)
              ...





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/9) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/57c18dc1e36e8130416cb4e70b69b237e7b97489d2181c780b529fd8bbb8ef4c).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

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

I like the idea of `tvm.script` as the intention is to have the script to be able to represent both relay and tir module collectively.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/4) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/daecad725e4b05fb1bd5e238ffa66cbf6adfae7ed3676e1afb1a3b07956f6083).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

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

One thing that is worth considering is how are we going to parse a module with mixed relay and tir functions (or those with external ones).

```
@tvm.script
class MixedModule:
     def relay_func(x: ty.Tensor):
         return relay.call_tir_dest_passing(tir_func, x)
   
     def tir_func(x: ty.handle)
          ...
```
Having such mixed module(and unified design) is a motivation for a common decorator. Although I agree we need to think about ways to distinguish the two.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/8) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/32e541cc416ea2da4f403f152463bbe27f29e368725af3bb3a2d5d6975dc5643).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

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

I don't think having a single decorator makes sense given that the two scripts will require disambiguation with separate decorators. My recent syntactic rewriting work on Relay shares very little concrete syntax with TIR. Either way we will probably need `tvm.script.tir` and `tvm.script.relay` even if we use them to mark function parsed by a single big parser.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/7) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/fbb5e03f78fe0fb3d6f131e1a514f16c01aa52390a995e3eb242c5fdc6685947).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Junru Shao via Apache TVM Discuss <no...@discuss.tvm.ai>.

CC: @spectrometerHBH @Hzfengsy @were





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/9b11224b419a8bc6c443f4c313aee2f8f4207139f6b063301e06408d37c806bb).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

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

To move forward, how about we go with option 2b for now.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/14) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/bfb977d97f1e0bce32257a544842936eaefd92bc20ced2970d06b109164e262c).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Tristan Konolige via Apache TVM Discuss <no...@discuss.tvm.ai>.

Yes and no. Right now we do not need to differentiate. But in the future, functions in a module may either use be for TIR or for relay.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/13) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/d441a983c0b0cb655d1cda6c63799ba86b83db44b5a77e224b578957b852dc27).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Bohan Hou via Apache TVM Discuss <no...@discuss.tvm.ai>.

No matter which option we take, do we have to discriminate between function and class when annotating with decorator?





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/12) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/f8b561ec26d38b88a31e3f14ca3b63434d680fde3731a7ac902170f666581a88).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Jason Knight via Apache TVM Discuss <no...@discuss.tvm.ai>.

:heart_eyes: :star_struck: Thank you for proposing this! Completely agreed that we should disambiguate.

Having `tvm.script` and `te.hybrid.script` is an improvement, but I still think there is far more overlap than ideal between the two.

What about `pytir`? Then it opens the door to other embedded TIR DSLs in other languages being succeessfully disambiguated as well.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/5e16cc1d5e08b1db8ea9d12b21bf7a2daf9a22c658ecc1d3fbaadce2317b800b).

[Apache TVM Discuss] [Development/RFC] [RFC] Rename Hybrid Script

Posted by Bohan Hou via Apache TVM Discuss <no...@discuss.tvm.ai>.

`tvm.script` looks good to me.





---
[Visit Topic](https://discuss.tvm.apache.org/t/rfc-rename-hybrid-script/7915/5) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/54246941961b3e6b124049e6d64100d4a88cce5b40608f94e3edf2a8e35b7c52).