We need to deploy pytorch models to e.g. Android, so we need a method to export a model. This is my starting point. Can you please tell me if I am on the right way or if I am doing something totally stupid?
import sys
import torch
from torch import nn
from torchvision import models
from torch.utils.serialization import load_lua

def dump(f):
	s = str(f.__class__)
	sys.stdout.write(s[s.rfind('.')+1:-2]+'(')
	for fa in f.previous_functions:
		if isinstance(fa[0], torch.autograd.Function):
			dump(fa[0])
			sys.stdout.write(',')
		if isinstance(fa[0], torch.nn.parameter.Parameter):
			sys.stdout.write('param,')
		elif isinstance(fa[0], torch.autograd.Variable):
			sys.stdout.write('input,')
	sys.stdout.write(')')


class MyNet(nn.Module):
    def __init__(self):
        super(MyNet, self).__init__()
        self.conv1 = nn.Conv2d(3, 16, kernel_size=1, bias=False)
        self.bn1 = nn.BatchNorm2d(16)
        self.conv2 = nn.Conv2d(3, 16, kernel_size=1, bias=True)

    def forward(self, x):
        return self.bn1(self.conv1(x))+self.conv2(x)
        

#net = models.alexnet()
#net=load_lua('model.net') #Legacy networks won't work (no support for Variables)
net = MyNet()
input=torch.autograd.Variable(torch.zeros(1,3,128,128))
output=net.forward(input)
dump(output.creator)
print('')

The output for the simple MyNet will be
Add(BatchNorm(ConvNd(input,param,),param,param,),ConvNd(input,param,param,),)

Thanks