code: def dispatch_strategy(
      fn: NativeFunctionWithDifferentiabilityInfo,
  ) -> str:
      """How are we going to call the underlying implementation of a
      declaration?  There are two strategies:
          - use_derived: we want to call the implementation on CPUDoubleType
            (or a similar, derived Type instance).  Because these derived
            instances deal in Tensors, not Variables (it's a completely different
            object, so it doesn't dispatch back to VariableType), code on
            this dispatch path needs to wrap/unwrap tensors.  If the
            derived implementation takes and returns tensors, the
            implementation is usually differentiable (although we also use
            the derived dispatch path for non-differentiable functions
            that we still want to dispatch on the derived Type instance;
            e.g., size())
          - use_type: we want to call the implementation on Type, because
            it is implemented concretely, and the functions it invokes will
            get dispatched back to VariableType (which will ensure that they
            are differentiable.)
      """
      # fn is derived as long as any of its per-key differentiability infos
      # has_derivatives. dispatch_strategy() is used to guard generation of fns in VariableType
      # and ADInplaceOrViewType. We want to generate these functions as long as a
      # derivative is defined for ANY dispatch key.
      if fn.func.is_abstract or (
          fn.info is not None
          and any(info.has_derivatives for info in fn.info.values())
      ):
          # If the function is abstract (not implemented on at::Type), we must
          # call the implementation on the derived type with unpacked tensors.
  
          # If the function has a derivative specified and is concrete, we could
          # call either implementation. We prefer the calling the derived
          # type's implementation with unpacked tensors because it is more
          # performant in some cases: any internal calls to other ATen functions
          # won't have the history tracked.
  
          # If the function has a type dispatched argument (i.e. is a factory),
          # we prefer calling the derived type's implementation both because it is
          # more performant and to ensure factory functions return tensors with _version
          # of 0 (probably not strictly necessary, but nice to have to keeps versions simple
          # to understand.
  
          return "use_derived"
      else:
          # If the function is concrete (we don't have to override it) and we
          # didn't declare it in derivatives.yaml, we'll assume that it is
          # actually implemented out of differentiable functions. (This
          # assumption might not hold, but then you'll see gradcheck fail.)
          return "use_type"
  
imports: import re
  from dataclasses import dataclass
  from typing import cast, Dict, List, Match, Optional, Sequence, Set, Tuple
  from torchgen import local
  from torchgen.api import cpp
  from torchgen.api.types import BaseCType, Binding, NamedCType, tensorListT
  from torchgen.model import BaseTy, BaseType, FunctionSchema, ListType, NativeFunction, NativeFunctionsViewGroup, SchemaKind, Type
  from torchgen.utils import IDENT_REGEX
label_desc: Use image node_id 4 for calling a global function with example usage: dispatch_strategy(fn) and returns: str, str