torchdata.datapipes.utils.to_graph(dp, *, debug: bool = False) graphviz.Digraph

Visualizes a DataPipe by returning a graphviz.Digraph, which is a graph of the data pipeline. This allows you to visually inspect all the transformation that takes place in your DataPipes.


The package graphviz is required to use this function.


The most common interfaces for the returned graph object are:

  • render(): Save the graph to a file.

  • view(): Open the graph in a viewer.

  • dp – DataPipe that you would like to visualize (generally the last one in a chain of DataPipes).

  • debug (bool) – If True, renders internal datapipes that are usually hidden from the user (such as ChildDataPipe of demux and fork). Defaults to False.


>>> from torchdata.datapipes.iter import IterableWrapper
>>> from torchdata.datapipes.utils import to_graph
>>> dp = IterableWrapper(range(10))
>>> dp1, dp2 = dp.demux(num_instances=2, classifier_fn=lambda x: x % 2)
>>> dp1 = x: x + 1)
>>> dp2 = dp2.filter(lambda _: True)
>>> dp3 = t: t[0] + t[1])
>>> g = to_graph(dp3)
>>> g.view()  # This will open the graph in a viewer


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources