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

   Both issues below seem to have the same root cause: `torch_op` has an 
attribute `std::string TorchFunctionAttrs::serialized_function` that is used to 
save binary data, not an actual string. In the first issue, this causes an 
error in `src/parser/parser.cc` when trying to parse the module
   ```
   #[version = "0.0.5"]
   def @main(%x: Tensor[(1, 2), int32], %y: Tensor[(2, 2), int32], %x1: 
Tensor[(1, 3), int32], %y1: Tensor[(3, 3), int32]) {
     %0 = annotation.compiler_begin(%x, meta[relay.attrs.CompilerAttrs][0]);
     %1 = annotation.compiler_begin(%y, meta[relay.attrs.CompilerAttrs][1]);
     %2 = torch_op(%0, %1, 
serialized_function_base64="PK\x03\x04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x12\x00archive/data.pklFB\x0E\x00ZZZZZZZZZZZZZZ\x80\x02c__torch__\nPlaceholderModule\nq\x00)\x81}(X\x08\x00\x00\x00trainingq\x01\x88ubq\x02.PK\x07\x088\x00a\xE5:\x00\x00\x00:\x00\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00?\x00archive/code/__torch__.pyFB;\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZe\x8D\xC1\n\xC20\x10D\xEF\xFD\x8A9\xB6P\xFB\x01\x01\xFD\x03\xC1\x837\x91\x906\x1B[H\xB3\xB2I\xB0\xFD{K\xAA\x07\xF1\xB4;o\x98\x99\xC1\x9B\x18q\xF1f\xA0\x91\xBD%9\xB3\xCD\x9E\xEA\xFD4\xAA\x02\xB4~\x1A13%\x92\xA85\x8E\xB8\xDD\x0B\xED\xB3s?(\x89\x99\xC2\x14\x1EP\xE8\x99\xFDF,98\x96\x97\x11[G\xF2Nm\xB1\xC42\x8CZw\x7F\x9B\xED\x16\x00\x16\x85+\x85\xC8\xB2\xCB\xF5+\x1B\x1CN\x9FW\x15G(e\t(u\xDD\x9C}\xBD\xB4X\x9B\xEA\rPK\x07\x08J\xA2\xA3E\x8E\x00\x00\x00
 
\xD1\x00\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00!\x00archive/code/__torch__.py.debug_pklFB\x1D\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZU\x8E\xCBJ\xC3@\x18\x85'i\xEBe\\*\xA2\xBBY\xB8\x88\"\xC9^(\xD8\x82\x97\xF2{\x81\x18p62\x904%\xA31\xC9\x9F\xF9+\xCD\xCE\xDD<\x97o\xE0#\x99\xC4\xA2\xF4p\xE0\xC0\xF9\xCE\xE2|\xBA\xF2\x881v\xFD\x18\xDEO\"\xF5<\x8Bn\xD5S\x14\xCE\x1EnT4\x99\xDE]!\xF3d\x8B\x19:\xF2\xB0\r\xD1\xEA\x92\xCA:\xC9\xFCWM\xBEIj]\x11GW\x1E\xAF\xE1<]\x88\xDFV-\nou.\x9A\xD3\x0B\x8E\x03y\xB0\xE6\x9D\xEA\xD4\x88\xB1X\x893\xD1p\x1C\xCA\xFD\rD\xCB\xBA\xE8\x16\x1CG\xD2oI@\x1F\xEF\x01\xA5\x86LP5\x94\x95E\x90\x94\x05\xD5:\xEEK\x95\xEB\xB8\xBF\xA3\xCA\xCA\xF8U\x83[\x84\xDB\xC0\x92\xFF\x8B\xAA\xD2\xC9[\x9E\xF2x\xA9\xF3\xB9\xD2\x05\xE5\xDA\xB4\x8Fw\xBC\x17/\xA5\x10\x180\x8B\xBB}t\xFE\xCA:\x00\x0E\xB80\x80!\xB0n2\x82\x13\x8B\x1C\xC60\xB5\xE0X\xF8\xCE\xFE\xE6\x16\xF7\xAC\xFF\x03PK\x07\x08du\xF6\xAD\xFA\x00\x00\x00A\x01\x00\x00PK\x03\x
 
04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00C\x00archive/constants.pklFB?\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\x80\x02).PK\x07\x08m/\tW\x04\x00\x00\x00\x04\x00\x00\x00PK\x03\x04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0F\x00?\x00archive/versionFB;\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ3\nPK\x07\x08\xD1\x9EgU\x02\x00\x00\x00\x02\x00\x00\x00PK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x008\x00a\xE5:\x00\x00\x00:\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00archive/data.pklPK\x01\x02\x00\x00\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00J\xA2\xA3E\x8E\x00\x00\x00\xD1\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8A\x00\x00\x00archive/code/__torch__.pyPK\x01\x02\x00\x00\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00du\xF6\xAD\xFA\x00\x00\x00A\x01\x00\x00#\x00\x00\x00\x00\x00\x
 
00\x00\x00\x00\x00\x00\x00\x00\x9E\x01\x00\x00archive/code/__torch__.py.debug_pklPK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00m/\tW\x04\x00\x00\x00\x04\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x03\x00\x00archive/constants.pklPK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\xD1\x9EgU\x02\x00\x00\x00\x02\x00\x00\x00\x0F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94\x03\x00\x00archive/versionPK\x06\x06,\x00\x00\x00\x00\x00\x00\x00\x1E\x03-\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00V\x01\x00\x00\x00\x00\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00PK\x06\x07\x00\x00\x00\x00h\x05\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00PK\x05\x06\x00\x00\x00\x00\x05\x00\x05\x00V\x01\x00\x00\x12\x04\x00\x00\x00\x00");
     %3 = annotation.compiler_end(%2, meta[relay.attrs.CompilerAttrs][2]);
     %4 = annotation.compiler_begin(%x1, meta[relay.attrs.CompilerAttrs][3]);
     %5 = annotation.compiler_begin(%y1, meta[relay.attrs.CompilerAttrs][4]);
     %6 = torch_op(%4, %5, 
serialized_function_base64="PK\x03\x04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x12\x00archive/data.pklFB\x0E\x00ZZZZZZZZZZZZZZ\x80\x02c__torch__\nPlaceholderModule\nq\x00)\x81}(X\x08\x00\x00\x00trainingq\x01\x88ubq\x02.PK\x07\x088\x00a\xE5:\x00\x00\x00:\x00\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00?\x00archive/code/__torch__.pyFB;\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZe\x8D\xC1\n\xC20\x10D\xEF\xFD\x8A9\xB6P\xFB\x01\x01\xFD\x03\xC1\x837\x91\x906\x1B[H\xB3\xB2I\xB0\xFD{K\xAA\x07\xF1\xB4;o\x98\x99\xC1\x9B\x18q\xF1f\xA0\x91\xBD%9\xB3\xCD\x9E\xEA\xFD4\xAA\x02\xB4~\x1A13%\x92\xA85\x8E\xB8\xDD\x0B\xED\xB3s?(\x89\x99\xC2\x14\x1EP\xE8\x99\xFDF,98\x96\x97\x11[G\xF2Nm\xB1\xC42\x8CZw\x7F\x9B\xED\x16\x00\x16\x85+\x85\xC8\xB2\xCB\xF5+\x1B\x1CN\x9FW\x15G(e\t(u\xDD\x9C}\xBD\xB4X\x9B\xEA\rPK\x07\x08J\xA2\xA3E\x8E\x00\x00\x00
 
\xD1\x00\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00!\x00archive/code/__torch__.py.debug_pklFB\x1D\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZU\x8E\xCBJ\xC3@\x18\x85'i\xEBe\\*\xA2\xBBY\xB8\x88\"\xC9^(\xD8\x82\x97\xF2{\x81\x18p62\x904%\xA31\xC9\x9F\xF9+\xCD\xCE\xDD<\x97o\xE0#\x99\xC4\xA2\xF4p\xE0\xC0\xF9\xCE\xE2|\xBA\xF2\x881v\xFD\x18\xDEO\"\xF5<\x8Bn\xD5S\x14\xCE\x1EnT4\x99\xDE]!\xF3d\x8B\x19:\xF2\xB0\r\xD1\xEA\x92\xCA:\xC9\xFCWM\xBEIj]\x11GW\x1E\xAF\xE1<]\x88\xDFV-\nou.\x9A\xD3\x0B\x8E\x03y\xB0\xE6\x9D\xEA\xD4\x88\xB1X\x893\xD1p\x1C\xCA\xFD\rD\xCB\xBA\xE8\x16\x1CG\xD2oI@\x1F\xEF\x01\xA5\x86LP5\x94\x95E\x90\x94\x05\xD5:\xEEK\x95\xEB\xB8\xBF\xA3\xCA\xCA\xF8U\x83[\x84\xDB\xC0\x92\xFF\x8B\xAA\xD2\xC9[\x9E\xF2x\xA9\xF3\xB9\xD2\x05\xE5\xDA\xB4\x8Fw\xBC\x17/\xA5\x10\x180\x8B\xBB}t\xFE\xCA:\x00\x0E\xB80\x80!\xB0n2\x82\x13\x8B\x1C\xC60\xB5\xE0X\xF8\xCE\xFE\xE6\x16\xF7\xAC\xFF\x03PK\x07\x08du\xF6\xAD\xFA\x00\x00\x00A\x01\x00\x00PK\x03\x
 
04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00C\x00archive/constants.pklFB?\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\x80\x02).PK\x07\x08m/\tW\x04\x00\x00\x00\x04\x00\x00\x00PK\x03\x04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0F\x00?\x00archive/versionFB;\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ3\nPK\x07\x08\xD1\x9EgU\x02\x00\x00\x00\x02\x00\x00\x00PK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x008\x00a\xE5:\x00\x00\x00:\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00archive/data.pklPK\x01\x02\x00\x00\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00J\xA2\xA3E\x8E\x00\x00\x00\xD1\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8A\x00\x00\x00archive/code/__torch__.pyPK\x01\x02\x00\x00\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00du\xF6\xAD\xFA\x00\x00\x00A\x01\x00\x00#\x00\x00\x00\x00\x00\x
 
00\x00\x00\x00\x00\x00\x00\x00\x9E\x01\x00\x00archive/code/__torch__.py.debug_pklPK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00m/\tW\x04\x00\x00\x00\x04\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x03\x00\x00archive/constants.pklPK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\xD1\x9EgU\x02\x00\x00\x00\x02\x00\x00\x00\x0F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94\x03\x00\x00archive/versionPK\x06\x06,\x00\x00\x00\x00\x00\x00\x00\x1E\x03-\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00V\x01\x00\x00\x00\x00\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00PK\x06\x07\x00\x00\x00\x00h\x05\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00PK\x05\x06\x00\x00\x00\x00\x05\x00\x05\x00V\x01\x00\x00\x12\x04\x00\x00\x00\x00");
     %7 = annotation.compiler_end(%6, meta[relay.attrs.CompilerAttrs][5]);
     %8 = sum(%3);
     %9 = sum(%7);
     add(%8, %9)
   }
   
   #[metadata]
   {
     "root": 1, 
     "nodes": [
       {
         "type_key": ""
       }, 
       {
         "type_key": "Map", 
         "keys": [
           "relay.attrs.CompilerAttrs"
         ], 
         "data": [2]
       }, 
       {
         "type_key": "Array", 
         "data": [3, 4, 5, 6, 7, 8]
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }
     ], 
     "b64ndarrays": [], 
     "attrs": {"tvm_version": "0.11.1"}
   }
   ```
   
   In the second issue, the json parser fails trying to parse this corrupted 
