code: def test_classifier_free_guidance(self):
      class Namespace(dict):
          pass
  
      logits_uncond = torch.tensor([[[1.0, 0, 1.5]]])
      logits_cond = torch.tensor([[[1.0, 1.0, 1.0]]])
  
      def dummy_model(
          input_ids,
          attention_mask,
          use_cache=True,
          past_key_values=None,
      ):
          out = Namespace()
          out.logits = logits_uncond
          out.past_key_values = None
          return out
  
      def lsm(x):
          return torch.nn.functional.log_softmax(x, dim=-1)
  
      # explicit unconditional prompt + attention mask
      input_ids = torch.LongTensor([[0]])
      cfg = UnbatchedClassifierFreeGuidanceLogitsProcessor(
          1.5,
          dummy_model,
          input_ids,
          torch.ones_like(input_ids, dtype=torch.long),
      )
      out = cfg(input_ids, logits_cond)[0, -1]
  
      res = (
          lsm(logits_uncond)
          + 1.5 * (lsm(logits_cond) - lsm(logits_uncond))
      )[0, -1]
  
      self.assertAlmostEqual(out[0].item(), res[0].item())
      self.assertAlmostEqual(out[1].item(), res[1].item())
      self.assertAlmostEqual(out[2].item(), res[2].item())
  
      # explicit unconditional prompt
      input_ids = torch.LongTensor([[0]])
      cfg = UnbatchedClassifierFreeGuidanceLogitsProcessor(
          1.5, dummy_model, input_ids
      )
      out = cfg(input_ids, logits_cond)[0, -1]
  
      res = (
          lsm(logits_uncond)
          + 1.5 * (lsm(logits_cond) - lsm(logits_uncond))
      )[0, -1]
  
      self.assertAlmostEqual(out[0].item(), res[0].item())
      self.assertAlmostEqual(out[1].item(), res[1].item())
      self.assertAlmostEqual(out[2].item(), res[2].item())
  
      # all implicit
      input_ids = torch.LongTensor([[0]])
      cfg = UnbatchedClassifierFreeGuidanceLogitsProcessor(
          1.5, dummy_model
      )
      out = cfg(input_ids, logits_cond)[0, -1]
  
      res = (
          lsm(logits_uncond)
          + 1.5 * (lsm(logits_cond) - lsm(logits_uncond))
      )[0, -1]
  
      self.assertAlmostEqual(out[0].item(), res[0].item())
      self.assertAlmostEqual(out[1].item(), res[1].item())
      self.assertAlmostEqual(out[2].item(), res[2].item())
  
imports: import unittest
  from typing import List, Union
  from parameterized import parameterized
  from transformers import is_torch_available
  from transformers.testing_utils import require_torch, torch_device
  from ..test_modeling_common import ids_tensor
label_desc: Use image node_id 24 for calling the LogitsProcessorTest obj's underlying member method code with example usage: obj.test_classifier_free_guidance() and returns: out, torch