| 31 | } |
| 32 | |
| 33 | void test_float32_matches_torch_cuda() { |
| 34 | const std::vector<float> expected_seed_1234 = { |
| 35 | -1.61649048F, 0.56845516F, -0.510224819F, -0.911339402F, |
| 36 | -1.15551639F, -0.22615087F, -1.2891326F, 1.065382F, |
| 37 | -0.7166605F, -0.533334374F, 0.207757875F, -0.979843318F, |
| 38 | 0.744693458F, -0.239484429F, 0.27371496F, 0.092008315F, |
| 39 | }; |
| 40 | const auto actual = engine::sampling::generate_torch_cuda_randn( |
| 41 | expected_seed_1234.size(), |
| 42 | 1234, |
| 43 | engine::sampling::TorchRandnPrecision::Float32); |
| 44 | require_vector_close(actual, expected_seed_1234, 2.0e-6F, "float32 torch_cuda_randn"); |
| 45 | |
| 46 | const auto extended = engine::sampling::generate_torch_cuda_randn( |
| 47 | 300, |
| 48 | 1234, |
| 49 | engine::sampling::TorchRandnPrecision::Float32); |
| 50 | const std::vector<std::pair<size_t, float>> expected_positions = { |
| 51 | {16, -0.803610802F}, |
| 52 | {17, -1.6377064F}, |
| 53 | {31, -0.300402969F}, |
| 54 | {32, -0.251393795F}, |
| 55 | {63, -0.924830973F}, |
| 56 | {64, 0.799798131F}, |
| 57 | {127, -0.167921364F}, |
| 58 | {128, -0.322486848F}, |
| 59 | {255, -1.76037288F}, |
| 60 | {256, 0.534284174F}, |
| 61 | {299, -0.986868858F}, |
| 62 | }; |
| 63 | for (const auto & [index, expected] : expected_positions) { |
| 64 | require_close(extended[index], expected, 2.0e-6F, "float32 torch_cuda_randn high index"); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void test_bfloat16_matches_torch_cuda() { |
| 69 | const std::vector<float> expected_seed_5678 = { |
no test coverage detected