tom:

The short answer is not really. The JIT supports classes insofar as they are static - if you JIT-compile Modules, you don’t give it the class source but rather an instance. It will then go through the data members and see and process their types, assuming they will be fixed (which isn’t the case in Python in general).


This bit’s interesting. I might’ve been misunderstanding the cache behavior here. If I script different instances of the same class at different times, does it use the cache or treat every instance separately? script, not trace. Because if it treats instances separately, could assigning different modules to attributes be a workaround for JITing functions that make use of modules from arguments (by not passing them through arguments…)?



 tom:

Maybe you might find more success in taking the “JIT” part more literally, e.g. JIT-compiling a local function from a dynamic function.


Which is why I’d imagine being able to “JIT” the same function with different types. Am I misinterpreting this?



 tom:

More seriously we discuss this a bit in section 15.3.1 Interacting with the PyTorch JIT / What to expect from moving beyond classic Python/PyTorch of out book that you can download in exchange for anwering a few questions .


Looks great! Thanks for the rec.