code: def test_spatial_transformer_default(self):
      torch.manual_seed(0)
      if torch.cuda.is_available():
          torch.cuda.manual_seed_all(0)
  
      sample = torch.randn(1, 32, 64, 64).to(torch_device)
      spatial_transformer_block = Transformer2DModel(
          in_channels=32,
          num_attention_heads=1,
          attention_head_dim=32,
          dropout=0.0,
          cross_attention_dim=None,
      ).to(torch_device)
      with torch.no_grad():
          attention_scores = spatial_transformer_block(sample).sample
  
      assert attention_scores.shape == (1, 32, 64, 64)
      output_slice = attention_scores[0, -1, -3:, -3:]
  
      expected_slice = torch.tensor(
          [
              -1.9455,
              -0.0066,
              -1.3933,
              -1.5878,
              0.5325,
              -0.6486,
              -1.8648,
              0.7515,
              -0.9689,
          ],
          device=torch_device,
      )
      assert torch.allclose(
          output_slice.flatten(), expected_slice, atol=1e-3
      )
  
imports: import unittest
  import numpy
  import torch
  from torch import nn
  from diffusers.models.attention import GEGLU, AdaLayerNorm, ApproximateGELU
  from diffusers.models.embeddings import get_timestep_embedding
  from diffusers.models.lora import LoRACompatibleLinear
  from diffusers.models.resnet import Downsample2D, ResnetBlock2D, Upsample2D
  from diffusers.models.transformer_2d import Transformer2DModel
  from diffusers.utils.testing_utils import torch_device
label_desc: Use image node_id 1 for calling the Transformer2DModelTests obj's underlying member method code with example usage: obj.test_spatial_transformer_default() without return types