Skip to main content

Intro to MAX Graph

The MAX Graph API allows you to build your entire AI inference pipeline in Mojo. By building the graph with MAX Graph, you can combine the performance and programmability of Mojo with the cutting-edge compiler technologies and hardware portability provided by MAX Engine. This combination allows you to build highly performant graphs, with less code that’s more readable than code from other performance-based graph libraries in C or C++.

We built MAX Graph because, although MAX Engine can execute models from frameworks such as PyTorch and TensorFlow faster than the default runtimes, sometimes the high-level abstractions still leave performance on the table. With the MAX Graph API, we give you full control of the graph at a lower level.


The Graph API is a low-level Mojo API that allows you to create an acyclic graph (as a Graph) using ops provided in max.graph.ops or using custom ops that you create in Mojo.

All ops are connected to each other with Symbol values, which define the edges in the graph. A Symbol represents a value that doesn't actually exist until execution time. It could be a graph input, a constant, or the output of an op.

To add ops to your graph, you chain a sequence of op functions (each function takes a Symbol—an input, a constant, or other op output), and then add that sequence to the graph by passing the final op Symbol to Graph.output().

You can think of a complete Graph like a function definition, except it's a static computation graph, not an eager execution graph. That means you cannot execute the graph until you compile it with MAX Engine.


The Graph API is not designed to train models. Currently, you must load the weights into the model as constants.

Get started

To learn more, see the MAX Graph tutorial or the Graph API examples in GitHub.

Also see how you can implement custom ops in MAX Graph.