Skip to content

Commit 9c22a28

Browse files
nihuiCopilot
andauthored
Update src/layer/gemm.cpp
Co-authored-by: Copilot <[email protected]>
1 parent 17b7109 commit 9c22a28

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/layer/gemm.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ int Gemm::load_model(const ModelBin& mb)
212212
{
213213
// block quantize
214214
const i6x4_t* i6ptr1 = i6ptr + j * block_size / 4;
215-
const float inv_scale = 1.f / scale_ptr[j];
215+
// Prevent division by zero: if scale_ptr[j] == 0, use 1.0 as safe default
216+
const float safe_scale = (scale_ptr[j] == 0.f) ? 1.f : scale_ptr[j];
217+
const float inv_scale = 1.f / safe_scale;
216218
float* ptr1 = ptr + j * block_size;
217219
const int block_size1 = std::min(block_size, constantK - j * block_size);
218220

0 commit comments

Comments
 (0)