code: def test_unbind_get_stack_strides(dim: int, contiguous: bool):
      def not_stacked(t, d):
          return xformers.ops.get_stack_strides(t, d) is None
  
      x = torch.randn([10, 20, 4, 4, 3])
      ndim = x.ndim
  
      # Non-contiguous tensors
      if not contiguous:
          x = x.transpose(dim, (dim + 1) % ndim)
      assert contiguous == x.is_contiguous()
  
      tensors = xformers.ops.unbind(x, dim)
      tensors2 = torch.unbind(x.clone(), dim)
  
      for cat_dim in range(ndim):
          permute = list(range(ndim))
          permute.pop(dim)
          permute.insert(cat_dim, dim)
          x_permuted = x.permute(permute)
          assert not_stacked(
              [tensors2[0], tensors[1]], cat_dim
          ), "different storage"
          assert not_stacked(
              [tensors[0], tensors[1].clone()], cat_dim
          ), "different storage"
  
          def test_slice(s):
              slices = [slice(None) for _ in range(ndim)]
              slices[cat_dim] = s
              reference = x_permuted[tuple(slices)]
              stacked = xformers.ops.stack_or_none(tensors[s], cat_dim)
              assert stacked is not None
              assert (
                  xformers.ops.get_stack_strides(tensors[s], cat_dim)
                  == reference.stride()
              )
              assert torch.allclose(
                  stacked, torch.stack(tensors2[s], cat_dim)
              )
              assert _get_storage_base(stacked) == _get_storage_base(
                  tensors[0]
              )
  
          # tensors
          test_slice(slice(None))
  
          # tensors[1:]
          test_slice(slice(1, None))
  
          # tensors[:2]
          test_slice(slice(None, 2))
  
          # tensors[::2]
          test_slice(slice(None, None, 2))
  
imports: import random
  import pytest
  import torch
  import xformers.ops
  from xformers.ops.common import _get_storage_base
label_desc: Use image node_id 2 for calling a global function with example usage: test_unbind_get_stack_strides(dim, contiguous) and returns: unknown