How can I determine if a tensor has any named dimensions?

I would like to have my code used the named dimensions unless no dimensions exists, but I’m not sure how I would determine this.

Example:

x1 = torch.ones(1,3,4,4)
x2 = torch.ones(1,3,4,4).refine_names("D0", "D1", "D2", "D3")

x1 = #No named dims
x2 = # Has named dims

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')