json
   ```
   "{
     "root": 1, 
     "nodes": [
       {
         "type_key": ""
       }, 
       {
         "type_key": "IRModule", 
         "attrs": {
           "attrs": "0", 
           "functions": "2", 
           "global_type_var_map_": "98", 
           "global_var_map_": "97", 
           "source_map": "99", 
           "type_definitions": "96"
         }
       }, 
       {
         "type_key": "Map", 
         "data": [3, 27]
       }, 
       {
         "type_key": "GlobalVar", 
         "attrs": {
           "_checked_type_": "5", 
           "name_hint": "4", 
           "span": "0", 
           "virtual_device_": "0"
         }
       }, 
       {
         "type_key": "runtime.String", 
         "repr_str": "main"
       }, 
       {
         "type_key": "FuncType", 
         "attrs": {
           "arg_types": "6", 
           "ret_type": "23", 
           "span": "0", 
           "type_constraints": "26", 
           "type_params": "25"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [7, 11, 15, 19]
       }, 
       {
         "type_key": "relay.TensorType", 
         "attrs": {
           "dtype": "int32", 
           "shape": "8", 
           "span": "0"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [9, 10]
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "1"
         }
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "2"
         }
       }, 
       {
         "type_key": "relay.TensorType", 
         "attrs": {
           "dtype": "int32", 
           "shape": "12", 
           "span": "0"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [13, 14]
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "2"
         }
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "2"
         }
       }, 
       {
         "type_key": "relay.TensorType", 
         "attrs": {
           "dtype": "int32", 
           "shape": "16", 
           "span": "0"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [17, 18]
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "1"
         }
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "3"
         }
       }, 
       {
         "type_key": "relay.TensorType", 
         "attrs": {
           "dtype": "int32", 
           "shape": "20", 
           "span": "0"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [21, 22]
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "3"
         }
       }, 
       {
         "type_key": "IntImm", 
         "attrs": {
           "dtype": "int32", 
           "span": "0", 
           "value": "3"
         }
       }, 
       {
         "type_key": "relay.TensorType", 
         "attrs": {
           "dtype": "int32", 
           "shape": "24", 
           "span": "0"
         }
       }, 
       {
         "type_key": "Array"
       }, 
       {
         "type_key": "Array"
       }, 
       {
         "type_key": "Array"
       }, 
       {
         "type_key": "relay.Function", 
         "attrs": {
           "_checked_type_": "92", 
           "attrs": "0", 
           "body": "43", 
           "params": "28", 
           "ret_type": "0", 
           "span": "0", 
           "type_params": "91", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [29, 34, 37, 40]
       }, 
       {
         "type_key": "relay.Var", 
         "attrs": {
           "_checked_type_": "0", 
           "span": "0", 
           "type_annotation": "7", 
           "vid": "30", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "relay.Id", 
         "attrs": {"name_hint": "31"}
       }, 
       {
         "type_key": "runtime.String", 
         "repr_str": "x"
       }, 
       {
         "type_key": "VirtualDevice", 
         "attrs": {
           "device_type_int": "-1", 
           "memory_scope": "33", 
           "target": "0", 
           "virtual_device_id": "-1"
         }
       }, 
       {
         "type_key": "runtime.String"
       }, 
       {
         "type_key": "relay.Var", 
         "attrs": {
           "_checked_type_": "0", 
           "span": "0", 
           "type_annotation": "11", 
           "vid": "35", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "relay.Id", 
         "attrs": {"name_hint": "36"}
       }, 
       {
         "type_key": "runtime.String", 
         "repr_str": "y"
       }, 
       {
         "type_key": "relay.Var", 
         "attrs": {
           "_checked_type_": "0", 
           "span": "0", 
           "type_annotation": "15", 
           "vid": "38", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "relay.Id", 
         "attrs": {"name_hint": "39"}
       }, 
       {
         "type_key": "runtime.String", 
         "repr_str": "x"
       }, 
       {
         "type_key": "relay.Var", 
         "attrs": {
           "_checked_type_": "0", 
           "span": "0", 
           "type_annotation": "19", 
           "vid": "41", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "relay.Id", 
         "attrs": {"name_hint": "42"}
       }, 
       {
         "type_key": "runtime.String", 
         "repr_str": "y"
       }, 
       {
         "type_key": "relay.Call", 
         "attrs": {
           "_checked_type_": "0", 
           "args": "45", 
           "attrs": "0", 
           "op": "44", 
           "span": "0", 
           "type_args": "90", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Op", 
         "repr_str": "add"
       }, 
       {
         "type_key": "Array", 
         "data": [46, 70]
       }, 
       {
         "type_key": "relay.Call", 
         "attrs": {
           "_checked_type_": "0", 
           "args": "48", 
           "attrs": "68", 
           "op": "47", 
           "span": "0", 
           "type_args": "69", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Op", 
         "repr_str": "sum"
       }, 
       {
         "type_key": "Array", 
         "data": [49]
       }, 
       {
         "type_key": "relay.Call", 
         "attrs": {
           "_checked_type_": "0", 
           "args": "51", 
           "attrs": "66", 
           "op": "50", 
           "span": "0", 
           "type_args": "67", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Op", 
         "repr_str": "annotation.compiler_end"
       }, 
       {
         "type_key": "Array", 
         "data": [52]
       }, 
       {
         "type_key": "relay.Call", 
         "attrs": {
           "_checked_type_": "0", 
           "args": "54", 
           "attrs": "64", 
           "op": "53", 
           "span": "0", 
           "type_args": "65", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Op", 
         "repr_str": "torch_op"
       }, 
       {
         "type_key": "Array", 
         "data": [55, 60]
       }, 
       {
         "type_key": "relay.Call", 
         "attrs": {
           "_checked_type_": "0", 
           "args": "57", 
           "attrs": "58", 
           "op": "56", 
           "span": "0", 
           "type_args": "59", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Op", 
         "repr_str": "annotation.compiler_begin"
       }, 
       {
         "type_key": "Array", 
         "data": [29]
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "Array"
       }, 
       {
         "type_key": "relay.Call", 
         "attrs": {
           "_checked_type_": "0", 
           "args": "61", 
           "attrs": "62", 
           "op": "56", 
           "span": "0", 
           "type_args": "63", 
           "virtual_device_": "32"
         }
       }, 
       {
         "type_key": "Array", 
         "data": [34]
       }, 
       {
         "type_key": "relay.attrs.CompilerAttrs", 
         "attrs": {"compiler": "torch"}
       }, 
       {
         "type_key": "Array"
       }, 
       {
         "type_key": "relay.attrs.TorchFunctionAttrs", 
         "attrs": {"serialized_function_base64": "PK�03�04"
   ```
   
   I worked around it by encoding the binary data in `serialized_function` in 
