class_docstr: A class to create libraries that can be used to register new operators or
  override operators in existing libraries from Python.
  A user can optionally pass in a dispatch keyname if they only want to register
  kernels corresponding to only one specific dispatch key.
  
  To create a library to override operators in an existing library (with name ns), set the kind to "IMPL".
  To create a new library (with name ns) to register new operators, set the kind to "DEF".
  To create a fragment of a possibly existing library to register operators (and bypass
  the limitation that there is only one library for a given namespace), set the kind to
  "FRAGMENT".
  
  Args:
      ns: library name
      kind: "DEF", "IMPL" (default: "IMPL"), "FRAGMENT"
      dispatch_key: PyTorch dispatch key (default: "")
docstr: Registers the function implementation for an operator defined in the library.
  
  Args:
      op_name: operator name (along with the overload) or OpOverload object.
      fn: function that's the operator implementation for the input dispatch key or :func:`~fallthrough_kernel`
          to register a fallthrough.
      dispatch_key: dispatch key that the input function should be registered for. By default, it uses
                    the dispatch key that the library was created with.
  
  Example::
      >>> my_lib = Library("aten", "IMPL")
      >>> def div_cpu(self, other):
      >>>     return self * (1 / other)
      >>> my_lib.impl("div.Tensor", div_cpu, "CPU")
docstr_tok: ["Registers","the","function","implementation","for","an","operator","defined","in","the","library",".","Args",":","op_name",":","operator","name","(","along","with","the","overload",")","or","OpOverload","object",".","fn",":","function","that","'s","the","operator","implementation","for","the","input","dispatch","key","or",":","func",":","`","~fallthrough_kernel","`","to","register","a","fallthrough",".","dispatch_key",":","dispatch","key","that","the","input","function","should","be","registered","for",".","By","default",",","it","uses","the","dispatch","key","that","the","library","was","created","with",".","Example",":",":",">",">",">","my_lib","=","Library","(","``","aten","''",",","``","IMPL","''",")",">",">",">","def","div_cpu","(","self",",","other",")",":",">",">",">","return","self","*","(","1","\/","other",")",">",">",">","my_lib.impl","(","``","div.Tensor","''",",","div_cpu",",","``","CPU","''",")"]
code: def impl(self, op_name, fn, dispatch_key=""):
      r"""Registers the function implementation for an operator defined in the library.
  
      Args:
          op_name: operator name (along with the overload) or OpOverload object.
          fn: function that's the operator implementation for the input dispatch key or :func:`~fallthrough_kernel`
              to register a fallthrough.
          dispatch_key: dispatch key that the input function should be registered for. By default, it uses
                        the dispatch key that the library was created with.
  
      Example::
          >>> my_lib = Library("aten", "IMPL")
          >>> def div_cpu(self, other):
          >>>     return self * (1 / other)
          >>> my_lib.impl("div.Tensor", div_cpu, "CPU")
      """
      if not callable(fn):
          raise TypeError(
              f"Input function is required to be a callable but found type {type(fn)}"
          )
      if dispatch_key == "":
          dispatch_key = self.dispatch_key
  
      if isinstance(op_name, str):
          name = op_name
      elif isinstance(op_name, OpOverload):
          name = op_name._schema.name
          overload_name = op_name._schema.overload_name
          if overload_name != "":
              name = name + "." + overload_name
      else:
          raise RuntimeError(
              "impl should be passed either a name or an OpOverload object as the first argument"
          )
  
      key = self.ns + "/" + name.split("::")[-1] + "/" + dispatch_key
      if key in _impls:
          # TODO: in future, add more info about where the existing function is registered (this info is
          # today already returned by the C++ warning when impl is called but we error out before that)
          raise RuntimeError(
              "This is not allowed since there's already a kernel registered from python overriding {}"
              "'s behavior for {} dispatch key and {} namespace.".format(
                  name.split("::")[-1], dispatch_key, self.ns
              )
          )
  
      if dispatch_key == "Meta":
          dispatcher_op_name = name
          if "::" not in dispatcher_op_name:
              dispatcher_op_name = f"{self.ns}::{dispatcher_op_name}"
  
          # Internally, we shouldn't be registering meta kernels for any operators that
          # have CompositeImplicitAutograd kernels.
          # Instead, we should be letting those decompositions run, and writing meta kernels
          # only for the base operators.
          if torch._C._dispatch_has_kernel_for_dispatch_key(
              dispatcher_op_name, "CompositeImplicitAutograd"
          ):
              raise RuntimeError(
                  f"We should not register a meta kernel directly to the operator '{name}',"
                  " because it has a CompositeImplicitAutograd kernel in core."
                  " Instead we should let the operator decompose, and ensure that we have meta kernels"
                  " for the base ops that it decomposes into."
              )
  
      assert self.m is not None
      self.m.impl(
          name,
          dispatch_key
          if dispatch_key != ""
          else "CompositeImplicitAutograd",
          fn,
      )
  
      _impls.add(key)
      self._op_impls.add(key)
  
imports: from ._ops import OpOverload
  from typing import Any, Optional, Set, List
  import traceback
  import torch
  import weakref
  import functools
  import inspect
  import re
  import sys
label_desc: Use image node_id 4 for calling the Library obj's underlying member method code with example usage: obj.impl(op_name, fn, dispatch_key) without return types