Decorator @torch.compiler.disable() backward compability

Hi,

I have a model that I want to compile, but I need to disable compilation for some functions inside the class. I use @torch.compiler.disable() to disable compilation for these functions, and an argparse parameter to decide whether to attempt compilation.

The issue arises when using an older version of PyTorch that does not support torch.compile. I get an error because torch.compile does not exist in those versions. How can I use this decorator while maintaining backward compatibility? Note that the user should not use the compile parameter with the old PyTorch version, but the decorator still causes an issue.

Thanks

PyTorch does not guarantee forward compatibility, i.e. running new code in older PyTorch releases, but backwards compatibility, i.e. older code should run fine in newer PyTorch releases.
You could check the torch.__version__ inside the script and raise an error asking users to either update PyTorch or to remove the compile usage (you could also try to use compile conditionally based on the version).