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

   Consider the following Relay program:
   ```python
   import tvm
   from tvm import relay
   from tvm.relay.prelude import Prelude
   
   p = prelude.Prelude().mod
   list_var = p.get_global_type_var("List")
   list_data = p.type_definitions[list_var]
   nil_ctor = None
   for ctor in list_data.constructors:
       if ctor.name_hint == "Nil":
           nil_ctor = ctor
   assert nil_ctor != None
   
   p["main"] = relay.Function(
       [],
       relay.Match(
           relay.Call(nil_ctor, [], type_args=[relay.TensorType((), 
dtype="int64")]),
           [relay.Clause(relay.PatternWildcard(), relay.const(1, 
dtype="int64"))],
       ),
       ret_type=relay.TensorType((), dtype="int64"),
   )
   ```
   
   If we print the module using the pretty-printer, we obtain the following 
(omitting parts of the module that aren't relevant):
   ```
   type List[A] {
     Cons(A, List[A]),
     Nil,
   }
   
   # snip
   
   def @main() -> int64 {
     %10 = Nil;
     match (%10) {
       _ => {
         1i64
       },
     }
   }
   ```
   
   It all looks as it should, right? However, if we parse back the module and 
compare it to the original, the comparison fails:
   ```python
   text = p.astext(show_meta_data=True)
   with open(os.path.join(out_dir, "prog.rly"), "w") as fp:
       fp.write(text)
   new_mod = tvm.parser.fromtext(text)
   assert tvm.ir.structural_equal(p["main"], new_mod["main"], 
map_free_vars=True)
   ```
   
   The reason for this is the type args field on the call to `Nil`.
   ```python
   print(new_mod["main"].body.data.type_args) # prints "[IncompleteTypeNode(0, 
0x556f6335e570)]"
   ```
   
   The text format is not serializing the type args field. In this case, type 
inference cannot unambiguously infer the type arg for the constructor (indeed, 
there is not enough information for it).
   
   (Bug discovered in the process of fuzzer development.)


-- 
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]

Reply via email to