You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/11/03 22:41:58 UTC

[GitHub] [tvm] slyubomirsky opened a new issue, #13288: [Bug][IRModule] Using `type_definitions` in the constructor leads to a crash.

slyubomirsky opened a new issue, #13288:
URL: https://github.com/apache/tvm/issues/13288

   The Python constructor for `tvm.IRModule` has a bug; namely, it is impossible to pass a non-empty dictionary for the `type_definitions` argument.
   
   Here is the relevant portion of the constructor:
   ```python
       def __init__(self, functions=None, type_definitions=None):
           # ...
           if type_definitions is None:
               type_definitions = {}
           elif isinstance(type_definitions, dict):
               mapped_type_defs = {}
               for k, v in type_definitions.items():
                   if isinstance(k, string_types):
                       k = _ty.GlobalTypeVar(k)
                   if not isinstance(k, _ty.GlobalTypeVar):
                       raise TypeError("Expect type_definitions to be Dict[GlobalTypeVar, Type]")
                   mapped_type_defs[k] = v
               type_definitions = mapped_type_defs
       # ....
   ```
   
   It is not possible to make a Python dict with `GlobalTypeVar`s as keys because they are non-hashable. If you use strings as keys, the constructor crashes due to GTVs' being nonhashable.
   
   Example that causes an error:
   ```python
   import tvm
   from tvm import relay
   gtv1 = relay.GlobalTypeVar("gtv1")
   gtv2 = relay.GlobalTypeVar("gtv2")
   td1 = relay.TypeData(gtv1, [], []) # contents are not relevant right now
   td2 = relay.TypeData(gtv2, [], [])
   
   # this will crash
   mod = tvm.IRModule(functions=None, type_definitions={"gtv1": td1, "gtv2": td2})
   ```
   
   Resulting error
   ```
     # ...
     File "[...]/tvm/python/tvm/ir/module.py", line 62, in __init__
       mapped_type_defs[k] = v
   TypeError: unhashable type: 'GlobalTypeVar'
   ```


-- 
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: commits-unsubscribe@tvm.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org