Skip to content

Commit

Permalink
Fix runtime::String backward compatibility in JSON (#5725)
Browse files Browse the repository at this point in the history
  • Loading branch information
junrushao authored Jun 4, 2020
1 parent a642089 commit 8935990
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/tvm/ir/json_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def _convert(item, _):
return _convert

def _update_global_key(item, _):
item["repr_str"] = item["global_key"]
del item["global_key"]
if "global_key" in item:
item["repr_str"] = item["global_key"]
del item["global_key"]
return item

def _update_from_std_str(key):
Expand All @@ -111,8 +112,10 @@ def _convert(item, nodes):
"EnvFunc": _update_global_key,
"relay.Op": [_update_global_key, _rename("Op")],
"relay.TypeVar": [_ftype_var, _update_from_std_str("name_hint")],
"TypeVar": _update_from_std_str("name_hint"),
"relay.Id": [_update_from_std_str("name_hint")],
"relay.GlobalTypeVar": [_ftype_var, _update_from_std_str("name_hint")],
"GlobalTypeVar": _update_from_std_str("name_hint"),
"relay.Type": _rename("Type"),
"relay.TupleType": _rename("TupleType"),
"relay.TypeConstraint": _rename("TypeConstraint"),
Expand All @@ -124,6 +127,7 @@ def _convert(item, nodes):
"relay.SourceName": _rename("SourceName"),
"relay.Span": _rename("Span"),
"relay.GlobalVar": [_rename("GlobalVar"), _update_from_std_str("name_hint")],
"GlobalVar": _update_from_std_str("name_hint"),
"relay.Pass": _rename("transform.Pass"),
"relay.PassInfo": _rename("transform.PassInfo"),
"relay.PassContext": _rename("transform.PassContext"),
Expand Down
18 changes: 18 additions & 0 deletions tests/python/relay/test_json_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ def test_global_var():
}
tvar = tvm.ir.load_json(json.dumps(data))
assert isinstance(tvar, tvm.ir.GlobalVar)
nodes = [
{"type_key": ""},
{"type_key": "GlobalVar",
"attrs": {
"_checked_type_": "0",
"name_hint": "x",
"span": "0"
}
}
]
data = {
"root" : 1,
"nodes": nodes,
"attrs": {"tvm_version": "0.6.0"},
"b64ndarrays": [],
}
tvar = tvm.ir.load_json(json.dumps(data))
assert isinstance(tvar, tvm.ir.GlobalVar)


def test_op():
Expand Down

0 comments on commit 8935990

Please sign in to comment.