iga:

Because I never use this attribute in compiled methods, there should not be a reason to try compiling it and discarding.


I’m not sure I understand the use case completely, but you are indeed using it in the scripted m module.
If you create an eager module first, the attribute will be there:
module = M(Foo())
m = torch.jit.script(module)
m.get_f() # error
module.get_f() # works