oli4100:

auto X = torch::zeros({a, b}, torch::dtype(torch::[?]))
X.packed_accessor32<[?],2,torch::RestrictPtrTraits>()



Sometimes you search for something for hours only to find the answer shortly after asking the question  The following is the answer:
auto X = torch::zeros({a, b}, torch::dtype(at::ScalarType::BFloat16))
X.packed_accessor32<at::BFloat16,2,torch::RestrictPtrTraits>()