Save and load Inline and Lowered Graphs as ScriptModules

Is it possible to save a inline’d and lowered graph as a ScriptModule and load it using torch.jit.load? My use case is to resolve the ClassType inputs into actual accessed tensor parameters.

Yes, this should be possible. What did you try that didn’t work ?

@eellison: Thanks for your response. I need some help/suggestion in how to proceed. Lowering a graph (which belongs to a scriptmodule’s method) returns a lowered graph and parameters. This pass replaces the input class object (for example "self") with actual parameters belonging to "self" which are accessed throughout the graph. Now, creating a method with this lowered graph and adding this method to a module will seem like adding a method which takes original inputs along with the parameter tensors. The question I had is, how do I package these parameters and this lowered graph such that when we run the method, I would only need to provide the inputs to original ScriptModule and not these parameters? Not sure if I am explaining the question well. Please do let me know if I am not thinking straight.

Could we do the following?

  1. Run LowerGraph pass: This pass will return a new Graph and a list of tensors.
  2. Add these Tensors as constants in the graph and remove the corresponding Graph input from the graph. Replace all the input’s references with the constants references.
  3. Create a module from this graph.

Is this a valid approach?

This will create a graph whose inputs are only the original model’s inputs.