Rate this Page

torch.jit.script_if_tracing#

torch.jit.script_if_tracing(fn)[source]#

Compilesfn when it is first called during tracing.

torch.jit.script has a non-negligible start up time when it is first called due tolazy-initializations of many compiler builtins. Therefore you should not useit in library code. However, you may want to have parts of your library workin tracing even if they use control flow. In these cases, you should use@torch.jit.script_if_tracing to substitute fortorch.jit.script.

Parameters

fn – A function to compile.

Returns

If called during tracing, aScriptFunction created bytorch.jit.script is returned.Otherwise, the original functionfn is returned.