Download code/tt_sam3/utils.py from changh95/sam3-p150: direct link, hf CLI and curl.
- Browser
- Download file 918 Bytes
-
https://huggingface.co/changh95/sam3-p150/resolve/main/code/tt_sam3/utils.py
- Command line
-
hf download hf://changh95/sam3-p150/code/tt_sam3/utils.py
-
curl -L -o utils.py https://huggingface.co/changh95/sam3-p150/resolve/main/code/tt_sam3/utils.py
918 Bytes
| # SPDX-FileCopyrightText: (c) 2026 Tenstorrent AI ULC | |
| # SPDX-License-Identifier: Apache-2.0 | |
| """PCC utilities — standalone replacements for tests.ttnn.utils_for_testing.""" | |
| import torch | |
| def comp_pcc(a: torch.Tensor, b: torch.Tensor, pcc_threshold: float = 0.99): | |
| """Compute Pearson correlation coefficient between two tensors. | |
| Returns: | |
| (bool, float): (passes_threshold, pcc_value) | |
| """ | |
| a = a.detach().double().flatten() | |
| b = b.detach().double().flatten() | |
| a = a - a.mean() | |
| b = b - b.mean() | |
| denom = (a.norm() * b.norm()).item() + 1e-12 | |
| pcc_val = float((a @ b).item() / denom) | |
| return pcc_val >= pcc_threshold, pcc_val | |
| def assert_with_pcc(a: torch.Tensor, b: torch.Tensor, pcc: float = 0.99): | |
| """Assert PCC between two tensors meets threshold.""" | |
| passes, pcc_val = comp_pcc(a, b, pcc) | |
| assert passes, f"PCC {pcc_val:.6f} < {pcc}" | |
| return passes, pcc_val | |