code: def replace(Klass):
      old_call = Klass.visit_reference
  
      def visit_reference(self, node):
          if "refuri" in node and "generated" in node.get("refuri"):
              ref = node.get("refuri")
              ref_anchor = ref.split("#")
              if len(ref_anchor) > 1:
                  # Only add the id if the node href and the text match,
                  # i.e. the href is "torch.flip#torch.flip" and the content is
                  # "torch.flip" or "flip" since that is a signal the node refers
                  # to autogenerated content
                  anchor = ref_anchor[1]
                  txt = node.parent.astext()
                  if txt == anchor or txt == anchor.split(".")[-1]:
                      self.body.append(f'<p id="{ref_anchor[1]}"/>')
          return old_call(self, node)
  
      Klass.visit_reference = visit_reference
  
file_path: pytorch/docs/source/conf.py
imports: import os
  import pkgutil
  import re
  from os import path
  import torch
  import pytorch_sphinx_theme
  from sphinx.ext.coverage import CoverageBuilder
  from sphinx.writers import html, html5
  import sphinx.ext.doctest
  from docutils import nodes
  from sphinx import addnodes
  from sphinx.util.docfields import TypedField
label_desc: Use image node_id 4 for calling a global function with example usage: replace(Klass) and returns: old_call