base64 and decoding when needed, but I'm not sure if the problem is with the 
string containing binary data or with parsers that fail on it.
   
   ### Expected behavior
   
   No errors working with module with torchop
   
   ### Actual behavior
   
   1. Error performing `AnnotateSpans` pass
   
   ```
   error: expected a `)` found unknown
    --> GeneratedSource:5:3801
      |  
    5 |    %2 = torch_op(%0, %1, 
serialized_function="PK\x03\x04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x12\x00archive/data.pklFB\x0E\x00ZZZZZZZZZZZZZZ\x80\x02c__torch__\nPlaceholderModule\nq\x00)\x81}(X\x08\x00\x00\x00trainingq\x01\x88ubq\x02.PK\x07\x088\x00a\xE5:\x00\x00\x00:\x00\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00?\x00archive/code/__torch__.pyFB;\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZe\x8D\xC1\n\xC20\x10D\xEF\xFD\x8A9\xB6P\xFB\x01\x01\xFD\x03\xC1\x837\x91\x906\x1B[H\xB3\xB2I\xB0\xFD{K\xAA\x07\xF1\xB4;o\x98\x99\xC1\x9B\x18q\xF1f\xA0\x91\xBD%9\xB3\xCD\x9E\xEA\xFD4\xAA\x02\xB4~\x1A13%\x92\xA85\x8E\xB8\xDD\x0B\xED\xB3s?(\x89\x99\xC2\x14\x1EP\xE8\x99\xFDF,98\x96\x97\x11[G\xF2Nm\xB1\xC42\x8CZw\x7F\x9B\xED\x16\x00\x16\x85+\x85\xC8\xB2\xCB\xF5+\x1B\x1CN\x9FW\x15G(e\t(u\xDD\x9C}\xBD\xB4X\x9B\xEA\rPK\x07\x08J\xA2\xA3E\x8E\x00\x00\x00\
 
xD1\x00\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00#\x00!\x00archive/code/__torch__.py.debug_pklFB\x1D\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZU\x8E\xCBJ\xC3@\x18\x85'i\xEBe\\*\xA2\xBBY\xB8\x88\"\xC9^(\xD8\x82\x97\xF2{\x81\x18p62\x904%\xA31\xC9\x9F\xF9+\xCD\xCE\xDD<\x97o\xE0#\x99\xC4\xA2\xF4p\xE0\xC0\xF9\xCE\xE2|\xBA\xF2\x881v\xFD\x18\xDEO\"\xF5<\x8Bn\xD5S\x14\xCE\x1EnT4\x99\xDE]!\xF3d\x8B\x19:\xF2\xB0\r\xD1\xEA\x92\xCA:\xC9\xFCWM\xBEIj]\x11GW\x1E\xAF\xE1<]\x88\xDFV-\nou.\x9A\xD3\x0B\x8E\x03y\xB0\xE6\x9D\xEA\xD4\x88\xB1X\x893\xD1p\x1C\xCA\xFD\rD\xCB\xBA\xE8\x16\x1CG\xD2oI@\x1F\xEF\x01\xA5\x86LP5\x94\x95E\x90\x94\x05\xD5:\xEEK\x95\xEB\xB8\xBF\xA3\xCA\xCA\xF8U\x83[\x84\xDB\xC0\x92\xFF\x8B\xAA\xD2\xC9[\x9E\xF2x\xA9\xF3\xB9\xD2\x05\xE5\xDA\xB4\x8Fw\xBC\x17/\xA5\x10\x180\x8B\xBB}t\xFE\xCA:\x00\x0E\xB80\x80!\xB0n2\x82\x13\x8B\x1C\xC60\xB5\xE0X\xF8\xCE\xFE\xE6\x16\xF7\xAC\xFF\x03PK\x07\x08du\xF6\xAD\xFA\x00\x00\x00A\x01\x00\x00PK\x03\x0
 
4\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00C\x00archive/constants.pklFB?\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\x80\x02).PK\x07\x08m/\tW\x04\x00\x00\x00\x04\x00\x00\x00PK\x03\x04\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0F\x00?\x00archive/versionFB;\x00ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ3\nPK\x07\x08\xD1\x9EgU\x02\x00\x00\x00\x02\x00\x00\x00PK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x008\x00a\xE5:\x00\x00\x00:\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00archive/data.pklPK\x01\x02\x00\x00\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00J\xA2\xA3E\x8E\x00\x00\x00\xD1\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8A\x00\x00\x00archive/code/__torch__.pyPK\x01\x02\x00\x00\x14\x00\x08\x08\x08\x00\x00\x00\x00\x00du\xF6\xAD\xFA\x00\x00\x00A\x01\x00\x00#\x00\x00\x00\x00\x00\x0
 
0\x00\x00\x00\x00\x00\x00\x00\x9E\x01\x00\x00archive/code/__torch__.py.debug_pklPK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00m/\tW\x04\x00\x00\x00\x04\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x03\x00\x00archive/constants.pklPK\x01\x02\x00\x00\x00\x00\x08\x08\x00\x00\x00\x00\x00\x00\xD1\x9EgU\x02\x00\x00\x00\x02\x00\x00\x00\x0F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94\x03\x00\x00archive/versionPK\x06\x06,\x00\x00\x00\x00\x00\x00\x00\x1E\x03-\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00V\x01\x00\x00\x00\x00\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00PK\x06\x07\x00\x00\x00\x00h\x05\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00PK\x05\x06\x00\x00\x00\x00\x05\x00\x05\x00V\x01\x00\x00\x12\x04\x00\x00\x00\x00");
      |                                                                         
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                      
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                      
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                      
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                  
   note: run with `TVM_BACKTRACE=1` environment variable to display a backtrace.
   ```
   
   2. Error performing `copy.deepcopy`
   ```
   Traceback (most recent call last):
     File "/tvm/tests/python/contrib/test_libtorch_ops.py", line 97, in <module>
       test_backend()
     File "/tvm/tests/python/contrib/test_libtorch_ops.py", line 64, in 
test_backend
       mod2 = copy.deepcopy(mod)
     File "/usr/lib/python3.8/copy.py", line 172, in deepcopy
       y = _reconstruct(x, memo, *rv)
     File "/usr/lib/python3.8/copy.py", line 272, in _reconstruct
       y.__setstate__(state)
     File "/tvm/python/tvm/runtime/object.py", line 93, in __setstate__
       self.__init_handle_by_constructor__(_ffi_node_api.LoadJSON, handle)
     File "/tvm/python/tvm/_ffi/_ctypes/object.py", line 145, in 
__init_handle_by_constructor__
       handle = __init_by_constructor__(fconstructor, args)
     File "/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 260, in 
__init_handle_by_constructor__
       raise get_last_ffi_error()
   tvm._ffi.base.TVMError: Traceback (most recent call last):
     20: TVMFuncCall
           at /tvm/src/runtime/c_runtime_api.cc:477
     19: tvm::runtime::PackedFuncObj::CallPacked(tvm::runtime::TVMArgs, 
tvm::runtime::TVMRetValue*) const
           at /tvm/include/tvm/runtime/packed_func.h:1217
     18: _ZN3tvm7runtime13PackedFuncObj9ExtractorINS0_16Pac
     17: tvm::runtime::TypedPackedFunc<tvm::runtime::ObjectRef 
(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>)>::AssignTypedLambda<tvm::runtime::ObjectRef 
(*)(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >)>(tvm::runtime::ObjectRef 
(*)(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >), std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >)::{lambda(tvm::runtime::TVMArgs 
const&, tvm::runtime::TVMRetValue*)#1}::operator()(tvm::runtime::TVMArgs 
const&, tvm::runtime::TVMRetValue*) const
           at /tvm/include/tvm/runtime/packed_func.h:1730
     16: void tvm::runtime::detail::unpack_call<tvm::runtime::ObjectRef, 1, 
tvm::runtime::ObjectRef (*)(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> 
>)>(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const*, tvm::runtime::ObjectRef (* 
const&)(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >), tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*)
           at /tvm/include/tvm/runtime/packed_func.h:1670
     15: void 
tvm::runtime::detail::unpack_call_dispatcher<tvm::runtime::ObjectRef, 1, 0, 
tvm::runtime::ObjectRef (*)(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> 
>)>::run<>(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const*, std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > (*)(), tvm::runtime::ObjectRef 
(* const&)(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >), tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*)
           at /tvm/include/tvm/runtime/packed_func.h:1630
     14: void 
tvm::runtime::detail::unpack_call_dispatcher<tvm::runtime::ObjectRef, 0, 1, 
tvm::runtime::ObjectRef (*)(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> 
>)>::run<tvm::runtime::TVMMovableArgValueWithContext_>(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char> > const*, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 
(*)(), tvm::runtime::ObjectRef (* const&)(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >), tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*, tvm::runtime::TVMMovableArgValueWithContext_&&)
           at /tvm/include/tvm/runtime/packed_func.h:1645
     13: tvm::LoadJSON(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >)
           at /tvm/src/node/serialization.cc:581
     12: tvm::JSONGraph::Load(dmlc::JSONReader*)
     11: dmlc::JSONObjectReadHelper::ReadAllFields(dmlc::JSONReader*)
           at /tvm/3rdparty/dmlc-core/include/dmlc/json.h:929
     10: _ZN4dmlc20JSONObjectReadHelper14ReaderFunc
     9: dmlc::json::ArrayHandler<std::vector<tvm::JSONNode, 
std::allocator<tvm::JSONNode> > >::Read(dmlc::JSONReader*, 
std::vector<tvm::JSONNode, std::allocator<tvm::JSONNode> >*)
     8: _ZN4dmlc4json7HandlerIN3tvm8JSONNodeEE4Rea
     7: _ZN4dmlc4json20CommonJSONSerializerIN3tvm8
     6: tvm::JSONNode::Load(dmlc::JSONReader*)
     5: dmlc::JSONObjectReadHelper::ReadAllFields(dmlc::JSONReader*)
           at /tvm/3rdparty/dmlc-core/include/dmlc/json.h:929
     4: _ZN4dmlc20JSONObjectReadHelper14ReaderFunc
     3: dmlc::json::MapHandler<std::map<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > >, 
std::allocator<std::pair<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 
> > > >::Read(dmlc::JSONReader*, std::map<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > >, 
std::allocator<std::pair<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 
> > >*)
     2: void dmlc::JSONReader::Read<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > 
>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>*)
           at /tvm/3rdparty/dmlc-core/include/dmlc/json.h:811
     1: dmlc::json::Handler<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > >::Read(dmlc::JSONReader*, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>*)
           at /tvm/3rdparty/dmlc-core/include/dmlc/json.h:469
     0: dmlc::JSONReader::ReadString(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >*)
           at /tvm/3rdparty/dmlc-core/include/dmlc/json.h:702
     File "/tvm/3rdparty/dmlc-core/include/dmlc/json.h", line 702
   TVMError: Error at Line 410, around ^``, Expect '"' but reach end of line
   ```
   
   ### Environment
   
   Ubuntu 20.04.5, TVM branch `origin/tvm-0.11.1`
   
   ### Steps to reproduce
   
   1. Add `AnnotateSpans` pass in the test `test_backend` in 
