From 2a9498d5df6319fc294752f4574c0a23727c84c4 Mon Sep 17 00:00:00 2001 From: jeromeku Date: Mon, 31 Mar 2025 11:23:22 -0700 Subject: [PATCH] add deepseek v3 --- unsloth/registry/_deepseek.py | 53 +++++++++++++++++++++++++++++++++++ unsloth/registry/registry.py | 3 ++ 2 files changed, 56 insertions(+) create mode 100644 unsloth/registry/_deepseek.py diff --git a/unsloth/registry/_deepseek.py b/unsloth/registry/_deepseek.py new file mode 100644 index 0000000000..8bdcd3c2e7 --- /dev/null +++ b/unsloth/registry/_deepseek.py @@ -0,0 +1,53 @@ +from unsloth.registry.registry import ModelInfo, ModelMeta, QuantType, _register_models + +_IS_DEEPSEEKV3_REGISTERED = False + +class DeepseekV3ModelInfo(ModelInfo): + @classmethod + def construct_model_name(cls, base_name, version, size, quant_type, instruct_tag): + key = f"{base_name}-V{version}" + key = cls.append_instruct_tag(key, instruct_tag) + key = cls.append_quant_type(key, quant_type) + return key + +# Deepseek V3 Model Meta +DeepseekV3Meta = ModelMeta( + org="deepseek-ai", + base_name="DeepSeek", + instruct_tags=[None], + model_version="3", + model_sizes=[""], + model_info_cls=DeepseekV3ModelInfo, + is_multimodal=False, + quant_types=[QuantType.NONE, QuantType.BF16], +) + +DeepseekV3_0324Meta = ModelMeta( + org="deepseek-ai", + base_name="DeepSeek", + instruct_tags=[None], + model_version="3-0324", + model_sizes=[""], + model_info_cls=DeepseekV3ModelInfo, + is_multimodal=False, + quant_types=[QuantType.NONE, QuantType.GGUF], +) + +def register_deepseek_v3_models(include_original_model: bool = False): + global _IS_DEEPSEEKV3_REGISTERED + if _IS_DEEPSEEKV3_REGISTERED: + return + _register_models(DeepseekV3Meta, include_original_model=include_original_model) + _register_models(DeepseekV3_0324Meta, include_original_model=include_original_model) + _IS_DEEPSEEKV3_REGISTERED = True + +register_deepseek_v3_models(include_original_model=True) + +if __name__ == "__main__": + from unsloth.registry.registry import MODEL_REGISTRY, _check_model_info + for model_id, model_info in MODEL_REGISTRY.items(): + model_info = _check_model_info(model_id) + if model_info is None: + print(f"\u2718 {model_id}") + else: + print(f"\u2713 {model_id}") diff --git a/unsloth/registry/registry.py b/unsloth/registry/registry.py index 869a7efb5d..1eee884259 100644 --- a/unsloth/registry/registry.py +++ b/unsloth/registry/registry.py @@ -8,17 +8,20 @@ class QuantType(Enum): UNSLOTH = "unsloth" # dynamic 4-bit quantization GGUF = "GGUF" NONE = "none" + BF16 = "bf16" # only for Deepseek V3 # Tags for Hugging Face model paths BNB_QUANTIZED_TAG = "bnb-4bit" UNSLOTH_DYNAMIC_QUANT_TAG = "unsloth" + "-" + BNB_QUANTIZED_TAG GGUF_TAG = "GGUF" +BF16_TAG = "bf16" QUANT_TAG_MAP = { QuantType.BNB: BNB_QUANTIZED_TAG, QuantType.UNSLOTH: UNSLOTH_DYNAMIC_QUANT_TAG, QuantType.GGUF: GGUF_TAG, QuantType.NONE: None, + QuantType.BF16: BF16_TAG, } # NOTE: models registered with org="unsloth" and QUANT_TYPE.NONE are aliases of QUANT_TYPE.UNSLOTH