Export computation graph

is there any way to export the actual computation graph of a model that is trained or not? Since ‘model.state_dict()’ give the weights in an ordered dict. By some manual coding, It can be made as JSON. Theoretically, weights can be sent as JSON over the net. If it possible to generate sent computation graph as follows

class linearRegression(nn.Module):
    def __init__(self):
        super(linearRegression, self).__init__()
        self.linear = nn.Linear(1, 1)

    def forward(self, x):
        out = self.linear(x)
        return out

model = linearRegression()


#OrderedDict([('linear.weight', tensor([[0.6289]])),
#            ('linear.bias', tensor([0.7113]))])

but when I have to export to libtorch(C++), I have to make an exact same copy of the class to use the model. I guess there might be an easy way which I don’t know that to an export graph from different language

You can use the JIT and script the model as described here.