`test_libtorch_ops.py`
   ```
   diff --git a/tests/python/contrib/test_libtorch_ops.py 
b/tests/python/contrib/test_libtorch_ops.py
   index 2bfb78b40..4692bdb49 100644
   --- a/tests/python/contrib/test_libtorch_ops.py
   +++ b/tests/python/contrib/test_libtorch_ops.py
   @@ -58,6 +58,7 @@ def test_backend():
            tvm.relay.transform.InferType()(mod)
    
            # mod = tvm.relay.transform.AnnotateTarget("target.torch")(mod)
   +        mod = tvm.relay.transform.AnnotateSpans()(mod)
            mod = tvm.relay.transform.MergeCompilerRegions()(mod)
            mod = tvm.relay.transform.PartitionGraph()(mod)
            mod = tvm.relay.transform.InferType()(mod)
   ```
   
   2. Try to copy a module
   ```
   diff --git a/tests/python/contrib/test_libtorch_ops.py 
b/tests/python/contrib/test_libtorch_ops.py
   index 2bfb78b40..e81528524 100644
   --- a/tests/python/contrib/test_libtorch_ops.py
   +++ b/tests/python/contrib/test_libtorch_ops.py
   @@ -58,6 +58,8 @@ def test_backend():
            tvm.relay.transform.InferType()(mod)
    
            # mod = tvm.relay.transform.AnnotateTarget("target.torch")(mod)
   +        import copy
   +        mod2 = copy.deepcopy(mod)
            mod = tvm.relay.transform.MergeCompilerRegions()(mod)
            mod = tvm.relay.transform.PartitionGraph()(mod)
            mod = tvm.relay.transform.InferType()(mod)
   ```
   
   ### Triage
   
   * byoc:libtorch
   


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