docstr: Verify that we can populate and load functions from the cache.
docstr_tok: ["Verify","that","we","can","populate","and","load","functions","from","the","cache","."]
code: def test_cache_load_function(self, device, dtype, dynamic):
      """
      Verify that we can populate and load functions from the cache.
      """
      if device == "cuda" and not HAS_CUDA:
          raise unittest.SkipTest("requires CUDA")
      if (
          device == "cuda"
          and dtype == torch.bfloat16
          and not SM80OrLater
      ):
          raise unittest.SkipTest("requires SM80 or later")
  
      def fn(x, y):
          return (x * 2, y @ y)
  
      a = torch.rand(25, dtype=dtype, device=device)
      b = torch.rand(5, 5, dtype=dtype, device=device)
      c = a.view(5, 5)
  
      compiled_fn = torch.compile(fn, dynamic=dynamic)
  
      # A first call shold miss in the cache.
      self.assertEqual(fn(a, b), compiled_fn(a, b))
      self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 1)
      self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 0)
  
      # A second call should hit. (First reset so in-memory guards
      # don't prevent compilation).
      torch._dynamo.reset()
      self.assertEqual(fn(a, b), compiled_fn(a, b))
      self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 1)
      self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 1)
  
      # But we expect different code if the tensors are aliased.
      torch._dynamo.reset()
      self.assertEqual(fn(a, c), compiled_fn(a, c))
      self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 2)
      self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 1)
  
imports: import functools
  import pickle
  import tempfile
  import unittest
  from unittest.mock import patch
  import torch
  from torch._dynamo.test_case import run_tests, TestCase
  from torch._dynamo.utils import counters
  from torch._inductor import config
  from torch._inductor.codecache import AsyncCompile, FxGraphCachePickler, FxGraphHashDetails, TensorMetadata, TensorMetadataAndValues
  from torch.testing._internal.common_cuda import SM80OrLater
  from torch.testing._internal.common_device_type import largeTensorTest
  from torch.testing._internal.common_utils import instantiate_parametrized_tests, parametrize
  from torch.testing._internal.inductor_utils import HAS_CUDA
  from torch.utils._triton import has_triton
label_desc: Use image node_id 4 for calling the TestFxGraphCache obj's underlying member method code with example usage: obj.test_cache_load_function(device, dtype, dynamic) and returns: unknown,  unknown