openvino
4d83b594 - Disable fp16 compression for periodic func (#31249)

Commit
308 days ago
Disable fp16 compression for periodic func (#31249) ### Description of the issue(symptom, root-cause, how it was resolved) **- Expected result (FP32)** ![output_result_expected](https://github.com/user-attachments/assets/595e997f-4c12-415d-9cd4-387d0b2d25a0) **- Actual result (FP16)** ![output_result_actual](https://github.com/user-attachments/assets/db077ae7-5a78-4f6d-9232-0db436dba6bc) **- root cause** - In RoPE, the periodic function such as sin and cos return incorrect results due to FP16 precision issue. This impacts the variance of the result data and causes accuracy issues in the output for ltx-video. - I found same accuracy issues related to FP16 precision occurring with std::sin and std::cos. - **Test codes and output resutls** ```c++ std::vector<float> fp32_input_vec = { -9555.0f, -10340.642578f, 10234.32454f, 9342.f, -21.0f, 10.f, 100.f, -50.f, -5.f, 5.f, 1.f, -2.f }; std::vector<ov::float16> fp16_input_vec; for (auto& in : fp32_input_vec) { fp16_input_vec.push_back(ov::float16(in)); } std::cout << "input,std::sin(float),std::sin(float16),std::cos(float),std::cos(float16)" << std::endl; for (size_t i = 0; i < fp32_input_vec.size(); ++i) { std::cout << fp32_input_vec[i] << "," << std::sin(fp32_input_vec[i]) << "," << std::sin(fp16_input_vec[i]) << "," << std::cos(fp32_input_vec[i]) << "," << std::cos(fp16_input_vec[i]) << std::endl; } ``` | Input | std::sin(fp32) | std::sin(fp16) | std::cos(fp32) | std::cos(fp16) | |-----------|----------------|----------------|----------------|----------------| | -9555.f | 0.988157 | -0.999922 | -0.153447 | 0.0124629 | | -10340.6f | 0.99592 | -0.95349 | 0.0902359 | -0.301426 | | 10234.3 | -0.833077 | 0.166494 | 0.553158 | -0.986042 | | 9342.f | -0.889638 | 0.785466 | 0.456666 | 0.618905 | | -21.f | -0.836656 | -0.836656 | -0.547729 | -0.547729 | | 10.f | -0.544021 | -0.544021 | -0.839072 | -0.839072 | | 100.f | -0.506366 | -0.506366 | 0.862319 | 0.862319 | | -50.f | 0.262375 | 0.262375 | 0.964966 | 0.964966 | | -5.f | 0.958924 | 0.958924 | 0.283662 | 0.283662 | | 5.f | -0.958924 | -0.958924 | 0.283662 | 0.283662 | | 1.f | 0.841471 | 0.841471 | 0.540302 | 0.540302 | | -2.f | -0.909297 | -0.909297 | -0.416147 | -0.416147 | - **how it is resolved** - To address this accuracy issue, disable FP16 compression for periodic functions such as sin and cos in models with FP16 inference precision. - Disable FP16 compression for periodic functions. - Traverse inputs to locate the first node that modifies output data based on input data. - Skip and continue traversing inputs if the current node does not compute output data using input data, such as nodes like reshape or transpose. - Disable FP16 compression for the identified node. #### The code and line that caused this issue (if it is not changed directly) - openvino/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/activation_ref.cl (activation_ref) - In the activation kernel, OpenCL's sin and cos functions return incorrect results due to FP16 precision issues. The kernel itself doesn't have an issue; the problem lies with the precision of the FP16 input data. #### Reproduction step and snapshot (if applicable. Do not attach for customer model) - you can run ltx-video from the sample code in https://huggingface.co/Lightricks/LTX-Video/blob/main/README.md #### Problematic graph - problematic graph ![graph_issued](https://github.com/user-attachments/assets/fd20171a-54e3-4cf9-a5cd-ee25515c1e78) - fixed graph : sin, cos and multiply are disabled fp16 compression ![graph_fixed](https://github.com/user-attachments/assets/2e6069b3-4197-43e3-b472-4fbad51d9250) #### Checklist - [ ] Is it a proper fix? (not a workaround) - Need to review to make a proper fix - [ ] Did you include test case for this fix, if necessary? - Will be added functional test - [ ] Did you review existing test that can be extended to cover this scenario? Which test did you review? ### Tickets: - *166691*
Author
Parents
Loading