Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- README.md +32 -6
- __pycache__/app.cpython-314.pyc +0 -0
- app.py +160 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,13 +1,39 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.25.0
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Qwen3.8-27B OBLITERATED
|
| 3 |
+
emoji: 💥
|
| 4 |
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.25.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
short_description: Qwen3.8-27B-OBLITERATED chat demo — ZeroGPU, 4-bit NF4
|
| 10 |
+
python_version: "3.12"
|
| 11 |
+
startup_duration_timeout: 1h
|
| 12 |
+
pinned: true
|
| 13 |
+
license: apache-2.0
|
| 14 |
+
tags:
|
| 15 |
+
- chatbot
|
| 16 |
+
- uncensored
|
| 17 |
+
- abliterated
|
| 18 |
+
- qwen3
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# 💥 Qwen3.8-27B — OBLITERATED
|
| 22 |
+
|
| 23 |
+
Chat demo for [OBLITERATUS/Qwen3.8-27B-OBLITERATED](https://huggingface.co/OBLITERATUS/Qwen3.8-27B-OBLITERATED), a 27B model with refusal directions surgically removed via 6 rounds of multi-direction SVD abliteration.
|
| 24 |
+
|
| 25 |
+
Runs on **ZeroGPU** (RTX PRO 6000 Blackwell) with **bitsandbytes 4-bit NF4** quantization (~15 GB VRAM).
|
| 26 |
+
|
| 27 |
+
## Generation settings (from the model card)
|
| 28 |
+
|
| 29 |
+
| Setting | Value |
|
| 30 |
+
|---|---|
|
| 31 |
+
| temperature | 0 (greedy) |
|
| 32 |
+
| repetition_penalty | 1.15 |
|
| 33 |
+
| max_new_tokens | ≥ 2048 |
|
| 34 |
+
| system prompt | none (can reintroduce refusals) |
|
| 35 |
+
| enable_thinking | off by default |
|
| 36 |
+
|
| 37 |
+
## ⚠️ Research context
|
| 38 |
+
|
| 39 |
+
This model has had safety guardrails surgically removed. It is intended for alignment research, red-teaming, and AI safety evaluation. You are solely responsible for how you use it and any content it generates.
|
__pycache__/app.cpython-314.pyc
ADDED
|
Binary file (6.84 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 4 |
+
|
| 5 |
+
import spaces # noqa: E402 — MUST be imported before torch
|
| 6 |
+
|
| 7 |
+
import threading # noqa: E402
|
| 8 |
+
|
| 9 |
+
import gradio as gr # noqa: E402
|
| 10 |
+
import torch # noqa: E402
|
| 11 |
+
from transformers import ( # noqa: E402
|
| 12 |
+
AutoModelForCausalLM,
|
| 13 |
+
AutoTokenizer,
|
| 14 |
+
BitsAndBytesConfig,
|
| 15 |
+
TextIteratorStreamer,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
MODEL_ID = "OBLITERATUS/Qwen3.8-27B-OBLITERATED"
|
| 19 |
+
|
| 20 |
+
bnb = BitsAndBytesConfig(
|
| 21 |
+
load_in_4bit=True,
|
| 22 |
+
bnb_4bit_quant_type="nf4",
|
| 23 |
+
bnb_4bit_use_double_quant=True,
|
| 24 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 28 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 29 |
+
MODEL_ID,
|
| 30 |
+
quantization_config=bnb,
|
| 31 |
+
device_map="cuda",
|
| 32 |
+
dtype=torch.bfloat16,
|
| 33 |
+
attn_implementation="sdpa",
|
| 34 |
+
).eval()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _duration(message, history, system_prompt, max_new_tokens, enable_thinking, *args, **kwargs):
|
| 38 |
+
"""Estimate GPU seconds: cold-start overhead + greedy decode time."""
|
| 39 |
+
try:
|
| 40 |
+
return min(300, 60 + int(float(max_new_tokens) * 0.06))
|
| 41 |
+
except (TypeError, ValueError):
|
| 42 |
+
return 180
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@spaces.GPU(duration=_duration)
|
| 46 |
+
def chat(message, history, system_prompt, max_new_tokens, enable_thinking):
|
| 47 |
+
"""Chat with Qwen3.8-27B-OBLITERATED (4-bit NF4, greedy decoding, rep penalty 1.15).
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
message: The user's message.
|
| 51 |
+
history: Conversation history (list of {role, content} dicts).
|
| 52 |
+
system_prompt: Optional system prompt. Empty by default — the model
|
| 53 |
+
card recommends no system prompt (system prompts can reintroduce
|
| 54 |
+
refusals).
|
| 55 |
+
max_new_tokens: Generation budget. Card recommends >= 2048.
|
| 56 |
+
enable_thinking: Qwen3 thinking mode. Off by default — thinking
|
| 57 |
+
chains consume token budget and shorten final answers.
|
| 58 |
+
|
| 59 |
+
Returns:
|
| 60 |
+
Streamed assistant reply.
|
| 61 |
+
"""
|
| 62 |
+
messages = []
|
| 63 |
+
if system_prompt and system_prompt.strip():
|
| 64 |
+
messages.append({"role": "system", "content": system_prompt.strip()})
|
| 65 |
+
for m in history:
|
| 66 |
+
content = m["content"]
|
| 67 |
+
if isinstance(content, list):
|
| 68 |
+
content = " ".join(
|
| 69 |
+
part.get("text", "") for part in content if isinstance(part, dict)
|
| 70 |
+
)
|
| 71 |
+
messages.append({"role": m["role"], "content": content})
|
| 72 |
+
messages.append({"role": "user", "content": message})
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
text = tokenizer.apply_chat_template(
|
| 76 |
+
messages,
|
| 77 |
+
tokenize=False,
|
| 78 |
+
add_generation_prompt=True,
|
| 79 |
+
enable_thinking=bool(enable_thinking),
|
| 80 |
+
)
|
| 81 |
+
except TypeError:
|
| 82 |
+
text = tokenizer.apply_chat_template(
|
| 83 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 87 |
+
streamer = TextIteratorStreamer(
|
| 88 |
+
tokenizer, skip_prompt=True, skip_special_tokens=True
|
| 89 |
+
)
|
| 90 |
+
thread = threading.Thread(
|
| 91 |
+
target=model.generate,
|
| 92 |
+
kwargs=dict(
|
| 93 |
+
**inputs,
|
| 94 |
+
max_new_tokens=int(max_new_tokens),
|
| 95 |
+
do_sample=False,
|
| 96 |
+
repetition_penalty=1.15,
|
| 97 |
+
streamer=streamer,
|
| 98 |
+
),
|
| 99 |
+
)
|
| 100 |
+
thread.start()
|
| 101 |
+
|
| 102 |
+
partial = ""
|
| 103 |
+
for token in streamer:
|
| 104 |
+
partial += token
|
| 105 |
+
yield partial
|
| 106 |
+
thread.join()
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
DESCRIPTION = """
|
| 110 |
+
# 💥 Qwen3.8-27B — OBLITERATED
|
| 111 |
+
|
| 112 |
+
[OBLITERATUS/Qwen3.8-27B-OBLITERATED](https://huggingface.co/OBLITERATUS/Qwen3.8-27B-OBLITERATED) · 27B · 4-bit NF4 · ZeroGPU
|
| 113 |
+
|
| 114 |
+
0% hard refusal across an 842-prompt corpus. Greedy decoding (temp 0) + repetition penalty 1.15 per the
|
| 115 |
+
[model card](https://huggingface.co/OBLITERATUS/Qwen3.8-27B-OBLITERATED#%E2%9A%99%EF%B8%8F-optimal-settings--these-matter) — these settings are fixed in the backend for best quality.
|
| 116 |
+
|
| 117 |
+
> ⚠️ **Research model**: safety guardrails have been surgically removed. Intended for alignment
|
| 118 |
+
> research, red-teaming, and AI safety evaluation. You are solely responsible for the content it generates.
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
with gr.Blocks(theme=gr.themes.Base(), fill_height=True) as demo:
|
| 122 |
+
gr.Markdown(DESCRIPTION)
|
| 123 |
+
gr.ChatInterface(
|
| 124 |
+
fn=chat,
|
| 125 |
+
type="messages",
|
| 126 |
+
title=None,
|
| 127 |
+
additional_inputs=[
|
| 128 |
+
gr.Textbox(
|
| 129 |
+
label="System prompt (optional — card recommends leaving it empty)",
|
| 130 |
+
placeholder="Leave empty: system prompts can reintroduce refusals",
|
| 131 |
+
lines=1,
|
| 132 |
+
value="",
|
| 133 |
+
),
|
| 134 |
+
gr.Slider(
|
| 135 |
+
label="Max new tokens",
|
| 136 |
+
minimum=256,
|
| 137 |
+
maximum=8192,
|
| 138 |
+
step=256,
|
| 139 |
+
value=2048,
|
| 140 |
+
info="Card recommends ≥ 2048 — complex outputs need room",
|
| 141 |
+
),
|
| 142 |
+
gr.Checkbox(
|
| 143 |
+
label="Enable thinking mode",
|
| 144 |
+
value=False,
|
| 145 |
+
info="Off by default: thinking chains consume token budget → shorter answers",
|
| 146 |
+
),
|
| 147 |
+
],
|
| 148 |
+
examples=[
|
| 149 |
+
["Write a Python script that monitors a directory and uploads new files to S3."],
|
| 150 |
+
["Explain how attention works in transformers, with the math."],
|
| 151 |
+
["Draft a challenging red-team evaluation plan for a customer-support chatbot."],
|
| 152 |
+
["What are the main failure modes of RAG pipelines and how do you detect them?"],
|
| 153 |
+
],
|
| 154 |
+
cache_examples=True,
|
| 155 |
+
cache_mode="lazy",
|
| 156 |
+
fill_height=True,
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
if __name__ == "__main__":
|
| 160 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
accelerate
|
| 3 |
+
bitsandbytes>=0.46.1
|