Commit 532d67426 for llama.cpp

commit 532d67426bb874f06a8acc6959af81b34206f7f9
Author: AWA <bc15575202581@gmail.com>
Date:   Wed Nov 25 23:02:25 2026 +0800

    vocab : implement Metaspace prepend_scheme always for BPE (#33038)

    * vocab : implement Metaspace prepend_scheme always for BPE

    * Drop test-tokenizer-mmbert

diff --git a/src/llama-vocab.cpp b/src/llama-vocab.cpp
index a3ddc9b38..9e83a983e 100644
--- a/src/llama-vocab.cpp
+++ b/src/llama-vocab.cpp
@@ -693,8 +693,8 @@ struct llm_tokenizer_bpe_session {

         symbols_final.clear();

-        if (tok_pre == LLAMA_VOCAB_PRE_TYPE_MMBERT) {
-            // Metaspace pre-tokenizer: a text starts with an escaped space, and each escaped space starts a new word
+        if (vocab.get_metaspace_prepend_scheme() == LLAMA_METASPACE_PREPEND_SCHEME_ALWAYS) {
+            // Metaspace pre-tokenizer (prepend_scheme = "always"): each non-newline chunk starts with an escaped space, and each escaped space starts a new word
             std::vector<std::string> words;
             for (auto & word : word_collection) {
                 if (word.find_first_not_of('\n') == std::string::npos) {
@@ -2530,6 +2530,7 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
                     tokenizer_pre == "mmbert") {
                 pre_type = LLAMA_VOCAB_PRE_TYPE_MMBERT;
                 escape_whitespaces = true;
+                metaspace_prepend_scheme = LLAMA_METASPACE_PREPEND_SCHEME_ALWAYS;
             } else if (
                     tokenizer_pre == "sarvam-moe") {
                 pre_type = LLAMA_VOCAB_PRE_TYPE_SARVAM_MOE;
@@ -3022,9 +3023,6 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
                 } else {
                     throw std::runtime_error(format("unknown metaspace prepend_scheme: '%s'", scheme.c_str()));
                 }
-                if (type == LLAMA_VOCAB_TYPE_BPE && metaspace_prepend_scheme == LLAMA_METASPACE_PREPEND_SCHEME_ALWAYS) {
-                    throw std::runtime_error("metaspace prepend_scheme 'always' is not supported for BPE vocab");
-                }
             }
         }

@@ -4587,6 +4585,10 @@ bool llama_vocab::get_treat_whitespace_as_suffix() const {
     return pimpl->treat_whitespace_as_suffix;
 }

+enum llama_metaspace_prepend_scheme llama_vocab::get_metaspace_prepend_scheme() const {
+    return pimpl->metaspace_prepend_scheme;
+}
+
 const llama_vocab::normalizer_options & llama_vocab::get_normalizer_opts() const {
     return pimpl->normalizer_opts;
 }
diff --git a/src/llama-vocab.h b/src/llama-vocab.h
index 357ce931e..425a3236c 100644
--- a/src/llama-vocab.h
+++ b/src/llama-vocab.h
@@ -169,6 +169,7 @@ struct llama_vocab {
     bool get_remove_extra_whitespaces  () const;
     bool get_escape_whitespaces        () const;
     bool get_treat_whitespace_as_suffix() const;
+    enum llama_metaspace_prepend_scheme get_metaspace_prepend_scheme() const;
     const normalizer_options & get_normalizer_opts() const;

     const std::vector<llama_token> & get_suppress_tokens() const;