Skip to content

Fix division-by-zero #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void per_tensor_quant(int k, void* lut_scales_, void* b_) {{
float32x4_t abssum = vabsq_f32(vec_bs);
temp_max = vmaxq_f32(abssum, temp_max);
}}
float32_t scales = 127 / vmaxvq_f32(temp_max);
float32_t scales = 127 / (vmaxvq_f32(temp_max) + 1e-10f);
*lut_scales = scales;
#elif defined __AVX2__
__m256 max_vec = _mm256_set1_ps(0.f);
Expand All @@ -45,7 +45,7 @@ void per_tensor_quant(int k, void* lut_scales_, void* b_) {{
__m128 max1 = _mm_max_ps(_mm256_extractf128_ps(max_vec, 1), _mm256_castps256_ps128(max_vec));
max1 = _mm_max_ps(max1, _mm_movehl_ps(max1, max1));
max1 = _mm_max_ss(max1, _mm_movehdup_ps(max1));
float scales = 127 / _mm_cvtss_f32(max1);
float scales = 127 / (_mm_cvtss_f32(max1) + 1e-10f);
*lut_scales = scales;
#endif
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ inline int32_t per_tensor_quant(int k, void* lut_scales_, void* b_) {
__m128 max1 = _mm_max_ps(_mm256_extractf128_ps(max_vec, 1), _mm256_castps256_ps128(max_vec));
max1 = _mm_max_ps(max1, _mm_movehl_ps(max1, max1));
max1 = _mm_max_ss(max1, _mm_movehdup_ps(max1));
float scales = 127 / _mm_cvtss_f32(max1);
float scales = 127 / (_mm_cvtss_f32(max1) + 1e-10f);
*lut_scales = scales;
#endif
return 0;
Expand Down
4 changes: 2 additions & 2 deletions preset_kernels/bitnet_b1_58-3B/bitnet-lut-kernels-tl1.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void per_tensor_quant(int k, void* lut_scales_, void* b_) {{
float32x4_t abssum = vabsq_f32(vec_bs);
temp_max = vmaxq_f32(abssum, temp_max);
}}
float32_t scales = 127 / vmaxvq_f32(temp_max);
float32_t scales = 127 / (vmaxvq_f32(temp_max) + 1e-10f);
*lut_scales = scales;
#elif defined __AVX2__
__m256 max_vec = _mm256_set1_ps(0.f);
Expand All @@ -45,7 +45,7 @@ void per_tensor_quant(int k, void* lut_scales_, void* b_) {{
__m128 max1 = _mm_max_ps(_mm256_extractf128_ps(max_vec, 1), _mm256_castps256_ps128(max_vec));
max1 = _mm_max_ps(max1, _mm_movehl_ps(max1, max1));
max1 = _mm_max_ss(max1, _mm_movehdup_ps(max1));
float scales = 127 / _mm_cvtss_f32(max1);
float scales = 127 / (_mm_cvtss_f32(max1) + 1e-10f);
*lut_scales = scales;
#endif
}}
Expand Down
2 changes: 1 addition & 1 deletion preset_kernels/bitnet_b1_58-3B/bitnet-lut-kernels-tl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ inline int32_t per_tensor_quant(int k, void* lut_scales_, void* b_) {
__m128 max1 = _mm_max_ps(_mm256_extractf128_ps(max_vec, 1), _mm256_castps256_ps128(max_vec));
max1 = _mm_max_ps(max1, _mm_movehl_ps(max1, max1));
max1 = _mm_max_ss(max1, _mm_movehdup_ps(max1));
float scales = 127 / _mm_cvtss_f32(max1);
float scales = 127 / (_mm_cvtss_f32(max1) + 1e-10f);
*lut_scales = scales;
#endif
return 0;
Expand Down
4 changes: 2 additions & 2 deletions preset_kernels/bitnet_b1_58-large/bitnet-lut-kernels-tl1.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void per_tensor_quant(int k, void* lut_scales_, void* b_) {{
float32x4_t abssum = vabsq_f32(vec_bs);
temp_max = vmaxq_f32(abssum, temp_max);
}}
float32_t scales = 127 / vmaxvq_f32(temp_max);
float32_t scales = 127 / (vmaxvq_f32(temp_max) + 1e-10f);
*lut_scales = scales;
#elif defined __AVX2__
__m256 max_vec = _mm256_set1_ps(0.f);
Expand All @@ -45,7 +45,7 @@ void per_tensor_quant(int k, void* lut_scales_, void* b_) {{
__m128 max1 = _mm_max_ps(_mm256_extractf128_ps(max_vec, 1), _mm256_castps256_ps128(max_vec));
max1 = _mm_max_ps(max1, _mm_movehl_ps(max1, max1));
max1 = _mm_max_ss(max1, _mm_movehdup_ps(max1));
float scales = 127 / _mm_cvtss_f32(max1);
float scales = 127 / (_mm_cvtss_f32(max1) + 1e-10f);
*lut_scales = scales;
#endif
}}
Expand Down
2 changes: 1 addition & 1 deletion preset_kernels/bitnet_b1_58-large/bitnet-lut-kernels-tl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ inline int32_t per_tensor_quant(int k, void* lut_scales_, void* b_) {
__m128 max1 = _mm_max_ps(_mm256_extractf128_ps(max_vec, 1), _mm256_castps256_ps128(max_vec));
max1 = _mm_max_ps(max1, _mm_movehl_ps(max1, max1));
max1 = _mm_max_ss(max1, _mm_movehdup_ps(max1));
float scales = 127 / _mm_cvtss_f32(max1);
float scales = 127 / (_mm_cvtss_f32(max1) + 1e-10f);
*lut_scales = scales;
#endif
return 0;
Expand Down