code: def _script_if_tracing(fn: Callable[P, R]) -> Callable[P, R]:
      @functools.wraps(fn)
      def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
          if not is_tracing():
              # Not tracing, don't do anything
              return fn(*args, **kwargs)
  
          compiled_fn: Callable[P, R] = script(wrapper.__original_fn)  # type: ignore[attr-defined]
          return compiled_fn(*args, **kwargs)
  
      wrapper.__original_fn = fn  # type: ignore[attr-defined]
      wrapper.__script_if_tracing_wrapper = True  # type: ignore[attr-defined]
  
      return wrapper
  
imports: import contextlib
  import copy
  import functools
  import inspect
  import os
  import re
  import warnings
  from typing import Any, Callable, Dict, List, Optional, Set, TypeVar
  from typing_extensions import ParamSpec
  import torch
  from torch._jit_internal import _qualified_name, get_callable_argument_names, is_scripting
  from torch.autograd import function
  from torch.jit._script import _CachedForward, script, ScriptModule
  from torch.jit._state import _enabled, _python_cu
  from torch.nn import Module
  from torch.testing._comparison import default_tolerances
label_desc: Use image node_id 15 for calling a global function with example usage: _script_if_tracing(fn) and returns: wrapper, compiled_fn, fn