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.
- 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#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.