to_graph¶
- 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.Note
The package
graphviz
is required to use this function.Note
The most common interfaces for the returned graph object are:
- Parameters:
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 asChildDataPipe
of demux and fork). Defaults toFalse
.
Example
>>> 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 = dp1.map(lambda x: x + 1) >>> dp2 = dp2.filter(lambda _: True) >>> dp3 = dp1.zip(dp2).map(lambda t: t[0] + t[1]) >>> g = to_graph(dp3) >>> g.view() # This will open the graph in a viewer