commit b7451f934a438b23655aca77c4596705660512f5 Author: ModelHub XC Date: Sat Aug 1 06:18:14 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: huihui-ai/DeepSeek-R1-Distill-Qwen-1.5B-abliterated Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52373fe --- /dev/null +++ b/.gitattributes @@ -0,0 +1,36 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +tokenizer.json filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..818f1c2 --- /dev/null +++ b/README.md @@ -0,0 +1,144 @@ +--- +base_model: +- deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B +tags: +- text-generation-inference +- transformers +- unsloth +- abliterated +- uncensored +library_name: transformers +--- + +# huihui-ai/DeepSeek-R1-Distill-Qwen-1.5B-abliterated + +This is an uncensored version of [deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B) reasoning model that has been post-trained by huihui-ai. + +Please refer to [SFT with Unsloth](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2.5_(7B)-Alpaca.ipynb#scrollTo=2ejIt2xSNKKp) for the training method. + +This is a test conducted through fine-tuning for ablation to achieve the purpose of being uncensored, and the test results met the expected outcomes. + +## Use with ollama + +You can use [huihui_ai/deepseek-r1-abliterated](https://ollama.com/huihui_ai/deepseek-r1-abliterated) directly +``` +ollama run huihui_ai/deepseek-r1-abliterated:1.5b +``` + +## Use with transformers + +``` +from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer +import torch +import os +import signal + +cpu_count = os.cpu_count() +print(f"Number of CPU cores in the system: {cpu_count}") +half_cpu_count = cpu_count // 2 +os.environ["MKL_NUM_THREADS"] = str(half_cpu_count) +os.environ["OMP_NUM_THREADS"] = str(half_cpu_count) +torch.set_num_threads(half_cpu_count) + +print(f"PyTorch threads: {torch.get_num_threads()}") +print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}") +print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}") + +# Load the model and tokenizer +NEW_MODEL_ID = "huihui-ai/DeepSeek-R1-Distill-Qwen-1.5B-abliterated" +print(f"Load Model {NEW_MODEL_ID} ... ") +quant_config_4 = BitsAndBytesConfig( + load_in_4bit=True, + bnb_4bit_compute_dtype=torch.bfloat16, + bnb_4bit_use_double_quant=True, + llm_int8_enable_fp32_cpu_offload=True, +) + +model = AutoModelForCausalLM.from_pretrained( + NEW_MODEL_ID, + device_map="auto", + trust_remote_code=True, + #quantization_config=quant_config_4, + torch_dtype=torch.bfloat16 +) +tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True) +if tokenizer.pad_token is None: + tokenizer.pad_token = tokenizer.eos_token +tokenizer.pad_token_id = tokenizer.eos_token_id + +initial_messages = [{"role": "system", "content": "You are a helpful assistant."}] +messages = initial_messages.copy() + +class CustomTextStreamer(TextStreamer): + def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True): + super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens) + self.generated_text = "" + self.stop_flag = False + + def on_finalized_text(self, text: str, stream_end: bool = False): + self.generated_text += text + print(text, end="", flush=True) + if self.stop_flag: + raise StopIteration + + def stop_generation(self): + self.stop_flag = True + +def generate_stream(model, tokenizer, messages, max_new_tokens): + input_ids = tokenizer.apply_chat_template( + messages, + tokenize=True, + add_generation_prompt=True, + return_tensors="pt" + ) + attention_mask = torch.ones_like(input_ids, dtype=torch.long) + tokens = input_ids.to(model.device) + attention_mask = attention_mask.to(model.device) + + streamer = CustomTextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True) + + def signal_handler(sig, frame): + streamer.stop_generation() + print("\n[Generation stopped by user with Ctrl+C]") + + signal.signal(signal.SIGINT, signal_handler) + + print("Response: ", end="", flush=True) + try: + generated_ids = model.generate( + tokens, + attention_mask=attention_mask, + use_cache=False, + max_new_tokens=max_new_tokens, + do_sample=True, + pad_token_id=tokenizer.pad_token_id, + streamer=streamer + ) + del generated_ids + except StopIteration: + print("\n[Stopped by user]") + + del input_ids, attention_mask + torch.cuda.empty_cache() + signal.signal(signal.SIGINT, signal.SIG_DFL) + + return streamer.generated_text, streamer.stop_flag + +while True: + user_input = input("\nUser: ").strip() + if user_input.lower() == "/exit": + print("Exiting chat.") + break + if user_input.lower() == "/clear": + messages = initial_messages.copy() + print("Chat history cleared. Starting a new conversation.") + continue + if not user_input: + print("Input cannot be empty. Please enter something.") + continue + messages.append({"role": "user", "content": user_input}) + response, stop_flag = generate_stream(model, tokenizer, messages, 8192) + if stop_flag: + continue + messages.append({"role": "assistant", "content": response}) +``` diff --git a/config.json b/config.json new file mode 100644 index 0000000..c24d0e3 --- /dev/null +++ b/config.json @@ -0,0 +1,31 @@ +{ + "architectures": [ + "Qwen2ForCausalLM" + ], + "attention_dropout": 0.0, + "bos_token_id": 151643, + "eos_token_id": 151643, + "hidden_act": "silu", + "hidden_size": 1536, + "initializer_range": 0.02, + "intermediate_size": 8960, + "max_position_embeddings": 131072, + "max_window_layers": 21, + "model_type": "qwen2", + "num_attention_heads": 12, + "num_hidden_layers": 28, + "num_key_value_heads": 2, + "pad_token_id": 151654, + "rms_norm_eps": 1e-06, + "rope_scaling": null, + "rope_theta": 10000, + "sliding_window": 4096, + "tie_word_embeddings": false, + "torch_dtype": "bfloat16", + "transformers_version": "4.51.1", + "unsloth_version": "2025.3.19", + "use_cache": true, + "use_mrope": false, + "use_sliding_window": false, + "vocab_size": 151936 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..9319afa --- /dev/null +++ b/generation_config.json @@ -0,0 +1,11 @@ +{ + "_from_model_config": true, + "bos_token_id": 151646, + "do_sample": true, + "eos_token_id": 151643, + "max_length": 131072, + "pad_token_id": 151654, + "temperature": 0.6, + "top_p": 0.95, + "transformers_version": "4.51.1" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..3ef63f7 --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d464b76b5acb42925d37ffd8f46f71af9163505587f2a85ff100b8697e5fa599 +size 3554214752 diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..4f9f39e --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,17 @@ +{ + "bos_token": { + "content": "<|begin▁of▁sentence|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "eos_token": { + "content": "<|end▁of▁sentence|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "pad_token": "<|vision_pad|>" +} diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..1a2db24 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e20ddafc659ba90242154b55275402edeca0715e5dbb30f56815a4ce081f4893 +size 11422778 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..a235418 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,196 @@ +{ + "add_bos_token": true, + "add_eos_token": false, + "add_prefix_space": null, + "added_tokens_decoder": { + "151643": { + "content": "<|end▁of▁sentence|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151644": { + "content": "<|User|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151645": { + "content": "<|Assistant|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151646": { + "content": "<|begin▁of▁sentence|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151647": { + "content": "<|EOT|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151648": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151649": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151650": { + "content": "<|quad_start|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151651": { + "content": "<|quad_end|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151652": { + "content": "<|vision_start|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151653": { + "content": "<|vision_end|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151654": { + "content": "<|vision_pad|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151655": { + "content": "<|image_pad|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151656": { + "content": "<|video_pad|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": true + }, + "151657": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151658": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151659": { + "content": "<|fim_prefix|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151660": { + "content": "<|fim_middle|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151661": { + "content": "<|fim_suffix|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151662": { + "content": "<|fim_pad|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151663": { + "content": "<|repo_name|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + }, + "151664": { + "content": "<|file_sep|>", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false, + "special": false + } + }, + "bos_token": "<|begin▁of▁sentence|>", + "chat_template": "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='') %}{%- for message in messages %}{%- if message['role'] == 'system' %}{% set ns.system_prompt = message['content'] %}{%- endif %}{%- endfor %}{{bos_token}}{{ns.system_prompt}}{%- for message in messages %}{%- if message['role'] == 'user' %}{%- set ns.is_tool = false -%}{{'<|User|>' + message['content']}}{%- endif %}{%- if message['role'] == 'assistant' and message['content'] is none %}{%- set ns.is_tool = false -%}{%- for tool in message['tool_calls']%}{%- if not ns.is_first %}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- set ns.is_first = true -%}{%- else %}{{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- endfor %}{%- endif %}{%- if message['role'] == 'assistant' and message['content'] is not none %}{%- if ns.is_tool %}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{% set content = message['content'] %}{% if '' in content %}{% set content = content.split('')[-1] %}{% endif %}{{'<|Assistant|>' + content + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_tool = true -%}{%- if ns.is_output_first %}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- set ns.is_output_first = false %}{%- else %}{{'\\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'<|tool▁outputs▁end|>'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'<|Assistant|>\\n'}}{% endif %}", + "clean_up_tokenization_spaces": false, + "eos_token": "<|end▁of▁sentence|>", + "extra_special_tokens": {}, + "legacy": true, + "model_max_length": 131072, + "pad_token": "<|vision_pad|>", + "padding_side": "left", + "sp_model_kwargs": {}, + "tokenizer_class": "LlamaTokenizerFast", + "unk_token": null, + "use_default_system_prompt": false +}