Compare two tensors at the same evalue index. Returns None if identical.
(
idx: int,
tensor_a: Tensor,
tensor_b: Tensor,
op_map_a: Dict[int, List[OperatorUsage]],
op_map_b: Dict[int, List[OperatorUsage]],
constant_buffer_a: list,
constant_buffer_b: list,
mutable_data_a: Optional[list],
mutable_data_b: Optional[list],
max_samples: int,
)
| 546 | |
| 547 | |
| 548 | def _diff_tensors( |
| 549 | idx: int, |
| 550 | tensor_a: Tensor, |
| 551 | tensor_b: Tensor, |
| 552 | op_map_a: Dict[int, List[OperatorUsage]], |
| 553 | op_map_b: Dict[int, List[OperatorUsage]], |
| 554 | constant_buffer_a: list, |
| 555 | constant_buffer_b: list, |
| 556 | mutable_data_a: Optional[list], |
| 557 | mutable_data_b: Optional[list], |
| 558 | max_samples: int, |
| 559 | ) -> Optional[TensorDataDiff]: |
| 560 | """Compare two tensors at the same evalue index. Returns None if identical.""" |
| 561 | info_a = _make_tensor_info(idx, tensor_a, op_map_a) |
| 562 | info_b = _make_tensor_info(idx, tensor_b, op_map_b) |
| 563 | |
| 564 | metadata_diffs = _diff_tensor_metadata(tensor_a, tensor_b) |
| 565 | |
| 566 | bytes_a = _get_tensor_bytes(tensor_a, constant_buffer_a, mutable_data_a) |
| 567 | bytes_b = _get_tensor_bytes(tensor_b, constant_buffer_b, mutable_data_b) |
| 568 | |
| 569 | has_data = bytes_a is not None or bytes_b is not None |
| 570 | data_matches = bytes_a is not None and bytes_b is not None and bytes_a == bytes_b |
| 571 | |
| 572 | if not metadata_diffs and (not has_data or data_matches): |
| 573 | return None |
| 574 | |
| 575 | td = TensorDataDiff( |
| 576 | tensor_a=info_a, |
| 577 | tensor_b=info_b, |
| 578 | byte_size_a=len(bytes_a) if bytes_a else 0, |
| 579 | byte_size_b=len(bytes_b) if bytes_b else 0, |
| 580 | bytes_differ=not data_matches if has_data else False, |
| 581 | metadata_diffs=metadata_diffs, |
| 582 | ) |
| 583 | |
| 584 | if has_data and not data_matches and bytes_a is not None and bytes_b is not None: |
| 585 | ( |
| 586 | td.num_elements, |
| 587 | td.num_differing, |
| 588 | td.max_abs_diff, |
| 589 | td.mean_abs_diff, |
| 590 | td.element_diffs, |
| 591 | ) = _compute_tensor_stats( |
| 592 | bytes_a, bytes_b, tensor_a.scalar_type, tensor_a.sizes, max_samples |
| 593 | ) |
| 594 | |
| 595 | return td |
| 596 | |
| 597 | |
| 598 | def _diff_execution_plan( # noqa: C901 |
no test coverage detected