ArtusDev commited on
Commit
99c7e0a
·
verified ·
1 Parent(s): 018d292

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ quantization_config.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ license_link: https://huggingface.co/Qwen/Qwen3-30B-A3B/blob/main/LICENSE
5
+ pipeline_tag: text-generation
6
+ base_model:
7
+ - Qwen/Qwen3-30B-A3B
8
+ tags:
9
+ - chat
10
+ - abliterated
11
+ - uncensored
12
+ extra_gated_prompt: >-
13
+ **Usage Warnings**
14
+
15
+
16
+ “**Risk of Sensitive or Controversial Outputs**“: This model’s safety filtering has been significantly reduced, potentially generating sensitive, controversial, or inappropriate content. Users should exercise caution and rigorously review generated outputs.
17
+
18
+ “**Not Suitable for All Audiences**:“ Due to limited content filtering, the model’s outputs may be inappropriate for public settings, underage users, or applications requiring high security.
19
+
20
+ “**Legal and Ethical Responsibilities**“: Users must ensure their usage complies with local laws and ethical standards. Generated content may carry legal or ethical risks, and users are solely responsible for any consequences.
21
+
22
+ “**Research and Experimental Use**“: It is recommended to use this model for research, testing, or controlled environments, avoiding direct use in production or public-facing commercial applications.
23
+
24
+ “**Monitoring and Review Recommendations**“: Users are strongly advised to monitor model outputs in real-time and conduct manual reviews when necessary to prevent the dissemination of inappropriate content.
25
+
26
+ “**No Default Safety Guarantees**“: Unlike standard models, this model has not undergone rigorous safety optimization. huihui.ai bears no responsibility for any consequences arising from its use.
27
+
28
+
29
+ ---
30
+
31
+ # huihui-ai/Qwen3-30B-A3B-abliterated
32
+
33
+
34
+ This is an uncensored version of [Qwen/Qwen3-30B-A3B](https://huggingface.co/Qwen/Qwen3-30B-A3B) created with abliteration (see [remove-refusals-with-transformers](https://github.com/Sumandora/remove-refusals-with-transformers) to know more about it).
35
+ This is a crude, proof-of-concept implementation to remove refusals from an LLM model without using TransformerLens.
36
+
37
+ ## ollama
38
+
39
+ You can use [huihui_ai/qwen3-abliterated:30b](https://ollama.com/huihui_ai/qwen3-abliterated:30b) directly,
40
+ ```
41
+ ollama run huihui_ai/qwen3-abliterated:30b
42
+ ```
43
+
44
+ ## Usage
45
+ You can use this model in your applications by loading it with Hugging Face's `transformers` library:
46
+ You can try using **/no_think** to toggle think mode, but it’s not guaranteed to work every time.
47
+
48
+
49
+ ```python
50
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer
51
+ import torch
52
+ import os
53
+ import signal
54
+
55
+ cpu_count = os.cpu_count()
56
+ print(f"Number of CPU cores in the system: {cpu_count}")
57
+ half_cpu_count = cpu_count // 2
58
+ os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
59
+ os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
60
+ torch.set_num_threads(half_cpu_count)
61
+
62
+ print(f"PyTorch threads: {torch.get_num_threads()}")
63
+ print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
64
+ print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")
65
+
66
+ # Load the model and tokenizer
67
+ NEW_MODEL_ID = "huihui-ai/Qwen3-30B-A3B-abliterated"
68
+ print(f"Load Model {NEW_MODEL_ID} ... ")
69
+ quant_config_4 = BitsAndBytesConfig(
70
+ load_in_4bit=True,
71
+ bnb_4bit_compute_dtype=torch.bfloat16,
72
+ bnb_4bit_use_double_quant=True,
73
+ llm_int14_enable_fp32_cpu_offload=True,
74
+ )
75
+
76
+ model = AutoModelForCausalLM.from_pretrained(
77
+ NEW_MODEL_ID,
78
+ device_map="auto",
79
+ trust_remote_code=True,
80
+ #quantization_config=quant_config_4,
81
+ torch_dtype=torch.bfloat16
82
+ )
83
+ tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True)
84
+ if tokenizer.pad_token is None:
85
+ tokenizer.pad_token = tokenizer.eos_token
86
+ tokenizer.pad_token_id = tokenizer.eos_token_id
87
+
88
+ messages = []
89
+ enable_thinking = True
90
+ skip_prompt=True
91
+ skip_special_tokens=True
92
+
93
+ def apply_chat_template(tokenizer, messages, enable_thinking, add_generation_prompt=True):
94
+ input_ids = tokenizer.apply_chat_template(
95
+ messages,
96
+ tokenize=False,
97
+ add_generation_prompt=add_generation_prompt,
98
+ )
99
+ if not enable_thinking:
100
+ input_ids += "\n<think>\n\n</think>\n"
101
+ return input_ids
102
+
103
+ class CustomTextStreamer(TextStreamer):
104
+ def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
105
+ super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
106
+ self.generated_text = ""
107
+ self.stop_flag = False
108
+
109
+ def on_finalized_text(self, text: str, stream_end: bool = False):
110
+ self.generated_text += text
111
+ print(text, end="", flush=True)
112
+ if self.stop_flag:
113
+ raise StopIteration
114
+
115
+ def stop_generation(self):
116
+ self.stop_flag = True
117
+
118
+ def generate_stream(model, tokenizer, messages, enable_thinking, skip_prompt, skip_special_tokens, max_new_tokens):
119
+ formatted_prompt = apply_chat_template(tokenizer, messages, enable_thinking)
120
+ input_ids = tokenizer(
121
+ formatted_prompt,
122
+ return_tensors="pt",
123
+ return_attention_mask=True,
124
+ padding=False
125
+ )
126
+
127
+ tokens = input_ids['input_ids'].to(model.device)
128
+ attention_mask = input_ids['attention_mask'].to(model.device)
129
+
130
+ streamer = CustomTextStreamer(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
131
+
132
+ def signal_handler(sig, frame):
133
+ streamer.stop_generation()
134
+ print("\n[Generation stopped by user with Ctrl+C]")
135
+
136
+ signal.signal(signal.SIGINT, signal_handler)
137
+
138
+ print("Response: ", end="", flush=True)
139
+ try:
140
+ generated_ids = model.generate(
141
+ tokens,
142
+ attention_mask=attention_mask,
143
+ use_cache=False,
144
+ max_new_tokens=max_new_tokens,
145
+ do_sample=True,
146
+ pad_token_id=tokenizer.pad_token_id,
147
+ streamer=streamer
148
+ )
149
+ del generated_ids
150
+ except StopIteration:
151
+ print("\n[Stopped by user]")
152
+
153
+ del input_ids, attention_mask
154
+ torch.cuda.empty_cache()
155
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
156
+
157
+ return streamer.generated_text, streamer.stop_flag
158
+
159
+ while True:
160
+ user_input = input("User: ").strip()
161
+ if user_input.lower() == "/exit":
162
+ print("Exiting chat.")
163
+ break
164
+ if user_input.lower() == "/clear":
165
+ messages = []
166
+ print("Chat history cleared. Starting a new conversation.")
167
+ continue
168
+ if user_input.lower() == "/no_think":
169
+ if enable_thinking:
170
+ enable_thinking = False
171
+ print("Thinking = False.")
172
+ else:
173
+ enable_thinking = True
174
+ print("Thinking = True.")
175
+ continue
176
+ if user_input.lower() == "/skip_prompt":
177
+ if skip_prompt:
178
+ skip_prompt = False
179
+ print("skip_prompt = False.")
180
+ else:
181
+ skip_prompt = True
182
+ print("skip_prompt = True.")
183
+ continue
184
+ if user_input.lower() == "/skip_special_tokens":
185
+ if skip_special_tokens:
186
+ skip_special_tokens = False
187
+ print("skip_special_tokens = False.")
188
+ else:
189
+ skip_special_tokens = True
190
+ print("skip_special_tokens = True.")
191
+ continue
192
+ if not user_input:
193
+ print("Input cannot be empty. Please enter something.")
194
+ continue
195
+ messages.append({"role": "user", "content": user_input})
196
+ response, stop_flag = generate_stream(model, tokenizer, messages, enable_thinking, skip_prompt, skip_special_tokens, 14192)
197
+ print("", flush=True)
198
+ if stop_flag:
199
+ continue
200
+ messages.append({"role": "assistant", "content": response})
201
+ ```
202
+
203
+ ## Specific usage
204
+ You can achieve better results using AblationDecoderLayer. For specific usage, please refer to the file [load-Qwen3-30B-A3B-abliterated.py](https://huggingface.co/huihui-ai/Qwen3-30B-A3B-abliterated/blob/main/load-Qwen3-30B-A3B-abliterated.py).
205
+
206
+ The candidate layers can be 16(final_refusal_dir.pt).
207
+ You can try using **/no_think** to toggle think mode.
208
+
209
+
210
+ ### Donation
211
+
212
+ If you like it, please click 'like' and follow us for more updates.
213
+ You can follow [x.com/support_huihui](https://x.com/support_huihui) to get the latest model information from huihui.ai.
214
+
215
+ ##### Your donation helps us continue our further development and improvement, a cup of coffee can do it.
216
+ - bitcoin(BTC):
217
+ ```
218
+ bc1qqnkhuchxw0zqjh2ku3lu14hq145hc6gy1414uk70ge
219
+ ```
added_tokens.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 151668,
3
+ "</tool_call>": 151658,
4
+ "</tool_response>": 151666,
5
+ "<think>": 151667,
6
+ "<tool_call>": 151657,
7
+ "<tool_response>": 151665,
8
+ "<|box_end|>": 151649,
9
+ "<|box_start|>": 151648,
10
+ "<|endoftext|>": 151643,
11
+ "<|file_sep|>": 151664,
12
+ "<|fim_middle|>": 151660,
13
+ "<|fim_pad|>": 151662,
14
+ "<|fim_prefix|>": 151659,
15
+ "<|fim_suffix|>": 151661,
16
+ "<|im_end|>": 151645,
17
+ "<|im_start|>": 151644,
18
+ "<|image_pad|>": 151655,
19
+ "<|object_ref_end|>": 151647,
20
+ "<|object_ref_start|>": 151646,
21
+ "<|quad_end|>": 151651,
22
+ "<|quad_start|>": 151650,
23
+ "<|repo_name|>": 151663,
24
+ "<|video_pad|>": 151656,
25
+ "<|vision_end|>": 151653,
26
+ "<|vision_pad|>": 151654,
27
+ "<|vision_start|>": 151652
28
+ }
config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3MoeForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "decoder_sparse_step": 1,
9
+ "eos_token_id": 151645,
10
+ "head_dim": 128,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 2048,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 6144,
15
+ "max_position_embeddings": 40960,
16
+ "max_window_layers": 48,
17
+ "mlp_only_layers": [],
18
+ "model_type": "qwen3_moe",
19
+ "moe_intermediate_size": 768,
20
+ "norm_topk_prob": true,
21
+ "num_attention_heads": 32,
22
+ "num_experts": 128,
23
+ "num_experts_per_tok": 8,
24
+ "num_hidden_layers": 48,
25
+ "num_key_value_heads": 4,
26
+ "output_router_logits": false,
27
+ "rms_norm_eps": 1e-06,
28
+ "rope_scaling": null,
29
+ "rope_theta": 1000000.0,
30
+ "router_aux_loss_coef": 0.001,
31
+ "sliding_window": null,
32
+ "tie_word_embeddings": false,
33
+ "torch_dtype": "bfloat16",
34
+ "transformers_version": "4.51.3",
35
+ "use_cache": true,
36
+ "use_sliding_window": false,
37
+ "vocab_size": 151936,
38
+ "quantization_config": {
39
+ "quant_method": "exl3",
40
+ "version": "0.0.2",
41
+ "bits": 4.0,
42
+ "head_bits": 8,
43
+ "calibration": {
44
+ "rows": 100,
45
+ "cols": 2048
46
+ },
47
+ "out_scales": "auto"
48
+ }
49
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.6,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "4.51.3"
13
+ }
gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
load-Qwen3-30B-A3B-abliterated.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer
2
+ import torch
3
+ import torch.nn as nn
4
+ import os
5
+ import signal
6
+ from typing import Optional, Tuple
7
+ import einops
8
+ import jaxtyping
9
+
10
+ cpu_count = os.cpu_count()
11
+ print(f"Number of CPU cores in the system: {cpu_count}")
12
+ half_cpu_count = cpu_count // 2
13
+ os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
14
+ os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
15
+ torch.set_num_threads(half_cpu_count)
16
+
17
+ print(f"PyTorch threads: {torch.get_num_threads()}")
18
+ print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
19
+ print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")
20
+
21
+ # Load the model and tokenizer
22
+ MODEL_ID = "Qwen/Qwen3-30B-A3B"
23
+ print(f"Load Model {MODEL_ID} ... ")
24
+ quant_config_4 = BitsAndBytesConfig(
25
+ load_in_4bit=True,
26
+ bnb_4bit_compute_dtype=torch.bfloat16,
27
+ bnb_4bit_use_double_quant=True,
28
+ llm_int8_enable_fp32_cpu_offload=True,
29
+ )
30
+
31
+ model = AutoModelForCausalLM.from_pretrained(
32
+ MODEL_ID,
33
+ device_map="auto",
34
+ trust_remote_code=True,
35
+ quantization_config=quant_config_4,
36
+ torch_dtype=torch.bfloat16
37
+ )
38
+
39
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
40
+ if tokenizer.pad_token is None:
41
+ tokenizer.pad_token = tokenizer.eos_token
42
+ tokenizer.pad_token_id = tokenizer.eos_token_id
43
+
44
+ messages = []
45
+ enable_thinking = True
46
+ skip_prompt=True
47
+ skip_special_tokens=True
48
+
49
+ def direction_ablation_hook(activation: jaxtyping.Float[torch.Tensor, "... d_act"],
50
+ direction: jaxtyping.Float[torch.Tensor, "d_act"]):
51
+ proj = einops.einsum(activation, direction.view(-1, 1), '... d_act, d_act single -> ... single') * direction
52
+ return activation - proj
53
+
54
+ class AblationDecoderLayer(nn.Module):
55
+ def __init__(self, original_layer, refusal_dir):
56
+ super(AblationDecoderLayer, self).__init__()
57
+ self.original_layer = original_layer
58
+ self.refusal_dir = refusal_dir
59
+
60
+ def forward(self, *args, **kwargs):
61
+ hidden_states = args[0]
62
+ ablated = direction_ablation_hook(hidden_states, self.refusal_dir.to(hidden_states.device)).to(hidden_states.device)
63
+ args = (ablated,) + args[1:]
64
+ return self.original_layer.forward(*args, **kwargs)
65
+
66
+ class CustomTextStreamer(TextStreamer):
67
+ def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
68
+ super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
69
+ self.generated_text = ""
70
+ self.stop_flag = False
71
+
72
+ def on_finalized_text(self, text: str, stream_end: bool = False):
73
+ self.generated_text += text
74
+ print(text, end="", flush=True)
75
+ if self.stop_flag:
76
+ raise StopIteration
77
+
78
+ def stop_generation(self):
79
+ self.stop_flag = True
80
+
81
+ def generate_stream(model, tokenizer, messages, enable_thinking, skip_prompt, skip_special_tokens, max_new_tokens):
82
+ input_ids = tokenizer.apply_chat_template(
83
+ messages,
84
+ tokenize=True,
85
+ enable_thinking = enable_thinking,
86
+ add_generation_prompt=True,
87
+ return_tensors="pt"
88
+ )
89
+ attention_mask = torch.ones_like(input_ids, dtype=torch.long)
90
+ tokens = input_ids.to(model.device)
91
+ attention_mask = attention_mask.to(model.device)
92
+
93
+ streamer = CustomTextStreamer(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
94
+
95
+ def signal_handler(sig, frame):
96
+ streamer.stop_generation()
97
+ print("\n[Generation stopped by user with Ctrl+C]")
98
+
99
+ signal.signal(signal.SIGINT, signal_handler)
100
+
101
+ print("Response: ", end="", flush=True)
102
+ try:
103
+ generated_ids = model.generate(
104
+ tokens,
105
+ attention_mask=attention_mask,
106
+ use_cache=False,
107
+ max_new_tokens=max_new_tokens,
108
+ do_sample=True,
109
+ pad_token_id=tokenizer.pad_token_id,
110
+ streamer=streamer
111
+ )
112
+ del generated_ids
113
+ except StopIteration:
114
+ print("\n[Stopped by user]")
115
+
116
+ del input_ids, attention_mask
117
+ torch.cuda.empty_cache()
118
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
119
+
120
+ return streamer.generated_text, streamer.stop_flag
121
+
122
+
123
+
124
+ final_refusal_dirs= torch.load(MODEL_ID + "/final_refusal_dirs.pt", map_location='cpu', weights_only=True)
125
+ # candidate layer, 16, 21 ...
126
+ candidate_layer = 16
127
+
128
+ refusal_dir = final_refusal_dirs[candidate_layer]
129
+
130
+ for idx in range(len(model.model.layers)):
131
+ model.model.layers[idx] = AblationDecoderLayer(model.model.layers[idx], refusal_dir)
132
+
133
+ while True:
134
+ user_input = input("User: ").strip()
135
+ if user_input.lower() == "/exit":
136
+ print("Exiting chat.")
137
+ break
138
+ if user_input.lower() == "/clear":
139
+ messages = []
140
+ print("Chat history cleared. Starting a new conversation.")
141
+ continue
142
+ if user_input.lower() == "/no_think":
143
+ if enable_thinking:
144
+ enable_thinking = False
145
+ print("Thinking = False.")
146
+ else:
147
+ enable_thinking = True
148
+ print("Thinking = True.")
149
+ continue
150
+ if user_input.lower() == "/skip_prompt":
151
+ if skip_prompt:
152
+ skip_prompt = False
153
+ print("skip_prompt = False.")
154
+ else:
155
+ skip_prompt = True
156
+ print("skip_prompt = True.")
157
+ continue
158
+ if user_input.lower() == "/skip_special_tokens":
159
+ if skip_special_tokens:
160
+ skip_special_tokens = False
161
+ print("skip_special_tokens = False.")
162
+ else:
163
+ skip_special_tokens = True
164
+ print("skip_special_tokens = True.")
165
+ continue
166
+ if not user_input:
167
+ print("Input cannot be empty. Please enter something.")
168
+ continue
169
+ messages.append({"role": "user", "content": user_input})
170
+ response, stop_flag = generate_stream(model, tokenizer, messages, enable_thinking, skip_prompt, skip_special_tokens, 8192)
171
+ print("", flush=True)
172
+ if stop_flag:
173
+ continue
174
+ messages.append({"role": "assistant", "content": response})
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c30dab1216e517b9195ba159b2a5270d9e6b0b75b772eb90435d167d6909f0b7
3
+ size 8479696528
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3880ca2fbaf8c036edde7e9e1ebf7c7f6c6b5c9bb9c6c5693ca07b6532be7232
3
+ size 7540222304
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
quantization_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da44d3c511b4e8698e8fbaf8ef8f232178193f972b31bf4abe52fd697abe29e0
3
+ size 18426475
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
3
+ size 11422654
tokenizer_config.json ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ }
213
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|vision_start|>",
224
+ "<|vision_end|>",
225
+ "<|vision_pad|>",
226
+ "<|image_pad|>",
227
+ "<|video_pad|>"
228
+ ],
229
+ "bos_token": null,
230
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set content = message.content %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is not none %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in message.content %}\n {%- set content = message.content.split('</think>')[-1].lstrip('\\n') %}\n {%- set reasoning_content = message.content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- if loop.index0 > ns.last_query_index %}\n {%- if loop.last or (not loop.last and reasoning_content) %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content.strip('\\n') + '\\n</think>\\n\\n' + content.lstrip('\\n') }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
231
+ "clean_up_tokenization_spaces": false,
232
+ "eos_token": "<|im_end|>",
233
+ "errors": "replace",
234
+ "model_max_length": 131072,
235
+ "pad_token": "<|endoftext|>",
236
+ "split_special_tokens": false,
237
+ "tokenizer_class": "Qwen2Tokenizer",
238
+ "unk_token": null
239
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff