For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python function
subgraphable
subgraphable()
max.experimental.nn.subgraphable(module, *, name=None)
Marks a Module to call to a subgraph.
Use this to speed up graph build and compilation time.
When a name is given, all modules with that name will share the same subgraph. When a name is not given, the IR of the module’s traced call is used to determine whether an existing subgraph can be used (this process is slow, but guarantees correctness).
Use it as a class decorator so an ordinary layer loop auto-shares a body:
@subgraphable
@module_dataclass
class Block(Module[[Tensor], Tensor]): ...
def forward(self, x):
for layer in self.layers: # each call reuses one shared subgraph
x = layer(x)
return xOr mark a single instance directly: subgraphable(layer, name="block").
-
Parameters:
-
Returns:
-
The same class or instance, marked so
Module.__call__()lowers each call into a shared subgraph. -
Raises:
-
Return type:
-
_T