Download code/tt_sam3/tests/test_ttnn_sam3_patch_embed.py from changh95/sam3-p150: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/changh95/sam3-p150/resolve/main/code/tt_sam3/tests/test_ttnn_sam3_patch_embed.py
- Command line
-
hf download hf://changh95/sam3-p150/code/tt_sam3/tests/test_ttnn_sam3_patch_embed.py
-
curl -L -o test_ttnn_sam3_patch_embed.py https://huggingface.co/changh95/sam3-p150/resolve/main/code/tt_sam3/tests/test_ttnn_sam3_patch_embed.py
1.25 kB
| # SPDX-FileCopyrightText: © 2025 Tenstorrent AI ULC | |
| # SPDX-License-Identifier: Apache-2.0 | |
| import pytest | |
| import torch | |
| import ttnn | |
| from tt_sam3.utils import assert_with_pcc | |
| def test_tt_patch_embed(device, reset_seeds, batch_size, sam3_vit_backbone): | |
| """Test PatchEmbed against PyTorch reference.""" | |
| from tt_sam3.tt.ttnn_sam3_vitdet import tt_patch_embed, get_patch_embed_params | |
| torch.manual_seed(42) | |
| # Reference | |
| ref_model = sam3_vit_backbone | |
| pixel_values = torch.randn(batch_size, 3, 1008, 1008) | |
| with torch.no_grad(): | |
| ref_output = ref_model.patch_embed(pixel_values) # (B, H, W, C) = (1, 72, 72, 1024) | |
| # Our implementation | |
| params = get_patch_embed_params(ref_model) | |
| tt_output = tt_patch_embed(pixel_values, params["weight"], params["bias"], device) | |
| tt_output_torch = ttnn.to_torch(tt_output) | |
| # Compare - shape should match | |
| assert tt_output_torch.shape[-3:] == ref_output.shape[-3:], ( | |
| f"Shape mismatch: {tt_output_torch.shape} vs {ref_output.shape}" | |
| ) | |
| # PCC check | |
| assert_with_pcc(ref_output.float(), tt_output_torch.float(), 0.999) | |