Repository: microsoft/onnxruntime
File: onnxruntime/contrib_ops/cpu/moe/moe_quantization_cpu.cc (C++)

Code before:
        DequantizeBlock(fc1_weights_data + expert_idx * fc1_out_features * fc1_packed_cols,
                        fc1_scales_ptr,
                        is_fc1_block_wise ? block_size_ : 0, expert_weight_bits_,
                        fc1_out_features, hidden_size, B1_dequant, tp);
      }

      MlasGemm(CblasNoTrans, CblasTrans,
               m, n, k,
               1.0f, A1, k,
               B1_dequant, k,
               0.0f, C1, n,
               tp);

      fc1_bias_handled_by_q4_gemm = fc1_used_direct_q4 && has_fc1_bias;
      if (has_fc1_bias && !fc1_bias_handled_by_q4_gemm) {
        const T* B1_bias = fc1_bias_data + expert_idx * fc1_out_features;
        if constexpr (std::is_same_v<T, MLFloat16>) {
          MlasConvertHalfToFloatBuffer(reinterpret_cast<const MLFloat16*>(B1_bias), thread_bias1_buffer, static_cast<size_t>(fc1_out_features));
        } else {
          if (ShouldUseMemcpy(fc1_out_features)) {
            std::memcpy(thread_bias1_buffer, B1_bias, static_cast<size_t>(fc1_out_features) * sizeof(float));
          } else {
            const int64_t unroll_factor = GetUnrollFactor(fc1_out_features);
            int64_t j = 0;
            for (; j + unroll_factor <= fc1_out_features; j += unroll_factor) {
              for (size_t loop_k = 0; loop_k < unroll_factor; ++loop_k) {
                thread_bias1_buffer[j + loop_k] = static_cast<float>(B1_bias[j + loop_k]);
              }
            }
            for (; j < fc1_out_features; ++j) {
              thread_bias1_buffer[j] = static_cast<float>(B1_bias[j]);
            }
          }
        }

        for (int64_t i = 0; i < num_expert_tokens; ++i) {
          float* C1_row = C1 + i * fc1_out_features;
          const int64_t unroll_factor = GetUnrollFactor(fc1_out_features);

          int64_t j = 0;
          for (; j + unroll_factor <= fc1_out_features; j += unroll_factor) {
            for (size_t loop_k = 0; loop_k < unroll_factor; ++loop_k) {
              C1_row[j + loop_k] += thread_bias1_buffer[j + loop_k];
            }
          }
          for (; j < fc1_out_features; ++j) {
            C1_row[j] += thread_bias1_buffer[j];
          }
        }
      }


Review comment (suggestion):
>unroll_factor [](http://example.com/codeflow?start=47&length=13)

This compares size_t to int64_t, that should be caused to size_t along with j.
Indexing witn int64 on 32-bit platforms is error prone. #Resolved

Code after:
        DequantizeBlock(fc1_weights_data + expert_idx * fc1_out_features * fc1_packed_cols,
                        fc1_scales_ptr,
                        is_fc1_block_wise ? block_size_ : 0, expert_weight_bits_,
                        fc1_out_features, hidden_size, B1_dequant, tp);
      }

      MlasGemm(CblasNoTrans, CblasTrans,
               m, n, k,
               1.0f, A1, k,
               B1_dequant, k,
               0.0f, C1, n,
               tp);

      fc1_bias_handled_by_q4_gemm = fc1_used_direct_q4 && has_fc1_bias;
      if (has_fc1_bias && !fc1_bias_handled_by_q4_gemm) {
        const T* B1_bias = fc1_bias_data + expert_idx * fc1_out_features;
        if constexpr (std::is_same_v<T, MLFloat16>) {
          MlasConvertHalfToFloatBuffer(reinterpret_cast<const MLFloat16*>(B1_bias), thread_bias1_buffer, static_cast<size_t>(fc1_out_features));
        } else {
          if (ShouldUseMemcpy(fc1_out_features)) {
            std::memcpy(thread_bias1_buffer, B1_bias, static_cast<size_t>(fc1_out_features) * sizeof(float));
          } else {
            const size_t unroll_factor = static_cast<size_t>(GetUnrollFactor(fc1_out_features));
            size_t j = 0;
            for (; j + unroll_factor <= static_cast<size_t>(fc1_out_features); j += unroll_factor) {
              for (size_t loop_k = 0; loop_k < unroll_factor; ++loop_k) {
                thread_bias1_buffer[j + loop_k] = static_cast<float>(B1_bias[j + loop_k]);
              }
            }
            for (; j < static_cast<size_t>(fc1_out_features); ++j) {
              thread_bias1_buffer[j] = static_cast<float>(B1_bias[j]);
            }
          }
        }

        for (int64_t i = 0; i < num_expert_tokens; ++i) {
          float* C1_row = C1 + i * fc1_out_features;
          const size_t unroll_factor = static_cast<size_t>(GetUnrollFactor(fc1_out_features));

          size_t j = 0;
          for (; j + unroll_factor <= static_cast<size_t>(fc1_out_features); j += unroll_factor) {
            for (size_t loop_k = 0; loop_k < unroll_factor; ++loop_k) {
              C1_row[j + loop_k] += thread_bias1_buffer[j + loop_k];
            }
          }
          for (; j < static_cast<size_t>(fc1_out_features); ++j) {
            C1_row[j] += thread_bias1_buffer[j];
          }
        }
      }