parameters: (drop=False, **kwargs)
return_statement: return decorator
docstring: This decorator indicates to the compiler that a function or method should
      be ignored and left as a Python function. This allows you to leave code in
      your model that is not yet TorchScript compatible. If called from TorchScript,
      ignored functions will dispatch the call to the Python interpreter. Models with ignored
      functions cannot be exported; use :func:`@torch.jit.unused <torch.jit.unused>` instead.
  
      Example (using ``@torch.jit.ignore`` on a method)::
  
          import torch
          import torch.nn as nn
  
          class MyModule(nn.Module):
              @torch.jit.ignore
              def debugger(self, x):
                  import pdb
                  pdb.set_trace()
  
              def forward(self, x):
                  x += 10
                  # The compiler would normally try to compile `debugger`,
                  # but since it is `@ignore`d, it will be left as a call
                  # to Python
                  self.debugger(x)
                  return x
  
          m = torch.jit.script(MyModule())
  
          # Error! The call `debugger` cannot be saved since it calls into Python
          m.save("m.pt")
  
      Example (using ``@torch.jit.ignore(drop=True)`` on a method):
  
      .. testcode::
  
          import torch
          import torch.nn as nn
  
          class MyModule(nn.Module):
              @torch.jit.ignore(drop=True)
              def training_method(self, x):
                  import pdb
                  pdb.set_trace()
  
              def forward(self, x):
                  if self.training:
                      self.training_method(x)
                  return x
  
          m = torch.jit.script(MyModule())
  
          # This is OK since `training_method` is not saved, the call is replaced
          # with a `raise`.
          m.save("m.pt")
  
      .. testcleanup::
  
          import os
          os.remove('m.pt')
docstring_summary: This decorator indicates to the compiler that a function or method should
      be ignored and left as a Python function. This allows you to leave code in
      your model that is not yet TorchScript compatible. If called from TorchScript,
      ignored functions will dispatch the call to the Python interpreter. Models with ignored
      functions cannot be exported; use :func:`@torch.jit.unused <torch.jit.unused>` instead.
docstring_tokens: This decorator indicates to the compiler that a function or method should be ignored and left as a Python function . This allows you to leave code in your model that is not yet TorchScript compatible . If called from TorchScript ignored functions will dispatch the call to the Python interpreter . Models with ignored functions cannot be exported ; use : func : @torch . jit . unused <torch . jit . unused > instead .
function: def ignore(drop=False, **kwargs):
      """
      This decorator indicates to the compiler that a function or method should
      be ignored and left as a Python function. This allows you to leave code in
      your model that is not yet TorchScript compatible. If called from TorchScript,
      ignored functions will dispatch the call to the Python interpreter. Models with ignored
      functions cannot be exported; use :func:`@torch.jit.unused <torch.jit.unused>` instead.
  
      Example (using ``@torch.jit.ignore`` on a method)::
  
          import torch
          import torch.nn as nn
  
          class MyModule(nn.Module):
              @torch.jit.ignore
              def debugger(self, x):
                  import pdb
                  pdb.set_trace()
  
              def forward(self, x):
                  x += 10
                  # The compiler would normally try to compile `debugger`,
                  # but since it is `@ignore`d, it will be left as a call
                  # to Python
                  self.debugger(x)
                  return x
  
          m = torch.jit.script(MyModule())
  
          # Error! The call `debugger` cannot be saved since it calls into Python
          m.save("m.pt")
  
      Example (using ``@torch.jit.ignore(drop=True)`` on a method):
  
      .. testcode::
  
          import torch
          import torch.nn as nn
  
          class MyModule(nn.Module):
              @torch.jit.ignore(drop=True)
              def training_method(self, x):
                  import pdb
                  pdb.set_trace()
  
              def forward(self, x):
                  if self.training:
                      self.training_method(x)
                  return x
  
          m = torch.jit.script(MyModule())
  
          # This is OK since `training_method` is not saved, the call is replaced
          # with a `raise`.
          m.save("m.pt")
  
      .. testcleanup::
  
          import os
          os.remove('m.pt')
      """
  
      if callable(drop):
          # used without any args, so drop is actually a function
          #   @torch.jit.ignore
          #   def fn(...):
          fn = drop
          fn._torchscript_modifier = FunctionModifiers.IGNORE
          return fn
  
      if not isinstance(drop, bool):
          raise RuntimeError("Argument to @torch.jit.ignore must be a bool or "
                             f"a function but got {drop}")
  
      # for backwards compat
      drop_on_export = kwargs.pop("drop_on_export", None)
      if drop_on_export:
          warnings.warn("ignore(drop_on_export=True) has been deprecated. TorchScript will now drop the function "
                        "call on compilation. Use torch.jit.unused now. {}", category=FutureWarning)
  
          drop = drop_on_export
      elif drop:
          warnings.warn("ignore(True) has been deprecated. TorchScript will now drop the function "
                        "call on compilation. Use torch.jit.unused now. {}", category=FutureWarning)
  
      def decorator(fn):
          if drop:
              fn._torchscript_modifier = FunctionModifiers.UNUSED
          else:
              fn._torchscript_modifier = FunctionModifiers.IGNORE
          return fn
      return decorator
function_tokens: def ignore ( drop = False , * * kwargs ) : if callable ( drop ) : # used without any args, so drop is actually a function #   @torch.jit.ignore #   def fn(...): fn = drop fn . _torchscript_modifier = FunctionModifiers . IGNORE return fn if not isinstance ( drop , bool ) : raise RuntimeError ( "Argument to @torch.jit.ignore must be a bool or " f"a function but got {drop}" ) # for backwards compat drop_on_export = kwargs . pop ( "drop_on_export" , None ) if drop_on_export : warnings . warn ( "ignore(drop_on_export=True) has been deprecated. TorchScript will now drop the function " "call on compilation. Use torch.jit.unused now. {}" , category = FutureWarning ) drop = drop_on_export elif drop : warnings . warn ( "ignore(True) has been deprecated. TorchScript will now drop the function " "call on compilation. Use torch.jit.unused now. {}" , category = FutureWarning ) def decorator ( fn ) : if drop : fn . _torchscript_modifier = FunctionModifiers . UNUSED else : fn . _torchscript_modifier = FunctionModifiers . IGNORE return fn return decorator