ao icon indicating copy to clipboard operation
ao copied to clipboard

make it easier to debug tensor subclass metadata mismatch

Open vkuzo opened this issue 1 year ago • 1 comments

I'm hacking on a vLLM PoC, and I saw a stack trace like below:

[rank0]: ValueError: Not supported args for copy_ due to metadata mismatch: (Float8Tensor(self.act_quant_kwargs=None, self.qdata=tensor([[nan, nan, nan,  ..., nan, nan, nan],
[rank0]:         [nan, nan, nan,  ..., nan, nan, nan],
[rank0]:         [nan, nan, nan,  ..., nan, nan, nan],
[rank0]:         ...,
[rank0]:         [nan, nan, nan,  ..., nan, nan, nan],
[rank0]:         [nan, nan, nan,  ..., nan, nan, nan],
[rank0]:         [nan, nan, nan,  ..., nan, nan, nan]], device='cuda:0',
[rank0]:        dtype=torch.float8_e4m3fn), self.scale=tensor([[0.],
[rank0]:         [0.],
[rank0]:         [0.],
[rank0]:         ...,
[rank0]:         [0.],
[rank0]:         [0.],
[rank0]:         [0.]], device='cuda:0', dtype=torch.float32), self.block_size=[1, 2048], self.mm_config=Float8MMConfig(emulate=False, use_fast_accum=True, pad_inner_dim=False), self.kernel_preference=<KernelPreference.AUTO: 'auto'> self.shape=torch.Size([1408, 2048]), self.device=device(type='cuda', index=0), self.dtype=torch.bfloat16), Float8Tensor(self.act_quant_kwargs=None, self.qdata=tensor([[ -24.,  -18.,   44.,  ...,  104., -320., -176.],
[rank0]:         [ 160.,  128.,  128.,  ...,  112.,  -14.,   44.],
[rank0]:         [ -22.,   13.,   22.,  ...,   48.,  -13.,   72.],
[rank0]:         ...,
[rank0]:         [ -56., -112., -352.,  ..., -256.,   20.,   96.],
[rank0]:         [ 144.,  224.,  -52.,  ...,   40., -208.,  -15.],
[rank0]:         [-144.,  240.,  224.,  ...,  224.,   26.,  -80.]],
[rank0]:        dtype=torch.float8_e4m3fn), self.scale=tensor([[0.0001],
[rank0]:         [0.0001],
[rank0]:         [0.0001],
[rank0]:         ...,
[rank0]:         [0.0001],
[rank0]:         [0.0001],
[rank0]:         [0.0002]], dtype=torch.float32), self.block_size=[1, 2048], self.mm_config=Float8MMConfig(emulate=False, use_fast_accum=True, pad_inner_dim=False), self.kernel_preference=<KernelPreference.AUTO: 'auto'> self.shape=torch.Size([1408, 2048]), self.device=device(type='cpu'), self.dtype=torch.bfloat16))

It would be great if torchao told me exactly which attribute is not matching instead of me having to parse the wall of text.

vkuzo avatar Sep 23 '25 13:09 vkuzo

I'd like to pick this up. Plan: keep _same_metadata in torchao/utils.py as the boolean check, but factor its comparisons into a small helper that collects the list of mismatched fields (type, outer shape, per-tensor shapes from tensor_data_names / optional_tensor_data_names, and attributes from tensor_attribute_names / optional_tensor_attribute_names), then make the aten.copy_.default error report exactly the mismatched fields with concise values (e.g. self.device=cuda:0 vs src.device=cpu) instead of interpolating both tensors' full reprs. I'll add CPU tests in test/test_utils.py asserting the message names the exact mismatched field for attribute, inner-tensor-shape, and type mismatches. PR within ~48h.

sainikhiljuluri avatar Jul 30 '26 23:07 sainikhiljuluri