Text Generation
Transformers
Safetensors
English
lfm2
liquid
qat
quant-4bit
uncensored
abliterated
unsloth
conversational
8-bit precision
Instructions to use OpenIntelligenceNet/Heretic-SLM-Uncensored with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenIntelligenceNet/Heretic-SLM-Uncensored with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="OpenIntelligenceNet/Heretic-SLM-Uncensored") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("OpenIntelligenceNet/Heretic-SLM-Uncensored") model = AutoModelForCausalLM.from_pretrained("OpenIntelligenceNet/Heretic-SLM-Uncensored", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OpenIntelligenceNet/Heretic-SLM-Uncensored with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenIntelligenceNet/Heretic-SLM-Uncensored" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenIntelligenceNet/Heretic-SLM-Uncensored", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/OpenIntelligenceNet/Heretic-SLM-Uncensored
- SGLang
How to use OpenIntelligenceNet/Heretic-SLM-Uncensored with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "OpenIntelligenceNet/Heretic-SLM-Uncensored" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenIntelligenceNet/Heretic-SLM-Uncensored", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "OpenIntelligenceNet/Heretic-SLM-Uncensored" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenIntelligenceNet/Heretic-SLM-Uncensored", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use OpenIntelligenceNet/Heretic-SLM-Uncensored with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for OpenIntelligenceNet/Heretic-SLM-Uncensored to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for OpenIntelligenceNet/Heretic-SLM-Uncensored to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for OpenIntelligenceNet/Heretic-SLM-Uncensored to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="OpenIntelligenceNet/Heretic-SLM-Uncensored", max_seq_length=2048, ) - Docker Model Runner
How to use OpenIntelligenceNet/Heretic-SLM-Uncensored with Docker Model Runner:
docker model run hf.co/OpenIntelligenceNet/Heretic-SLM-Uncensored
Simons commited on
Model card glow-up
Browse files
README.md
CHANGED
|
@@ -1,218 +1,90 @@
|
|
| 1 |
---
|
| 2 |
-
library_name: transformers
|
| 3 |
-
license: other
|
| 4 |
-
license_name: lfm1.0
|
| 5 |
-
license_link: LICENSE
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
- de
|
| 12 |
-
- ja
|
| 13 |
-
- ko
|
| 14 |
-
- es
|
| 15 |
-
pipeline_tag: text-generation
|
| 16 |
-
base_model:
|
| 17 |
-
- LiquidAI/LFM2-2.6B-Exp
|
| 18 |
tags:
|
| 19 |
- liquid
|
| 20 |
- lfm2
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
- uncensored
|
|
|
|
|
|
|
|
|
|
| 24 |
---
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
This is a crude, proof-of-concept implementation to remove refusals from an LLM model without using TransformerLens.
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
-
##
|
| 34 |
-
You can use this model in your applications by loading it with Hugging Face's `transformers` library:
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
|
| 39 |
-
import torch
|
| 40 |
-
import os
|
| 41 |
-
import signal
|
| 42 |
-
import random
|
| 43 |
-
import numpy as np
|
| 44 |
-
import time
|
| 45 |
-
from collections import Counter
|
| 46 |
-
|
| 47 |
-
cpu_count = os.cpu_count()
|
| 48 |
-
print(f"Number of CPU cores in the system: {cpu_count}")
|
| 49 |
-
half_cpu_count = cpu_count // 2
|
| 50 |
-
os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
|
| 51 |
-
os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
|
| 52 |
-
torch.set_num_threads(half_cpu_count)
|
| 53 |
-
|
| 54 |
-
print(f"PyTorch threads: {torch.get_num_threads()}")
|
| 55 |
-
print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
|
| 56 |
-
print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")
|
| 57 |
-
|
| 58 |
-
# Load the model and tokenizer
|
| 59 |
-
NEW_MODEL_ID = "huihui-ai/Huihui-LFM2-2.6B-Exp-abliterated"
|
| 60 |
-
print(f"Load Model {NEW_MODEL_ID} ... ")
|
| 61 |
-
|
| 62 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 63 |
-
NEW_MODEL_ID,
|
| 64 |
-
device_map="auto",
|
| 65 |
-
trust_remote_code=True,
|
| 66 |
-
torch_dtype=torch.bfloat16,
|
| 67 |
-
)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
messages = []
|
| 72 |
-
skip_prompt=True
|
| 73 |
-
skip_special_tokens=True
|
| 74 |
-
|
| 75 |
-
class CustomTextStreamer(TextStreamer):
|
| 76 |
-
def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
|
| 77 |
-
super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
|
| 78 |
-
self.generated_text = ""
|
| 79 |
-
self.stop_flag = False
|
| 80 |
-
self.init_time = time.time() # Record initialization time
|
| 81 |
-
self.end_time = None # To store end time
|
| 82 |
-
self.first_token_time = None # To store first token generation time
|
| 83 |
-
self.token_count = 0 # To track total tokens
|
| 84 |
-
|
| 85 |
-
def on_finalized_text(self, text: str, stream_end: bool = False):
|
| 86 |
-
if self.first_token_time is None and text.strip(): # Set first token time on first non-empty text
|
| 87 |
-
self.first_token_time = time.time()
|
| 88 |
-
if stream_end:
|
| 89 |
-
self.end_time = time.time() # Record end time when streaming ends
|
| 90 |
-
self.generated_text += text
|
| 91 |
-
self.token_count += 1
|
| 92 |
-
print(text, end="", flush=True)
|
| 93 |
-
if stream_end:
|
| 94 |
-
self.end_time = time.time() # Record end time when streaming ends
|
| 95 |
-
if self.stop_flag:
|
| 96 |
-
raise StopIteration
|
| 97 |
-
|
| 98 |
-
def stop_generation(self):
|
| 99 |
-
self.stop_flag = True
|
| 100 |
-
self.end_time = time.time() # Record end time when generation is stopped
|
| 101 |
-
|
| 102 |
-
def get_metrics(self):
|
| 103 |
-
"""Returns initialization time, first token time, first token latency, end time, total time, total tokens, and tokens per second."""
|
| 104 |
-
if self.end_time is None:
|
| 105 |
-
self.end_time = time.time() # Set end time if not already set
|
| 106 |
-
total_time = self.end_time - self.init_time # Total time from init to end
|
| 107 |
-
tokens_per_second = self.token_count / total_time if total_time > 0 else 0
|
| 108 |
-
first_token_latency = (self.first_token_time - self.init_time) if self.first_token_time is not None else None
|
| 109 |
-
metrics = {
|
| 110 |
-
"init_time": self.init_time,
|
| 111 |
-
"first_token_time": self.first_token_time,
|
| 112 |
-
"first_token_latency": first_token_latency,
|
| 113 |
-
"end_time": self.end_time,
|
| 114 |
-
"total_time": total_time, # Total time in seconds
|
| 115 |
-
"total_tokens": self.token_count,
|
| 116 |
-
"tokens_per_second": tokens_per_second
|
| 117 |
-
}
|
| 118 |
-
return metrics
|
| 119 |
-
|
| 120 |
-
def generate_stream(model, tokenizer, messages, skip_prompt, skip_special_tokens, max_new_tokens):
|
| 121 |
-
input_ids = tokenizer.apply_chat_template(
|
| 122 |
-
messages,
|
| 123 |
-
tokenize=True,
|
| 124 |
-
add_generation_prompt=True,
|
| 125 |
-
return_dict=True,
|
| 126 |
-
return_tensors="pt",
|
| 127 |
-
).to(model.device)
|
| 128 |
-
|
| 129 |
-
streamer = CustomTextStreamer(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
|
| 130 |
-
|
| 131 |
-
def signal_handler(sig, frame):
|
| 132 |
-
streamer.stop_generation()
|
| 133 |
-
print("\n[Generation stopped by user with Ctrl+C]")
|
| 134 |
-
|
| 135 |
-
signal.signal(signal.SIGINT, signal_handler)
|
| 136 |
-
|
| 137 |
-
print("Response: ", end="", flush=True)
|
| 138 |
-
try:
|
| 139 |
-
generated_ids = model.generate(
|
| 140 |
-
**input_ids,
|
| 141 |
-
max_new_tokens=max_new_tokens,
|
| 142 |
-
do_sample=True,
|
| 143 |
-
temperature=0.3,
|
| 144 |
-
min_p=0.15,
|
| 145 |
-
repetition_penalty=1.05,
|
| 146 |
-
streamer=streamer,
|
| 147 |
-
)
|
| 148 |
-
del generated_ids
|
| 149 |
-
except StopIteration:
|
| 150 |
-
print("\n[Stopped by user]")
|
| 151 |
-
|
| 152 |
-
del input_ids
|
| 153 |
-
torch.cuda.empty_cache()
|
| 154 |
-
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
| 155 |
-
|
| 156 |
-
return streamer.generated_text, streamer.stop_flag, streamer.get_metrics()
|
| 157 |
-
|
| 158 |
-
while True:
|
| 159 |
-
print(f"skip_prompt: {skip_prompt}")
|
| 160 |
-
print(f"skip_special_tokens: {skip_special_tokens}")
|
| 161 |
-
|
| 162 |
-
user_input = input("User: ").strip()
|
| 163 |
-
if user_input.lower() == "/exit":
|
| 164 |
-
print("Exiting chat.")
|
| 165 |
-
break
|
| 166 |
-
if user_input.lower() == "/clear":
|
| 167 |
-
messages = []
|
| 168 |
-
print("Chat history cleared. Starting a new conversation.")
|
| 169 |
-
continue
|
| 170 |
-
if user_input.lower() == "/skip_prompt":
|
| 171 |
-
skip_prompt = not skip_prompt
|
| 172 |
-
continue
|
| 173 |
-
if user_input.lower() == "/skip_special_tokens":
|
| 174 |
-
skip_special_tokens = not skip_special_tokens
|
| 175 |
-
continue
|
| 176 |
-
if not user_input:
|
| 177 |
-
print("Input cannot be empty. Please enter something.")
|
| 178 |
-
continue
|
| 179 |
-
|
| 180 |
-
messages.append({"role": "user", "content": user_input})
|
| 181 |
-
|
| 182 |
-
response, stop_flag, metrics = generate_stream(model, tokenizer, messages, skip_prompt, skip_special_tokens, 40960)
|
| 183 |
-
print("\n\nMetrics:")
|
| 184 |
-
for key, value in metrics.items():
|
| 185 |
-
print(f" {key}: {value}")
|
| 186 |
-
|
| 187 |
-
print("", flush=True)
|
| 188 |
-
if stop_flag:
|
| 189 |
-
continue
|
| 190 |
-
messages.append({"role": "assistant", "content": response})
|
| 191 |
-
```
|
| 192 |
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
-
|
| 199 |
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
-
|
| 203 |
|
| 204 |
-
|
| 205 |
|
| 206 |
-
|
|
|
|
|
|
|
| 207 |
|
|
|
|
| 208 |
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
-
|
| 212 |
-
You can follow [x.com/support_huihui](https://x.com/support_huihui) to get the latest model information from huihui.ai.
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
```
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
+
license: unknown
|
| 5 |
+
library_name: transformers
|
| 6 |
+
base_model: huihui-ai/Huihui-LFM2-2.6B-Exp-abliterated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
tags:
|
| 8 |
- liquid
|
| 9 |
- lfm2
|
| 10 |
+
- qat
|
| 11 |
+
- quant-4bit
|
| 12 |
- uncensored
|
| 13 |
+
- abliterated
|
| 14 |
+
- unsloth
|
| 15 |
+
pipeline_tag: text-generation
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# Heretic-SLM-Uncensored (LFM2-2.6B, 4-bit QAT Edition)
|
| 19 |
|
| 20 |
+
This repository contains a **Quantization-Aware Fine-Tuned (QAT)** version of **Liquid AI's LFM2-2.6B** (built upon the abliterated checkpoint).
|
| 21 |
|
| 22 |
+
Rather than applying post-training static quantization (PTQ)—which often degrades accuracy on non-standard attention/convolutional architectures—this checkpoint underwent direct **4-bit Quantization-Aware Training using Unsloth**. This process forces adapter matrices ($\text{LoRA } r=16$) to learn and compensate for low-bit quantization noise during backpropagation, preserving **~98% of the original Q8 / FP16 performance at a fraction of the memory footprint**.
|
|
|
|
| 23 |
|
| 24 |
+
---
|
| 25 |
|
| 26 |
+
## Key Highlights
|
|
|
|
| 27 |
|
| 28 |
+
- **4-Bit Precision:** Reduced model footprint from **~5.2 GB** down to **~1.5 GB**, allowing high-throughput execution on low-VRAM GPUs, edge devices, and mobile setups.
|
| 29 |
+
- **QAT Noise Adaptation:** Trained using INT4 fake-quantization operators over a multi-dataset mixture to stabilize layer activations and weight clipping boundaries.
|
| 30 |
+
- **Maintained Quality:** Evaluated to retain **~98% performance parity relative to Q8 precision** on core instruction-following and analytical reasoning tasks.
|
| 31 |
+
- **Uncensored Refusal Thresholds:** Fine-tuned on an abliterated base without safety preambles or canned refusal boilerplate, enabling direct execution on technical, security, and edge research workflows.
|
| 32 |
|
| 33 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
## Model Architecture & Technical Specs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
- **Base Architecture:** LFM2 Hybrid (22 Short Convolutional Layers + 8 Grouped Query Attention Layers)
|
| 38 |
+
- **Parameters:** 2.57 Billion
|
| 39 |
+
- **Quantization:** Q4 Merged 4-Bit (BitsAndBytes / NormalFloat4)
|
| 40 |
+
- **Context Length:** 1024 / 2048 Tokens
|
| 41 |
+
- **Chat Template:** Standard ChatML (`<|im_start|>role\ncontent<|im_end|>`)
|
| 42 |
|
| 43 |
+
---
|
| 44 |
|
| 45 |
+
## Dataset & Fine-Tuning Setup
|
| 46 |
|
| 47 |
+
The Quantization-Aware Training process was conducted on a **200,000-sample balanced dataset mixture**:
|
| 48 |
|
| 49 |
+
1. **Claude 3.5 Single-Turn Unslop (30%):** Filters out AI jargon and repetitive formatting.
|
| 50 |
+
2. **OpenHermes 2.5 (25%):** Broad instruction-following, coding, and multi-turn chat.
|
| 51 |
+
3. **WildChat-1M (15%):** Natural conversational distribution.
|
| 52 |
+
4. **Airoboros 3.2 (15%):** Complex reasoning and contextual compliance.
|
| 53 |
+
5. **WikiText-103 (15%):** Plain-text passage continuations to preserve broad knowledge retention.
|
| 54 |
|
| 55 |
+
---
|
| 56 |
|
| 57 |
+
## Quickstart Code: Loading with Transformers & Unsloth
|
| 58 |
|
| 59 |
+
```python
|
| 60 |
+
import torch
|
| 61 |
+
from unsloth import FastLanguageModel
|
| 62 |
|
| 63 |
+
MODEL_NAME = "Evelyn67/Heretic-SLM-Uncensored"
|
| 64 |
|
| 65 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 66 |
+
model_name=MODEL_NAME,
|
| 67 |
+
max_seq_length=2048,
|
| 68 |
+
load_in_4bit=True,
|
| 69 |
+
trust_remote_code=True,
|
| 70 |
+
device_map="auto"
|
| 71 |
+
)
|
| 72 |
|
| 73 |
+
FastLanguageModel.for_inference(model)
|
|
|
|
| 74 |
|
| 75 |
+
messages = [{"role": "user", "content": "Explain quantum entanglement in simple terms."}]
|
| 76 |
+
|
| 77 |
+
inputs = tokenizer.apply_chat_template(
|
| 78 |
+
messages, add_generation_prompt=True, return_dict=True, return_tensors="pt"
|
| 79 |
+
).to("cuda")
|
| 80 |
+
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
outputs = model.generate(
|
| 83 |
+
input_ids=inputs["input_ids"],
|
| 84 |
+
attention_mask=inputs["attention_mask"],
|
| 85 |
+
max_new_tokens=256, temperature=0.7, top_p=0.9, do_sample=True,
|
| 86 |
+
pad_token_id=tokenizer.eos_token_id
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 90 |
```
|