TDGraphModule#
- class tensordict.prototype.fx.TDGraphModule(graph_module: GraphModule, out_keys: list[NestedKey])#
Bases:
ModuleThe module that
symbolic_trace()returns: an FX graph that reads and writes a tensordict.A call reads the
in_keysof the traced module from the input tensordict, runs the graph, and writes the outputs atout_keys, intotensordict_outif given, else into the input. Thegraphandcodeattributes are those of the underlyingtorch.fx.GraphModule.This class is a prototype: its API can change without a deprecation period. See
symbolic_trace()for an example.- Parameters:
graph_module (GraphModule) – the traced graph.
out_keys (list of NestedKey) – the keys where the outputs are written.
- forward(tensordict: TensorDictBase, tensordict_out: TensorDictBase | None = None, **kwargs) TensorDictBase#
Runs the graph on
tensordictand writes the outputs atout_keys.- Parameters:
tensordict (TensorDictBase) – the input tensordict.
tensordict_out (TensorDictBase, optional) – the tensordict to write the outputs into. Defaults to
None, which writes them intotensordict.**kwargs – passed to the graph.
- Returns:
The tensordict that holds the outputs.