Helper to compare float tensors
| 43 | |
| 44 | // Helper to compare float tensors |
| 45 | bool compare_float_tensors(const lfs::core::Tensor& gs_t, const torch::Tensor& torch_t, |
| 46 | float tol = FLOAT_TOLERANCE) { |
| 47 | if (gs_t.numel() != torch_t.numel()) { |
| 48 | std::cout << " Size mismatch: gs=" << gs_t.numel() |
| 49 | << " torch=" << torch_t.numel() << std::endl; |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | auto gs_cpu = gs_t.cpu().to_vector(); |
| 54 | auto torch_cpu = torch_t.cpu(); |
| 55 | auto torch_ptr = torch_cpu.data_ptr<float>(); |
| 56 | |
| 57 | for (size_t i = 0; i < gs_t.numel(); ++i) { |
| 58 | float diff = std::abs(gs_cpu[i] - torch_ptr[i]); |
| 59 | if (diff > tol) { |
| 60 | std::cout << " Mismatch at index " << i << ": gs=" << gs_cpu[i] |
| 61 | << " torch=" << torch_ptr[i] << " diff=" << diff << std::endl; |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | // Helper to compare int tensors |
| 69 | bool compare_int_tensors(const lfs::core::Tensor& gs_t, const torch::Tensor& torch_t) { |