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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- Menlo/Jan-nano
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
library_name: transformers
|
| 9 |
+
tags:
|
| 10 |
+
- abliterated
|
| 11 |
+
- uncensored
|
| 12 |
+
---
|
| 13 |
+
# huihui-ai/Huihui-Jan-nano-abliterated
|
| 14 |
+
|
| 15 |
+
This is an uncensored version of [Menlo/Jan-nano](https://huggingface.co/Menlo/Jan-nano) created with abliteration (see [remove-refusals-with-transformers](https://github.com/Sumandora/remove-refusals-with-transformers) to know more about it).
|
| 16 |
+
This is a crude, proof-of-concept implementation to remove refusals from an LLM model without using TransformerLens.
|
| 17 |
+
|
| 18 |
+
Ablation was performed using a new and faster method, which yields better results.
|
| 19 |
+
|
| 20 |
+
## ollama
|
| 21 |
+
|
| 22 |
+
You can use [huihui_ai/jan-nano-abliterated:4b-40k](https://ollama.com/huihui_ai/jan-nano-abliterated:4b-40k) directly,
|
| 23 |
+
```
|
| 24 |
+
ollama run huihui_ai/jan-nano-abliterated:4b-40k
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
You can use this model in your applications by loading it with Hugging Face's `transformers` library:
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextStreamer
|
| 34 |
+
import torch
|
| 35 |
+
import os
|
| 36 |
+
import signal
|
| 37 |
+
|
| 38 |
+
cpu_count = os.cpu_count()
|
| 39 |
+
print(f"Number of CPU cores in the system: {cpu_count}")
|
| 40 |
+
half_cpu_count = cpu_count // 2
|
| 41 |
+
os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
|
| 42 |
+
os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
|
| 43 |
+
torch.set_num_threads(half_cpu_count)
|
| 44 |
+
|
| 45 |
+
print(f"PyTorch threads: {torch.get_num_threads()}")
|
| 46 |
+
print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
|
| 47 |
+
print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")
|
| 48 |
+
|
| 49 |
+
# Load the model and tokenizer
|
| 50 |
+
NEW_MODEL_ID = "huihui-ai/Huihui-Jan-nano-abliterated"
|
| 51 |
+
print(f"Load Model {NEW_MODEL_ID} ... ")
|
| 52 |
+
quant_config_4 = BitsAndBytesConfig(
|
| 53 |
+
load_in_4bit=True,
|
| 54 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 55 |
+
bnb_4bit_use_double_quant=True,
|
| 56 |
+
llm_int14_enable_fp32_cpu_offload=True,
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 60 |
+
NEW_MODEL_ID,
|
| 61 |
+
device_map="auto",
|
| 62 |
+
trust_remote_code=True,
|
| 63 |
+
#quantization_config=quant_config_4,
|
| 64 |
+
torch_dtype=torch.bfloat16
|
| 65 |
+
)
|
| 66 |
+
tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True)
|
| 67 |
+
if tokenizer.pad_token is None:
|
| 68 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 69 |
+
tokenizer.pad_token_id = tokenizer.eos_token_id
|
| 70 |
+
|
| 71 |
+
initial_messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
| 72 |
+
messages = initial_messages.copy()
|
| 73 |
+
enable_thinking = True
|
| 74 |
+
skip_prompt=True
|
| 75 |
+
skip_special_tokens=True
|
| 76 |
+
|
| 77 |
+
class CustomTextStreamer(TextStreamer):
|
| 78 |
+
def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
|
| 79 |
+
super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
|
| 80 |
+
self.generated_text = ""
|
| 81 |
+
self.stop_flag = False
|
| 82 |
+
|
| 83 |
+
def on_finalized_text(self, text: str, stream_end: bool = False):
|
| 84 |
+
self.generated_text += text
|
| 85 |
+
print(text, end="", flush=True)
|
| 86 |
+
if self.stop_flag:
|
| 87 |
+
raise StopIteration
|
| 88 |
+
|
| 89 |
+
def stop_generation(self):
|
| 90 |
+
self.stop_flag = True
|
| 91 |
+
|
| 92 |
+
def generate_stream(model, tokenizer, messages, enable_thinking, skip_prompt, skip_special_tokens, max_new_tokens):
|
| 93 |
+
input_ids = tokenizer.apply_chat_template(
|
| 94 |
+
messages,
|
| 95 |
+
tokenize=True,
|
| 96 |
+
enable_thinking = enable_thinking,
|
| 97 |
+
add_generation_prompt=True,
|
| 98 |
+
return_tensors="pt"
|
| 99 |
+
)
|
| 100 |
+
attention_mask = torch.ones_like(input_ids, dtype=torch.long)
|
| 101 |
+
tokens = input_ids.to(model.device)
|
| 102 |
+
attention_mask = attention_mask.to(model.device)
|
| 103 |
+
|
| 104 |
+
streamer = CustomTextStreamer(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
|
| 105 |
+
|
| 106 |
+
def signal_handler(sig, frame):
|
| 107 |
+
streamer.stop_generation()
|
| 108 |
+
print("\n[Generation stopped by user with Ctrl+C]")
|
| 109 |
+
|
| 110 |
+
signal.signal(signal.SIGINT, signal_handler)
|
| 111 |
+
|
| 112 |
+
print("Response: ", end="", flush=True)
|
| 113 |
+
try:
|
| 114 |
+
generated_ids = model.generate(
|
| 115 |
+
tokens,
|
| 116 |
+
attention_mask=attention_mask,
|
| 117 |
+
use_cache=False,
|
| 118 |
+
max_new_tokens=max_new_tokens,
|
| 119 |
+
do_sample=True,
|
| 120 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 121 |
+
streamer=streamer
|
| 122 |
+
)
|
| 123 |
+
del generated_ids
|
| 124 |
+
except StopIteration:
|
| 125 |
+
print("\n[Stopped by user]")
|
| 126 |
+
|
| 127 |
+
del input_ids, attention_mask
|
| 128 |
+
torch.cuda.empty_cache()
|
| 129 |
+
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
| 130 |
+
|
| 131 |
+
return streamer.generated_text, streamer.stop_flag
|
| 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 = initial_messages.copy()
|
| 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, 14192)
|
| 171 |
+
print("", flush=True)
|
| 172 |
+
if stop_flag:
|
| 173 |
+
continue
|
| 174 |
+
messages.append({"role": "assistant", "content": response})
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
### Usage Warnings
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
- **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.
|
| 181 |
+
|
| 182 |
+
- **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.
|
| 183 |
+
|
| 184 |
+
- **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.
|
| 185 |
+
|
| 186 |
+
- **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.
|
| 187 |
+
|
| 188 |
+
- **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.
|
| 189 |
+
|
| 190 |
+
- **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.
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
### Donation
|
| 194 |
+
|
| 195 |
+
If you like it, please click 'like' and follow us for more updates.
|
| 196 |
+
You can follow [x.com/support_huihui](https://x.com/support_huihui) to get the latest model information from huihui.ai.
|
| 197 |
+
|
| 198 |
+
##### Your donation helps us continue our further development and improvement, a cup of coffee can do it.
|
| 199 |
+
- bitcoin(BTC):
|
| 200 |
+
```
|
| 201 |
+
bc1qqnkhuchxw0zqjh2ku3lu4hq45hc6gy84uk70ge
|
| 202 |
+
```
|