# Get relay graph in json frmat

**URL:** <https://discuss.tvm.apache.org/t/get-relay-graph-in-json-frmat/14529>\
**Category:** Questions\
**Created:** [March 15, 2023, 9:31am UTC](https://discuss.tvm.apache.org/t/get-relay-graph-in-json-frmat/14529 "2023-03-15T09:31:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yogeesh](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/y/9fc29f/32.png) [@yogeesh](https://discuss.tvm.apache.org/u/yogeesh)\
**Post date:** [March 15, 2023, 9:31am UTC](https://discuss.tvm.apache.org/t/get-relay-graph-in-json-frmat/14529/1 "2023-03-15T09:31:40Z")

</div>

i am very new to TVM , and trying to get relay IR graph as json format. i have created a simple add function to understand the work flow of tvm relay and looks like this 🙂`x = relay.var("x") y = tvm.relay.var("y") add_op = tvm.relay.add(x, y) add_function = relay.Function([x,y] , add_op) mod = tvm.IRModule.from_expr(add_function) viz = relay_viz.RelayVisualizer(mod) print(viz) viz.render("output.json") executor = tvm.relay.create_executor(kind="vm", mod=mod)` could someone pleae tell me how to get this graph in json format. my actual goal is to modify this relay graph nodes in some moanner and proceed to opt. and compilation normally. for that i need to visualize and get graph in json format first. thanks

---

<div class="post-metadata">

**Author:** ![cchung100m](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/cchung100m/32/710_2.png) [@cchung100m](https://discuss.tvm.apache.org/u/cchung100m)\
**Post date:** [March 21, 2023, 10:27am UTC](https://discuss.tvm.apache.org/t/get-relay-graph-in-json-frmat/14529/2 "2023-03-21T10:27:47Z")

</div>

Hi @yogeesh

Welcome to join the community and thank you for the asking.

As far as I know, the graph you get from the `relay.build` is in a json format, therefore, you can change the part you want from it. Hope the following example works for you.

```
x = relay.var("x") 
y = tvm.relay.var("y") 
add_op = tvm.relay.add(x, y) 
f = relay.Function([x,y], add_op)
mod = tvm.IRModule()
mod["main"] = f
with tvm.transform.PassContext(opt_level=3):
    json, lib, params = relay.build(mod, target="llvm")

```

Reference: [https://github.com/apache/tvm/blob/main/python/tvm/relay/build\_module.py#L132](https://github.com/apache/tvm/blob/main/python/tvm/relay/build_module.py#L132)

Best regards,

---

<div class="post-metadata">

**Author:** ![yogeesh](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/y/9fc29f/32.png) [@yogeesh](https://discuss.tvm.apache.org/u/yogeesh)\
**Post date:** [May 9, 2023, 10:33am UTC](https://discuss.tvm.apache.org/t/get-relay-graph-in-json-frmat/14529/3 "2023-05-09T10:33:33Z")

</div>

hi @cchung100m , sorry for the delay , and thank you for resolving my doubt. helps a lot.
