Utils Compat#
compat
#
| FUNCTION | DESCRIPTION |
|---|---|
jit_compile |
Conditionally apply torch.jit.script or torch.compile based on |
Functions#
jit_compile(func)
#
Conditionally apply torch.jit.script or torch.compile based on availability.
Python 3.14+ deprecates torch.jit.script in favor of torch.compile. This decorator provides backward and forward compatibility by:
- Using torch.compile if available (PyTorch 2.0+) and Python >= 3.14
- Using torch.jit.script on Python < 3.14
- Falling back to eager mode if neither is available or compilation fails
Can disable torch.compile by setting the environment variable: - TORCH_COMPILE_DISABLE=1
Version requirements:
- torch.jit.script: PyTorch 1.0+ (all versions)
- torch.compile: PyTorch 2.0+ only
Note
On Python 3.14+, torch.compile may still emit deprecation warnings about torch.jit.script_method internally. These warnings are from PyTorch's own implementation.
| PARAMETER | DESCRIPTION |
|---|---|
func
|
Function to potentially compile.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
callable
|
Compiled function or original function if compilation is unavailable. |