I figured it out! Somehow I missed that tensors have a .names attribute that gives me the required information:
x1 = torch.ones(1,3,4,4)
x2 = torch.ones(1,3,4,4).refine_names("D0", "D1", "D2", "D3")

print(x1.names)
print(x2.names)

(None, None, None, None)
('D0', 'D1', 'D2', 'D3')