Compare all fields of two Tensor dataclasses.
(tensor_a: Tensor, tensor_b: Tensor)
| 323 | |
| 324 | |
| 325 | def _diff_tensor_metadata(tensor_a: Tensor, tensor_b: Tensor) -> List[FieldDiff]: |
| 326 | """Compare all fields of two Tensor dataclasses.""" |
| 327 | diffs: List[FieldDiff] = [] |
| 328 | if tensor_a.scalar_type != tensor_b.scalar_type: |
| 329 | diffs.append( |
| 330 | FieldDiff("scalar_type", tensor_a.scalar_type, tensor_b.scalar_type) |
| 331 | ) |
| 332 | if tensor_a.storage_offset != tensor_b.storage_offset: |
| 333 | diffs.append( |
| 334 | FieldDiff( |
| 335 | "storage_offset", tensor_a.storage_offset, tensor_b.storage_offset |
| 336 | ) |
| 337 | ) |
| 338 | if tensor_a.sizes != tensor_b.sizes: |
| 339 | diffs.append(FieldDiff("sizes", tensor_a.sizes, tensor_b.sizes)) |
| 340 | if tensor_a.dim_order != tensor_b.dim_order: |
| 341 | diffs.append(FieldDiff("dim_order", tensor_a.dim_order, tensor_b.dim_order)) |
| 342 | if tensor_a.requires_grad != tensor_b.requires_grad: |
| 343 | diffs.append( |
| 344 | FieldDiff("requires_grad", tensor_a.requires_grad, tensor_b.requires_grad) |
| 345 | ) |
| 346 | if tensor_a.layout != tensor_b.layout: |
| 347 | diffs.append(FieldDiff("layout", tensor_a.layout, tensor_b.layout)) |
| 348 | if tensor_a.data_buffer_idx != tensor_b.data_buffer_idx: |
| 349 | diffs.append( |
| 350 | FieldDiff( |
| 351 | "data_buffer_idx", tensor_a.data_buffer_idx, tensor_b.data_buffer_idx |
| 352 | ) |
| 353 | ) |
| 354 | if tensor_a.allocation_info != tensor_b.allocation_info: |
| 355 | diffs.append( |
| 356 | FieldDiff( |
| 357 | "allocation_info", tensor_a.allocation_info, tensor_b.allocation_info |
| 358 | ) |
| 359 | ) |
| 360 | if tensor_a.shape_dynamism != tensor_b.shape_dynamism: |
| 361 | diffs.append( |
| 362 | FieldDiff( |
| 363 | "shape_dynamism", tensor_a.shape_dynamism, tensor_b.shape_dynamism |
| 364 | ) |
| 365 | ) |
| 366 | _diff_extra_tensor_info( |
| 367 | tensor_a.extra_tensor_info, tensor_b.extra_tensor_info, diffs |
| 368 | ) |
| 369 | return diffs |
| 370 | |
| 371 | |
| 372 | def _diff_extra_tensor_info( |
no test coverage detected