transcribe-cpp-sys 0.5.1

Native FFI bindings for transcribe.cpp, a C/C++ speech-to-text library built on ggml
Documentation
#include "npu_quant_policy.h"

#include "ggml-impl.h"
#include "ggml.h"

#include <mutex>
#include <string>

ExtraQuantType ggml_openvino_get_npu_requant_type() {
    const std::string policy = ggml_openvino_getenv_str("GGML_OPENVINO_NPU_REQUANT_POLICY", "group-128");
    if (policy == "group-128") {
        return ExtraQuantType::Q4_0_128;
    }
    if (policy == "channel-wise") {
        return ExtraQuantType::Q4_0_C;
    }
    GGML_ABORT("Unknown GGML_OPENVINO_NPU_REQUANT_POLICY: %s", policy.c_str());
}

std::optional<ExtraQuantType> ggml_openvino_npu_token_embd_requant_type(const ggml_tensor * tensor) {
    // A Q6_K embedding table is stored as q8_0_c by default on the NPU. The int4 layouts only pay off for a tied
    // embedding, where the table is also the lm_head weight and GET_ROWS gathers the packed rows
    // before dequantizing them (see gather_compressed_rows).
    if (tensor->type != GGML_TYPE_Q6_K) {
        return std::nullopt;
    }
    const std::string quant = ggml_openvino_getenv_str("GGML_OPENVINO_NPU_TOKEN_EMBD_QUANT", "q8_0_c");
    ExtraQuantType type;
    if (quant == "f16") {
        type = ExtraQuantType::F16;
    } else if (quant == "q8_0_c") {
        type = ExtraQuantType::Q8_0_C;
    } else if (quant == "q4_0_128") {
        type = ExtraQuantType::Q4_0_128;
    } else if (quant == "q4_0_c") {
        type = ExtraQuantType::Q4_0_C;
    } else {
        GGML_ABORT("Unknown GGML_OPENVINO_NPU_TOKEN_EMBD_QUANT: %s", quant.c_str());
    }
    static std::once_flag logged;
    std::call_once(logged, [&] {
        GGML_LOG_INFO("ggml-openvino: NPU token_embd.weight requant type: %s\n", quant.c_str());
    });
    return type;
}

std::optional<ExtraQuantType> ggml_openvino_npu_weight_requant_type(const ggml_tensor * tensor) {
    const ExtraQuantType type = ggml_openvino_get_npu_requant_type();
    // a group must fit within a row
    if (type == ExtraQuantType::Q4_0_128 && tensor->ne[0] % 128 != 0) {
        return ExtraQuantType::Q4_0_C;
    }
    return type;
}