| 66 | } |
| 67 | |
| 68 | void test_bfloat16_matches_torch_cuda() { |
| 69 | const std::vector<float> expected_seed_5678 = { |
| 70 | -0.65625F, -0.5625F, 0.384765625F, -0.151367188F, |
| 71 | 0.7421875F, 0.244140625F, 0.609375F, 0.00321960449F, |
| 72 | -0.46875F, 0.306640625F, -0.225585938F, -0.9140625F, |
| 73 | 0.7734375F, 0.120117188F, 0.52734375F, -0.5078125F, |
| 74 | }; |
| 75 | const auto actual = engine::sampling::generate_torch_cuda_randn( |
| 76 | expected_seed_5678.size(), |
| 77 | 5678, |
| 78 | engine::sampling::TorchRandnPrecision::BFloat16); |
| 79 | require_vector_close(actual, expected_seed_5678, 0.0F, "bfloat16 torch_cuda_randn"); |
| 80 | |
| 81 | const auto extended = engine::sampling::generate_torch_cuda_randn( |
| 82 | 300, |
| 83 | 1234, |
| 84 | engine::sampling::TorchRandnPrecision::BFloat16); |
| 85 | const std::vector<std::pair<size_t, float>> expected_positions = { |
| 86 | {16, -0.8046875F}, |
| 87 | {17, -1.640625F}, |
| 88 | {31, -0.30078125F}, |
| 89 | {32, -0.251953125F}, |
| 90 | {63, -0.92578125F}, |
| 91 | {64, 0.80078125F}, |
| 92 | {127, -0.16796875F}, |
| 93 | {128, -0.322265625F}, |
| 94 | {255, -1.7578125F}, |
| 95 | {256, 0.53515625F}, |
| 96 | {299, -0.98828125F}, |
| 97 | }; |
| 98 | for (const auto & [index, expected] : expected_positions) { |
| 99 | require_close(extended[index], expected, 0.0F, "bfloat16 torch_cuda_randn high index"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void test_fill_matches_vector_api() { |
| 104 | std::vector<float> filled(257, 0.0F); |
no test coverage detected