@@ -669,6 +669,36 @@ def get_vocab_base_pre(self, tokenizer) -> str:
669
669
# NOTE: if you get an error here, you need to update the convert_hf_to_gguf_update.py script
670
670
# or pull the latest version of the model from Huggingface
671
671
# don't edit the hashes manually!
672
+ if chkhsh == "b6e8e1518dc4305be2fe39c313ed643381c4da5db34a98f6a04c093f8afbe99b" :
673
+ # ref: https://huggingface.co/THUDM/glm-4-9b-chat
674
+ res = "chatglm-bpe"
675
+ if chkhsh == "81d72c7348a9f0ebe86f23298d37debe0a5e71149e29bd283904c02262b27516" :
676
+ # ref: https://huggingface.co/THUDM/glm-4-9b-chat
677
+ res = "chatglm-bpe"
678
+ if chkhsh == "a1336059768a55c99a734006ffb02203cd450fed003e9a71886c88acf24fdbc2" :
679
+ # ref: https://huggingface.co/THUDM/glm-4-9b-hf
680
+ res = "glm4"
681
+ if chkhsh == "1431a23e583c97432bc230bff598d103ddb5a1f89960c8f1d1051aaa944d0b35" :
682
+ # ref: https://huggingface.co/sapienzanlp/Minerva-7B-base-v1.0
683
+ res = "minerva-7b"
684
+ if chkhsh == "7e57df22b1fe23a7b1e1c7f3dc4e3f96d43a4eb0836d0c6bdc3436d7b2f1c664" :
685
+ # ref: https://huggingface.co/tencent/Hunyuan-A13B-Instruct
686
+ res = "hunyuan"
687
+ if chkhsh == "a6b57017d60e6edb4d88ecc2845188e0eb333a70357e45dcc9b53964a73bbae6" :
688
+ # ref: https://huggingface.co/tiiuae/Falcon-H1-0.5B-Base
689
+ res = "falcon-h1"
690
+ if chkhsh == "60476e1243776c4fb1b993dbd7a5f15ac22f83c80afdf425fa5ae01c8d44ef86" :
691
+ # ref: https://huggingface.co/tiiuae/Falcon-H1-1B-Base
692
+ res = "falcon-h1"
693
+ if chkhsh == "3eda48b4c4dc7de733d1a8b3e3b4a85243dbbf704da2ee9d42c6beced8897896" :
694
+ # ref: https://huggingface.co/tiiuae/Falcon-H1-7B-Base
695
+ res = "falcon-h1"
696
+ if chkhsh == "48f8e02c0359c0bbdd82f26909171fac1c18a457bb47573ed1fe3bbb2c1cfd4b" :
697
+ # ref: https://huggingface.co/tiiuae/Falcon-H1-34B-Base
698
+ res = "falcon-h1"
699
+ if chkhsh == "81212dc7cdb7e0c1074ca62c5aeab0d43c9f52b8a737be7b12a777c953027890" :
700
+ # ref: https://huggingface.co/moonshotai/Kimi-K2-Base
701
+ res = "kimi-k2"
672
702
if chkhsh == "0ef9807a4087ebef797fc749390439009c3b9eda9ad1a097abbe738f486c01e5" :
673
703
# ref: https://huggingface.co/meta-llama/Meta-Llama-3-8B
674
704
res = "llama-bpe"
@@ -804,45 +834,15 @@ def get_vocab_base_pre(self, tokenizer) -> str:
804
834
if chkhsh == "d5f1dd6f980fec569fb218a81a7658ac45fc56b38c5a0adeb1c232fbe04ef5ec" :
805
835
# ref: https://huggingface.co/ByteDance-Seed/Seed-Coder-8B-Base
806
836
res = "seed-coder"
807
- if chkhsh == "b6e8e1518dc4305be2fe39c313ed643381c4da5db34a98f6a04c093f8afbe99b" :
808
- # ref: https://huggingface.co/THUDM/glm-4-9b-chat
809
- res = "chatglm-bpe"
810
- if chkhsh == "81d72c7348a9f0ebe86f23298d37debe0a5e71149e29bd283904c02262b27516" :
811
- # ref: https://huggingface.co/THUDM/glm-4-9b-chat
812
- res = "chatglm-bpe"
813
- if chkhsh == "a1336059768a55c99a734006ffb02203cd450fed003e9a71886c88acf24fdbc2" :
814
- # ref: https://huggingface.co/THUDM/glm-4-9b-hf
815
- res = "glm4"
816
- if chkhsh == "1431a23e583c97432bc230bff598d103ddb5a1f89960c8f1d1051aaa944d0b35" :
817
- # ref: https://huggingface.co/sapienzanlp/Minerva-7B-base-v1.0
818
- res = "minerva-7b"
819
- if chkhsh == "7e57df22b1fe23a7b1e1c7f3dc4e3f96d43a4eb0836d0c6bdc3436d7b2f1c664" :
820
- # ref: https://huggingface.co/tencent/Hunyuan-A13B-Instruct
821
- res = "hunyuan"
822
837
if chkhsh == "b0a6b1c0bd5998ebd9df08611efde34a4ff03faed45ae09c43e6b31ebd4b94cf" :
823
838
# ref: https://huggingface.co/skt/A.X-4.0
824
839
res = "a.x-4.0"
825
- if chkhsh == "a6b57017d60e6edb4d88ecc2845188e0eb333a70357e45dcc9b53964a73bbae6" :
826
- # ref: https://huggingface.co/tiiuae/Falcon-H1-0.5B-Base
827
- res = "falcon-h1"
828
- if chkhsh == "60476e1243776c4fb1b993dbd7a5f15ac22f83c80afdf425fa5ae01c8d44ef86" :
829
- # ref: https://huggingface.co/tiiuae/Falcon-H1-1B-Base
830
- res = "falcon-h1"
831
- if chkhsh == "3eda48b4c4dc7de733d1a8b3e3b4a85243dbbf704da2ee9d42c6beced8897896" :
832
- # ref: https://huggingface.co/tiiuae/Falcon-H1-7B-Base
833
- res = "falcon-h1"
834
- if chkhsh == "48f8e02c0359c0bbdd82f26909171fac1c18a457bb47573ed1fe3bbb2c1cfd4b" :
835
- # ref: https://huggingface.co/tiiuae/Falcon-H1-34B-Base
836
- res = "falcon-h1"
837
840
if chkhsh == "f6791d196f87ce6b56a7d234be618e0d58f8cda3549416635b2bebcd22cd95c4" :
838
841
# ref: https://huggingface.co/K-intelligence/Midm-2.0-Base-Instruct
839
842
res = "midm-2.0"
840
843
if chkhsh == "169bf0296a13c4d9b7672313f749eb36501d931022de052aad6e36f2bf34dd51" :
841
844
# ref: https://huggingface.co/LiquidAI/LFM2-Tokenizer
842
845
res = "lfm2"
843
- if chkhsh == "81212dc7cdb7e0c1074ca62c5aeab0d43c9f52b8a737be7b12a777c953027890" :
844
- # ref: https://huggingface.co/moonshotai/Kimi-K2-Base
845
- res = "kimi-k2"
846
846
847
847
if res is None :
848
848
logger .warning ("\n " )
@@ -2778,6 +2778,76 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
2778
2778
yield from super ().modify_tensors (data_torch , name , bid )
2779
2779
2780
2780
2781
+ @ModelBase .register ("DreamModel" )
2782
+ class DreamModel (TextModel ):
2783
+ model_arch = gguf .MODEL_ARCH .DREAM
2784
+
2785
+ def get_vocab_base (self ) -> tuple [list [str ], list [int ], str ]:
2786
+ tokens : list [str ] = []
2787
+ toktypes : list [int ] = []
2788
+
2789
+ from transformers import AutoTokenizer
2790
+ tokenizer = AutoTokenizer .from_pretrained (self .dir_model , trust_remote_code = True )
2791
+
2792
+ vocab_dict = tokenizer .get_vocab ()
2793
+ vocab_size = self .hparams .get ("vocab_size" , len (vocab_dict ))
2794
+ assert max (vocab_dict .values ()) < vocab_size
2795
+
2796
+ tokpre = self .get_vocab_base_pre (tokenizer )
2797
+
2798
+ reverse_vocab = {id_ : encoded_tok for encoded_tok , id_ in vocab_dict .items ()}
2799
+ added_vocab = tokenizer .get_added_vocab ()
2800
+
2801
+ for i in range (vocab_size ):
2802
+ if i not in reverse_vocab :
2803
+ tokens .append (f"[PAD{ i } ]" )
2804
+ toktypes .append (gguf .TokenType .UNUSED )
2805
+ elif reverse_vocab [i ] in added_vocab :
2806
+ tokens .append (reverse_vocab [i ])
2807
+ # Check if it's a special token - treat special tokens as CONTROL tokens
2808
+ if hasattr (tokenizer , 'added_tokens_decoder' ) and i in tokenizer .added_tokens_decoder :
2809
+ if tokenizer .added_tokens_decoder [i ].special :
2810
+ toktypes .append (gguf .TokenType .CONTROL )
2811
+ else :
2812
+ toktypes .append (gguf .TokenType .USER_DEFINED )
2813
+ else :
2814
+ # Fallback: treat all added vocab as control tokens for special tokens like <|im_start|>
2815
+ toktypes .append (gguf .TokenType .CONTROL )
2816
+ else :
2817
+ tokens .append (reverse_vocab [i ])
2818
+ toktypes .append (gguf .TokenType .NORMAL )
2819
+
2820
+ return tokens , toktypes , tokpre
2821
+
2822
+ def set_vocab (self ):
2823
+ try :
2824
+ self ._set_vocab_sentencepiece ()
2825
+ except FileNotFoundError :
2826
+ self ._set_vocab_gpt2 ()
2827
+
2828
+ def set_gguf_parameters (self ):
2829
+ super ().set_gguf_parameters ()
2830
+ self ._try_set_pooling_type ()
2831
+
2832
+ # Dream models use non-causal attention for diffusion
2833
+ self .gguf_writer .add_causal_attention (False )
2834
+ # Handle RoPE scaling similar to Qwen2
2835
+ rope_scaling = self .hparams .get ("rope_scaling" ) or {}
2836
+ if rope_scaling .get ("rope_type" , rope_scaling .get ("type" )) == "yarn" and "factor" in rope_scaling :
2837
+ self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .YARN )
2838
+ self .gguf_writer .add_rope_scaling_factor (rope_scaling ["factor" ])
2839
+ self .gguf_writer .add_rope_scaling_orig_ctx_len (rope_scaling ["original_max_position_embeddings" ])
2840
+
2841
+ # Add Dream-specific parameters
2842
+ mask_token_id = self .hparams .get ("mask_token_id" )
2843
+ if mask_token_id is not None :
2844
+ self .gguf_writer .add_mask_token_id (mask_token_id )
2845
+
2846
+ def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
2847
+ # Dream model tensors should be mapped directly since it's the base model
2848
+ yield from super ().modify_tensors (data_torch , name , bid )
2849
+
2850
+
2781
2851
@ModelBase .register ("Ernie4_5_ForCausalLM" )
2782
2852
class Ernie4_5Model (TextModel ):
2783
2853
model_arch = gguf .MODEL_ARCH .ERNIE4_5
0 commit comments