3

When I compile my torch model to torchscript I can make use of the function forward by just calling the torchscript model object model().

But when I want to use another function created on the model I cant call the function. I try to do model.functionName() expecting to call the function functionName but nothing happens.

Any idea on how could I call subfunctions from the model object that are not forward?

Thanks

eljiwo
  • 687
  • 1
  • 8
  • 29
  • Do you want to apply the change only on that model or also on its layers? – aaossa Mar 15 '22 at 12:35
  • Also, is this a temporal change or you want to just replace the original `forward`? – aaossa Mar 15 '22 at 12:37
  • I dont get what you mean but change on model or layers. Is not a temporal change and it wont replace the forward neither. Is a function similar to the forward one, but where I convert float tensors to strings with a torchtext layer vocab() that the model has. Since the output type is different torchscript doesnt allow me to have both logics within one function, I need to create a different one. – eljiwo Mar 15 '22 at 23:09

1 Answers1

1

I suppose you should add decorator @torch.jit.export above the method you want to call and convert torchscript model again. After that you can call method by module.run_method(name, args) docs.

teplandr
  • 176
  • 1
  • 9