From 8ebfe03f95fc4cab0d89242fbaced5faf7f730c8 Mon Sep 17 00:00:00 2001 From: Colin Kealty <3266127+bartowski1182@users.noreply.github.com> Date: Thu, 12 Mar 2026 14:06:23 -0400 Subject: [PATCH] Move test-only stuff out of llama-quant.cpp --- src/llama-quant.cpp | 58 -------------------------- src/llama-quant.h | 5 --- tests/test-quant-type-selection.cpp | 63 +++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/llama-quant.cpp b/src/llama-quant.cpp index 6a1e46122a..e0aa84379f 100644 --- a/src/llama-quant.cpp +++ b/src/llama-quant.cpp @@ -755,64 +755,6 @@ ggml_type llama_ftype_get_default_type(llama_ftype ftype) { } } -struct ftype_name_entry { - const char * name; - llama_ftype ftype; -}; - -static const ftype_name_entry ftype_name_table[] = { - { "F32", LLAMA_FTYPE_ALL_F32 }, - { "F16", LLAMA_FTYPE_MOSTLY_F16 }, - { "BF16", LLAMA_FTYPE_MOSTLY_BF16 }, - { "Q4_0", LLAMA_FTYPE_MOSTLY_Q4_0 }, - { "Q4_1", LLAMA_FTYPE_MOSTLY_Q4_1 }, - { "Q5_0", LLAMA_FTYPE_MOSTLY_Q5_0 }, - { "Q5_1", LLAMA_FTYPE_MOSTLY_Q5_1 }, - { "Q8_0", LLAMA_FTYPE_MOSTLY_Q8_0 }, - { "Q2_K", LLAMA_FTYPE_MOSTLY_Q2_K }, - { "Q2_K_S", LLAMA_FTYPE_MOSTLY_Q2_K_S }, - { "Q3_K_S", LLAMA_FTYPE_MOSTLY_Q3_K_S }, - { "Q3_K_M", LLAMA_FTYPE_MOSTLY_Q3_K_M }, - { "Q3_K_L", LLAMA_FTYPE_MOSTLY_Q3_K_L }, - { "Q4_K_S", LLAMA_FTYPE_MOSTLY_Q4_K_S }, - { "Q4_K_M", LLAMA_FTYPE_MOSTLY_Q4_K_M }, - { "Q5_K_S", LLAMA_FTYPE_MOSTLY_Q5_K_S }, - { "Q5_K_M", LLAMA_FTYPE_MOSTLY_Q5_K_M }, - { "Q6_K", LLAMA_FTYPE_MOSTLY_Q6_K }, - { "IQ1_S", LLAMA_FTYPE_MOSTLY_IQ1_S }, - { "IQ1_M", LLAMA_FTYPE_MOSTLY_IQ1_M }, - { "IQ2_XXS", LLAMA_FTYPE_MOSTLY_IQ2_XXS }, - { "IQ2_XS", LLAMA_FTYPE_MOSTLY_IQ2_XS }, - { "IQ2_S", LLAMA_FTYPE_MOSTLY_IQ2_S }, - { "IQ2_M", LLAMA_FTYPE_MOSTLY_IQ2_M }, - { "IQ3_XXS", LLAMA_FTYPE_MOSTLY_IQ3_XXS }, - { "IQ3_XS", LLAMA_FTYPE_MOSTLY_IQ3_XS }, - { "IQ3_S", LLAMA_FTYPE_MOSTLY_IQ3_S }, - { "IQ3_M", LLAMA_FTYPE_MOSTLY_IQ3_M }, - { "IQ4_NL", LLAMA_FTYPE_MOSTLY_IQ4_NL }, - { "IQ4_XS", LLAMA_FTYPE_MOSTLY_IQ4_XS }, - { "TQ1_0", LLAMA_FTYPE_MOSTLY_TQ1_0 }, - { "TQ2_0", LLAMA_FTYPE_MOSTLY_TQ2_0 }, - { "MXFP4_MOE", LLAMA_FTYPE_MOSTLY_MXFP4_MOE }, -}; - -llama_ftype llama_ftype_from_name(const char * name) { - for (const auto & e : ftype_name_table) { - if (strcmp(name, e.name) == 0) { - return e.ftype; - } - } - return (llama_ftype)-1; -} - -const char * llama_ftype_to_name(llama_ftype ftype) { - for (const auto & e : ftype_name_table) { - if (e.ftype == ftype) { - return e.name; - } - } - return nullptr; -} void init_quantize_state_counters(quantize_state_impl & qs, std::vector & metadata) { for (auto & tm : metadata) { diff --git a/src/llama-quant.h b/src/llama-quant.h index d8fe643557..1614aa4013 100644 --- a/src/llama-quant.h +++ b/src/llama-quant.h @@ -86,11 +86,6 @@ struct quantize_state_impl { ggml_type llama_tensor_get_type(quantize_state_impl & qs, const llama_model_quantize_params * params, const ggml_tensor * tensor, ggml_type default_type, const tensor_metadata & tm); ggml_type llama_ftype_get_default_type(llama_ftype ftype); -// Ftype name <-> enum conversions. -// Returns (llama_ftype)-1 on failure. -llama_ftype llama_ftype_from_name(const char * name); -const char * llama_ftype_to_name(llama_ftype ftype); - // Initialize quantize_state_impl counters and populate tensor_metadata categories. // metadata: vector with name fields already set, will have category field populated. void init_quantize_state_counters(quantize_state_impl & qs, std::vector & metadata); diff --git a/tests/test-quant-type-selection.cpp b/tests/test-quant-type-selection.cpp index fd4b81ac97..7dac3b6659 100644 --- a/tests/test-quant-type-selection.cpp +++ b/tests/test-quant-type-selection.cpp @@ -16,6 +16,69 @@ #include #include +// --------------------------------------------------------------------------- +// ftype name <-> enum mapping +// --------------------------------------------------------------------------- + +struct ftype_name_entry { + const char * name; + llama_ftype ftype; +}; + +static const ftype_name_entry ftype_name_table[] = { + { "F32", LLAMA_FTYPE_ALL_F32 }, + { "F16", LLAMA_FTYPE_MOSTLY_F16 }, + { "BF16", LLAMA_FTYPE_MOSTLY_BF16 }, + { "Q4_0", LLAMA_FTYPE_MOSTLY_Q4_0 }, + { "Q4_1", LLAMA_FTYPE_MOSTLY_Q4_1 }, + { "Q5_0", LLAMA_FTYPE_MOSTLY_Q5_0 }, + { "Q5_1", LLAMA_FTYPE_MOSTLY_Q5_1 }, + { "Q8_0", LLAMA_FTYPE_MOSTLY_Q8_0 }, + { "Q2_K", LLAMA_FTYPE_MOSTLY_Q2_K }, + { "Q2_K_S", LLAMA_FTYPE_MOSTLY_Q2_K_S }, + { "Q3_K_S", LLAMA_FTYPE_MOSTLY_Q3_K_S }, + { "Q3_K_M", LLAMA_FTYPE_MOSTLY_Q3_K_M }, + { "Q3_K_L", LLAMA_FTYPE_MOSTLY_Q3_K_L }, + { "Q4_K_S", LLAMA_FTYPE_MOSTLY_Q4_K_S }, + { "Q4_K_M", LLAMA_FTYPE_MOSTLY_Q4_K_M }, + { "Q5_K_S", LLAMA_FTYPE_MOSTLY_Q5_K_S }, + { "Q5_K_M", LLAMA_FTYPE_MOSTLY_Q5_K_M }, + { "Q6_K", LLAMA_FTYPE_MOSTLY_Q6_K }, + { "IQ1_S", LLAMA_FTYPE_MOSTLY_IQ1_S }, + { "IQ1_M", LLAMA_FTYPE_MOSTLY_IQ1_M }, + { "IQ2_XXS", LLAMA_FTYPE_MOSTLY_IQ2_XXS }, + { "IQ2_XS", LLAMA_FTYPE_MOSTLY_IQ2_XS }, + { "IQ2_S", LLAMA_FTYPE_MOSTLY_IQ2_S }, + { "IQ2_M", LLAMA_FTYPE_MOSTLY_IQ2_M }, + { "IQ3_XXS", LLAMA_FTYPE_MOSTLY_IQ3_XXS }, + { "IQ3_XS", LLAMA_FTYPE_MOSTLY_IQ3_XS }, + { "IQ3_S", LLAMA_FTYPE_MOSTLY_IQ3_S }, + { "IQ3_M", LLAMA_FTYPE_MOSTLY_IQ3_M }, + { "IQ4_NL", LLAMA_FTYPE_MOSTLY_IQ4_NL }, + { "IQ4_XS", LLAMA_FTYPE_MOSTLY_IQ4_XS }, + { "TQ1_0", LLAMA_FTYPE_MOSTLY_TQ1_0 }, + { "TQ2_0", LLAMA_FTYPE_MOSTLY_TQ2_0 }, + { "MXFP4_MOE", LLAMA_FTYPE_MOSTLY_MXFP4_MOE }, +}; + +static llama_ftype llama_ftype_from_name(const char * name) { + for (const auto & e : ftype_name_table) { + if (strcmp(name, e.name) == 0) { + return e.ftype; + } + } + return (llama_ftype)-1; +} + +static const char * llama_ftype_to_name(llama_ftype ftype) { + for (const auto & e : ftype_name_table) { + if (e.ftype == ftype) { + return e.name; + } + } + return nullptr; +} + // --------------------------------------------------------------------------- // Mock tensor construction - may be better to extract this in the future // ---------------------------------------------------------------------------