code: def test_blocksparse_attention_parity(dtype):
      def _reset_seeds():
          torch.manual_seed(0)
  
      seq = 64
      model = 128
      heads = 4
      block_size = 16
      batch_size = 2
      batched_dim = heads * batch_size
      dim_head = model // heads
  
      test_config = {
          "dropout": 0.0,
          "causal": False,
          "seq_len": seq,
          "num_heads": 4,
          "dim_head": dim_head,
          "block_size": block_size,
          "layout": torch.ones(
              seq // block_size, seq // block_size, dtype=torch.long
          ),
      }
  
      inputs = torch.rand(
          batched_dim, seq, model, device="cuda", dtype=dtype
      )
  
      _reset_seeds()
      test_config["name"] = "scaled_dot_product"
      attention_sdp = build_attention(test_config)
      multi_head_sdp = MultiHeadDispatch(
          seq_len=seq,
          dim_model=model,
          residual_dropout=0.0,
          num_heads=heads,
          attention=attention_sdp,
      ).to(device=torch.device("cuda"), dtype=dtype)
      r_sdp = multi_head_sdp(inputs, inputs, inputs)
  
      _reset_seeds()
      test_config["name"] = "blocksparse"
      attention_blocksparse = build_attention(test_config)
      multi_head_blocksparse = MultiHeadDispatch(
          seq_len=seq,
          dim_model=model,
          residual_dropout=0.0,
          num_heads=heads,
          attention=attention_blocksparse,
      ).to(device=torch.device("cuda"), dtype=dtype)
      r_blocksparse = multi_head_blocksparse(inputs, inputs, inputs)
  
      torch.testing.assert_close(
          r_sdp, r_blocksparse, atol=5e-5, rtol=6e-3
      )
  
file_path: xformers/tests/test_triton_blocksparse.py
imports: import functools
  import pytest
  import torch
  import xformers
  from xformers.components import MultiHeadDispatch
  from xformers.components.attention import build_attention
  from xformers.components.attention.attention_patterns import block_sparsify_tensor
label_desc: Use image node_id 6 for calling a global function with example usage: test_blocksparse_attention_parity(dtype) without return types