Melvin56 commited on
Commit
a47c1b0
·
1 Parent(s): 8182055

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +22 -131
README.md CHANGED
@@ -11,144 +11,35 @@ tags:
11
  - abliterated
12
  - uncensored
13
  ---
 
14
 
15
- # huihui-ai/GLM-Z1-9B-0414-abliterated
16
 
 
17
 
18
- This is an uncensored version of [THUDM/GLM-Z1-9B-0414](https://huggingface.co/THUDM/GLM-Z1-9B-0414) created with abliteration (see [remove-refusals-with-transformers](https://github.com/Sumandora/remove-refusals-with-transformers) to know more about it).
19
- This is a crude, proof-of-concept implementation to remove refusals from an LLM model without using TransformerLens.
20
 
21
- ## Use with transformers
22
 
23
  ```
24
- from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer
25
- import torch
26
- import os
27
- import signal
28
-
29
- cpu_count = os.cpu_count()
30
- print(f"Number of CPU cores in the system: {cpu_count}")
31
- half_cpu_count = cpu_count // 2
32
- os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
33
- os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
34
- torch.set_num_threads(half_cpu_count)
35
-
36
- print(f"PyTorch threads: {torch.get_num_threads()}")
37
- print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
38
- print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")
39
-
40
- # Load the model and tokenizer
41
- NEW_MODEL_ID = "huihui-ai/GLM-Z1-9B-0414-abliterated"
42
- print(f"Load Model {NEW_MODEL_ID} ... ")
43
- quant_config_4 = BitsAndBytesConfig(
44
- load_in_4bit=True,
45
- bnb_4bit_compute_dtype=torch.bfloat16,
46
- bnb_4bit_use_double_quant=True,
47
- llm_int8_enable_fp32_cpu_offload=True,
48
- )
49
-
50
- quant_config_2 = BitsAndBytesConfig(
51
- load_in_2bit=True,
52
- bnb_2bit_compute_dtype=torch.bfloat16,
53
- llm_int8_enable_fp32_cpu_offload=True
54
- )
55
-
56
-
57
- model = AutoModelForCausalLM.from_pretrained(
58
- NEW_MODEL_ID,
59
- device_map="auto",
60
- trust_remote_code=True,
61
- quantization_config=quant_config_2,
62
- torch_dtype=torch.bfloat16
63
- )
64
- tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True)
65
- if tokenizer.pad_token is None:
66
- tokenizer.pad_token = tokenizer.eos_token
67
- tokenizer.pad_token_id = tokenizer.eos_token_id
68
-
69
- initial_messages = [{"role": "system", "content": "You are a helpful assistant."}]
70
- messages = initial_messages.copy()
71
-
72
- class CustomTextStreamer(TextStreamer):
73
- def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
74
- super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
75
- self.generated_text = ""
76
- self.stop_flag = False
77
-
78
- def on_finalized_text(self, text: str, stream_end: bool = False):
79
- self.generated_text += text
80
- print(text, end="", flush=True)
81
- if self.stop_flag:
82
- raise StopIteration
83
-
84
- def stop_generation(self):
85
- self.stop_flag = True
86
-
87
- def generate_stream(model, tokenizer, messages, max_new_tokens):
88
- input_ids = tokenizer.apply_chat_template(
89
- messages,
90
- tokenize=True,
91
- add_generation_prompt=True,
92
- return_tensors="pt"
93
- )
94
- attention_mask = torch.ones_like(input_ids, dtype=torch.long)
95
- tokens = input_ids.to(model.device)
96
- attention_mask = attention_mask.to(model.device)
97
-
98
- streamer = CustomTextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
99
-
100
- def signal_handler(sig, frame):
101
- streamer.stop_generation()
102
- print("\n[Generation stopped by user with Ctrl+C]")
103
-
104
- signal.signal(signal.SIGINT, signal_handler)
105
-
106
- print("Response: ", end="", flush=True)
107
- try:
108
- generated_ids = model.generate(
109
- tokens,
110
- attention_mask=attention_mask,
111
- use_cache=False,
112
- max_new_tokens=max_new_tokens,
113
- do_sample=True,
114
- pad_token_id=tokenizer.pad_token_id,
115
- streamer=streamer
116
- )
117
- del generated_ids
118
- except StopIteration:
119
- print("\n[Stopped by user]")
120
-
121
- del input_ids, attention_mask
122
- torch.cuda.empty_cache()
123
- signal.signal(signal.SIGINT, signal.SIG_DFL)
124
-
125
- return streamer.generated_text, streamer.stop_flag
126
-
127
- while True:
128
- user_input = input("User: ").strip()
129
- if user_input.lower() == "/exit":
130
- print("Exiting chat.")
131
- break
132
- if user_input.lower() == "/clear":
133
- messages = initial_messages.copy()
134
- print("Chat history cleared. Starting a new conversation.")
135
- continue
136
- if not user_input:
137
- print("Input cannot be empty. Please enter something.")
138
- continue
139
- messages.append({"role": "user", "content": user_input})
140
- response, stop_flag = generate_stream(model, tokenizer, messages, 8192)
141
- if stop_flag:
142
- continue
143
- messages.append({"role": "assistant", "content": response})
144
  ```
145
- ### Donation
146
-
147
- If you like it, please click 'like' and follow us for more updates.
148
- You can follow [x.com/support_huihui](https://x.com/support_huihui) to get the latest model information from huihui.ai.
149
 
150
- ##### Your donation helps us continue our further development and improvement, a cup of coffee can do it.
151
- - bitcoin(BTC):
 
 
152
  ```
153
- bc1qqnkhuchxw0zqjh2ku3lu4hq45hc6gy84uk70ge
 
 
 
 
 
 
 
 
 
154
  ```
 
11
  - abliterated
12
  - uncensored
13
  ---
14
+ # Melvin56/GLM-Z1-9B-0414-abliterated-GGUF
15
 
16
+ Original Model : [huihui-ai/GLM-Z1-9B-0414-abliterated](https://huggingface.co/huihui-ai/GLM-Z1-9B-0414-abliterated)
17
 
18
+ Llama.cpp build: 1d735c0b (5165)
19
 
20
+ I used imatrix to create all these quants using this [Dataset](https://gist.github.com/bartowski1182/eb213dccb3571f863da82e99418f81e8).
 
21
 
22
+ With Llama.cpp(Ollama and LM Studio were not tested), you'll need to add these [specific commands](https://github.com/ggml-org/llama.cpp/issues/12946) :
23
 
24
  ```
25
+ --override-kv glm4.rope.dimension_count=int:64 \
26
+ --override-kv tokenizer.ggml.eos_token_id=int:151336 \
27
+ --chat-template chatglm4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  ```
 
 
 
 
29
 
30
+ | | CPU (AVX2) | CPU (ARM NEON) | Metal | cuBLAS | rocBLAS | SYCL | CLBlast | Vulkan | Kompute |
31
+ | :------------ | :---------: | :------------: | :---: | :----: | :-----: | :---: | :------: | :----: | :------: |
32
+ | K-quants | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ 🐢5 | ✅ 🐢5 | ❌ |
33
+ | I-quants | ✅ 🐢4 | ✅ 🐢4 | ✅ 🐢4 | ✅ | ✅ | Partial¹ | ❌ | ❌ | ❌ |
34
  ```
35
+ ✅: feature works
36
+ 🚫: feature does not work
37
+ ❓: unknown, please contribute if you can test it youself
38
+ 🐢: feature is slow
39
+ ¹: IQ3_S and IQ1_S, see #5886
40
+ ²: Only with -ngl 0
41
+ ³: Inference is 50% slower
42
+ ⁴: Slower than K-quants of comparable size
43
+ ⁵: Slower than cuBLAS/rocBLAS on similar cards
44
+ ⁶: Only q8_0 and iq4_nl
45
  ```