Download tests/activation_test.cpp from Sariel00/Ling-3.0-tiny-RKNN: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/Sariel00/Ling-3.0-tiny-RKNN/resolve/main/tests/activation_test.cpp
- Command line
-
hf download hf://Sariel00/Ling-3.0-tiny-RKNN/tests/activation_test.cpp
-
curl -L -o activation_test.cpp https://huggingface.co/Sariel00/Ling-3.0-tiny-RKNN/resolve/main/tests/activation_test.cpp
1.62 kB
| int main() { | |
| double worst = 0.0; | |
| for (const int count : {1, 3, 4, 7, 128, 8193}) { | |
| std::vector<float> input(count), up(count), out(count), inplace(count); | |
| for (int i = 0; i < count; ++i) { | |
| input[i] = 80.0F * std::sin(i * 0.013F); | |
| up[i] = std::cos(i * 0.17F); | |
| } | |
| for (const bool multiply : {false, true}) { | |
| inplace = input; | |
| if (multiply) { | |
| ling3::SiluMultiply(input.data(), up.data(), out.data(), count); | |
| ling3::SiluMultiply(inplace.data(), up.data(), inplace.data(), count); | |
| } else { | |
| ling3::Silu(input.data(), out.data(), count); | |
| ling3::Silu(inplace.data(), inplace.data(), count); | |
| } | |
| for (int i = 0; i < count; ++i) { | |
| const double value = input[i]; | |
| const double expected = value / (1.0 + std::exp(-value)) * | |
| (multiply ? static_cast<double>(up[i]) : 1.0); | |
| const double error = std::abs(out[i] - expected) / std::max(1.0, std::abs(expected)); | |
| worst = std::max(worst, error); | |
| if (!std::isfinite(out[i]) || out[i] != inplace[i] || error > 5e-7) { | |
| std::cerr << "activation mismatch count=" << count << " index=" << i | |
| << " error=" << error << '\n'; | |
| return 1; | |
| } | |
| } | |
| } | |
| } | |
| std::cout << "max_scaled_error=" << worst << '\n'; | |
| } | |