Aidge Model Explorer#
Aidge offers integration with the Google Model Explorer plugin, enabling visualization of Aidge computational graphs. This tutorial provides a step-by-step guide on utilizing this powerful visualization tool to analyze and understand your graph structures.
Install requirements#
[ ]:
%pip install aidge-core \
aidge-backend-cpu \
aidge-onnx \
aidge-model-explorer
Setup#
[ ]:
import aidge_core
import aidge_model_explorer
import model_explorer
aidge_core.Log.set_console_level(aidge_core.Level.Warn)
For this tutorial, we will use a LSTM operator created using the LSTM MetaOperator available in aidge_core.
[ ]:
model = aidge_core.get_connected_graph_view(
aidge_core.LSTM(in_channels=4, hidden_channels=8, seq_length=5)
)
Wrapper method#
Aidge proposes a wrapper method that simplify the use of the visualization feature.
The following command can be used in your python script and will open in your browser.
[ ]:
aidge_model_explorer.visualize(model, "LSTM")
If you want to visualize the graph inside of your notebook you can use the embed option, this option only works with Python notebook.
[ ]:
aidge_model_explorer.visualize(model, "LSTM", embed=True)
Visualize from config#
You can also use the model_explorer API by using a aidge_model_explorer.Config(), which is an overridden class enabling full compatibility with the model_explorer API.
⚠️ The model explorer API does not run the app in a separated thread and the call to visualize_from_config is blocking. You need to stop manually the cell from running to execute the next cells.
[ ]:
# Config is an override of model_explorer.config() to be compatible with Aidge GraphView
config = aidge_model_explorer.config()
config.add_graphview(model, "lstm")
# Directly call model_explorer API
model_explorer.visualize_from_config(config)
Advanced uses#
Now that we have seen the basic usage of the visualize function, let’s explore how you can leverage this module to make graph exploration more intuitive and insightful.
If you see a ⭐ this means the feature is unique to the aidge_model_explorer module.
Synchronize graphs with node ids#
The Model Explorer provides a powerful feature to synchronize two graphs using node IDs. This allows you to visualize and compare a graph before and after modifications:

Note: Screen recording taken using v0.1.5 of model explorer.
You can experiment with the visualization tool using the code cell below. Please note that the model_explorer function operates in blocking mode, which means you’ll need to manually interrupt the cell execution before proceeding to the next steps.
[ ]:
config = aidge_model_explorer.config()
# Note: need to add graphview before doing any manipulation to keep the ids
config.add_graphview(model, "lstm")
expanded_model = model.clone()
aidge_core.expand_metaops(expanded_model)
config.add_graphview(expanded_model, "lstm_expanded")
model_explorer.visualize_from_config(config)
Add custom metadata#
To gain deeper, customizable insights into your model’s structure and behavior, you can augment the visualization with additional metadata. This enhanced visualization capability is implemented through a ConverterConfig object that manages metadata during the graph parsing process.
[ ]:
converter_config = aidge_model_explorer.ConverterConfig()
This configuration can be used to add metadata on each node:
[ ]:
converter_config.add_attribute(
"isMatMul", lambda node: "True" if (node.type() == "Matmul") else None
) # If lambda return None no attribute is added!
A usage example could be setting an attribute to determine whether a node’s input and output exceed a threshold, which helps quickly troubleshoot whether a DNN needs to be compressed.
You can also add information at the tensor level, for example, by adding the mean value of the tensor.
[ ]:
converter_config.add_output_metadata("mean", lambda _, tensor: str(tensor.mean()))
Once the converter configuration is ready, you can provide it along with your model to the model explorer configuration and visualize it. Please note that the model_explorer function operates in blocking mode, so you will need to manually interrupt the cell execution before proceeding.
[ ]:
config = aidge_model_explorer.config()
config.add_graphview(model, "custom_attr_lst", converter_config)
model_explorer.visualize_from_config(config)
Update node style directly in Aidge nodes#
To customize the visual appearance of nodes, you can apply the following styling attributes:
model_explorer:bg_color: Changes the background color of the node. The value must be a string representing a valid color in hexadecimal format (e.g., “#ff0800” for red). The string should follow the standard 6-digit RGB hex code format, beginning with a #.
model_explorer:border_color: Changes the border color of the node. The value must be a string representing a valid color in hexadecimal format (e.g., “#ff0800” for red). The string should follow the standard 6-digit RGB hex code format, beginning with a #.
model_explorer:h_border_color: Changes the border color on hover of the node. The value must be a string representing a valid color in hexadecimal format (e.g., “#ff0800” for red). The string should follow the standard 6-digit RGB hex code format, beginning with a #.
[ ]:
node = aidge_core.ReLU(name="Colorized Node!")
node.attributes().set_attr(name="model_explorer:bg_color", value="#ff0800")
node.attributes().set_attr(name="model_explorer:border_color", value="#00ff4c")
node.attributes().set_attr(name="model_explorer:h_border_color", value="#1100ff")
g = aidge_core.sequential([node])
aidge_model_explorer.visualize(g, "Colored_ReLU", embed=True)
Default Visualizations#
The Aidge Model Explorer provides default visualization options to help users get started quickly.
Implementation Status Visualization#
This feature adds an attribute and colors nodes in red when no suitable implementation is found (for example, when input/output datatypes don’t match). The attribute, named fail_best_match, contains:
A description of the current node’s specifications
The specifications for which Aidge has registered implementations
[ ]:
mul_node = aidge_core.Mul(name="mul")
p0 = aidge_core.Producer(aidge_core.Tensor(int(0)), name="p0")
p1 = aidge_core.Producer(aidge_core.Tensor(float(1)), name="p1")
p0.add_child(mul_node, 0, 0)
p1.add_child(mul_node, 0, 1)
ill_graph = aidge_core.GraphView()
ill_graph.add({mul_node, p0, p1})
We can now verify whether an implementation exists for the CPU backend.
[ ]:
import aidge_backend_cpu # <- Need to import this module to dynamically load the implementations
aidge_model_explorer.has_best_match(ill_graph, "cpu")
As expected, Aidge does not have an implementation for multiplying an integer and a float, so the Mul node is marked as failing in the visualization.