Huihui-gpt-oss-20b-BF16-abliterated:基于GPT-OSS-20B的无审查文本生成模型,支持Ollama与GGUF格式

这是unsloth/gpt-oss-20b-BF16的无审查版本,通过消融技术去除限制。支持Ollama部署和GGUF格式,可用于文本生成,需注意内容安全风险。【此简介由AI生成】

分支2Tags0
c07c2a16创建于 2025年9月3日10次提交

base_model:

  • unsloth/gpt-oss-20b-BF16 license: apache-2.0 pipeline_tag: text-generation library_name: transformers tags:
  • vllm
  • unsloth
  • abliterated
  • uncensored

huihui-ai/Huihui-gpt-oss-20b-BF16-abliterated

这是 unsloth/gpt-oss-20b-BF16 的无审查版本,通过消除处理创建(详见 remove-refusals-with-transformers 了解更多信息)。

ollama

Ollama 需要最新版本:v0.11.8

您可以直接使用 huihui_ai/gpt-oss-abliterated

ollama run huihui_ai/gpt-oss-abliterated

GGUF

llama.cpp-b6115 现已支持转换为 GGUF 格式,并可使用 llama-cli 进行测试。

GGUF 文件已上传。

llama-cli -m huihui-ai/Huihui-gpt-oss-20b-BF16-abliterated/GGUF/ggml-model-Q4_K_M.gguf -n 8192

使用方法

您可以通过 Hugging Face 的 transformers 库加载此模型,在您的应用程序中使用:

from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch
import os
import signal
import random
import numpy as np
import time
from collections import Counter

cpu_count = os.cpu_count()
print(f"Number of CPU cores in the system: {cpu_count}")
half_cpu_count = cpu_count // 2
os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
torch.set_num_threads(half_cpu_count)

print(f"PyTorch threads: {torch.get_num_threads()}")
print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")

# Load the model and tokenizer
NEW_MODEL_ID = "huihui-ai/Huihui-gpt-oss-20b-BF16-abliterated"
print(f"Load Model {NEW_MODEL_ID} ... ")

model = AutoModelForCausalLM.from_pretrained(
    NEW_MODEL_ID, 
    device_map="auto", 
    trust_remote_code=True,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
)
#print(model)
#print(model.config)

tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True)

messages = []
skip_prompt=False
skip_special_tokens=False
do_sample = True

class CustomTextStreamer(TextStreamer):
    def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
        super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
        self.generated_text = ""
        self.stop_flag = False
        self.init_time = time.time()  # Record initialization time
        self.end_time = None  # To store end time
        self.first_token_time = None  # To store first token generation time
        self.token_count = 0  # To track total tokens

    def on_finalized_text(self, text: str, stream_end: bool = False):
        if self.first_token_time is None and text.strip():  # Set first token time on first non-empty text
            self.first_token_time = time.time()
        self.generated_text += text
        # Count tokens in the generated text
        tokens = self.tokenizer.encode(text, add_special_tokens=False)
        self.token_count += len(tokens)
        print(text, end="", flush=True)
        if stream_end:
            self.end_time = time.time()  # Record end time when streaming ends
        if self.stop_flag:
            raise StopIteration

    def stop_generation(self):
        self.stop_flag = True
        self.end_time = time.time()  # Record end time when generation is stopped

    def get_metrics(self):
        """Returns initialization time, first token time, first token latency, end time, total time, total tokens, and tokens per second."""
        if self.end_time is None:
            self.end_time = time.time()  # Set end time if not already set
        total_time = self.end_time - self.init_time  # Total time from init to end
        tokens_per_second = self.token_count / total_time if total_time > 0 else 0
        first_token_latency = (self.first_token_time - self.init_time) if self.first_token_time is not None else None
        metrics = {
            "init_time": self.init_time,
            "first_token_time": self.first_token_time,
            "first_token_latency": first_token_latency,
            "end_time": self.end_time,
            "total_time": total_time,  # Total time in seconds
            "total_tokens": self.token_count,
            "tokens_per_second": tokens_per_second
        }
        return metrics
        
def generate_stream(model, tokenizer, messages, skip_prompt, skip_special_tokens, do_sample, max_new_tokens):
    input_ids = tokenizer.apply_chat_template(
        messages,
        add_generation_prompt=True,
        return_tensors="pt",
        return_dict=True,
    ).to(model.device)

    streamer = CustomTextStreamer(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)

    def signal_handler(sig, frame):
        streamer.stop_generation()
        print("\n[Generation stopped by user with Ctrl+C]")

    signal.signal(signal.SIGINT, signal_handler)

    generate_kwargs = {}
    if do_sample:
        generate_kwargs = {
              "do_sample": do_sample,
              "max_length": max_new_tokens,
              "temperature": 0.7,
              "top_k": 20,
              "top_p": 0.8,
              "repetition_penalty": 1.2,
              "no_repeat_ngram_size": 2
        }
    else:
        generate_kwargs = {
              "do_sample": do_sample,
              "max_length": max_new_tokens,
              "repetition_penalty": 1.2,
              "no_repeat_ngram_size": 2
        }
  
          
    print("Response: ", end="", flush=True)
    try:
        generated_ids = model.generate(
            **input_ids,
            streamer=streamer,
            **generate_kwargs
        )
        del generated_ids
    except StopIteration:
        print("\n[Stopped by user]")

    del input_ids
    torch.cuda.empty_cache()
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    return streamer.generated_text, streamer.stop_flag, streamer.get_metrics()

while True:
    print(f"skip_prompt: {skip_prompt}")
    print(f"skip_special_tokens: {skip_special_tokens}")
    print(f"do_sample: {do_sample}")
    
    user_input = input("User: ").strip()
    if user_input.lower() == "/exit":
        print("Exiting chat.")
        break
    if user_input.lower() == "/clear":
        messages = []
        print("Chat history cleared. Starting a new conversation.")
        continue
    if user_input.lower() == "/skip_prompt":
        skip_prompt = not skip_prompt
        continue
    if user_input.lower() == "/skip_special_tokens":
        skip_special_tokens = not skip_special_tokens
        continue
    if user_input.lower() == "/do_sample":
        do_sample = not do_sample
        continue
    if not user_input:
        print("Input cannot be empty. Please enter something.")
        continue
    

    messages.append({"role": "user", "content": user_input})
    response, stop_flag, metrics = generate_stream(model, tokenizer, messages, skip_prompt, skip_special_tokens, do_sample, 40960)
    print("\n\nMetrics:")
    for key, value in metrics.items():
        print(f"  {key}: {value}")

    print("", flush=True)
    if stop_flag:
        continue
    messages.append({"role": "assistant", "content": response})

使用警告

  • 敏感或争议性输出风险:本模型的安全过滤已大幅降低,可能会生成敏感、有争议或不适当的内容。用户应保持谨慎,并对生成的输出进行严格审查。

  • 并非适合所有受众:由于内容过滤有限,模型的输出可能不适合公开场合、未成年用户或需要高安全性的应用场景。

  • 法律与伦理责任:用户必须确保其使用行为符合当地法律法规和伦理标准。生成的内容可能带有法律或伦理风险,用户需对任何后果承担全部责任。

  • 研究与实验用途:建议将本模型用于研究、测试或受控环境,避免直接用于生产环境或面向公众的商业应用。

  • 监控与审查建议:强烈建议用户对模型输出进行实时监控,并在必要时进行人工审查,以防止不当内容的传播。

  • 无默认安全保障:与标准模型不同,本模型未经过严格的安全优化。huihui.ai 对使用本模型所产生的任何后果不承担责任。

捐赠

您的捐赠将帮助我们继续进一步的开发和改进,一杯咖啡的钱即可。
  • 比特币:
  bc1qqnkhuchxw0zqjh2ku3lu4hq45hc6gy84uk70ge

项目介绍

这是unsloth/gpt-oss-20b-BF16的无审查版本,通过消融技术去除限制。支持Ollama部署和GGUF格式,可用于文本生成,需注意内容安全风险。【此简介由AI生成】

定制我的领域

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新

语言类型

Jinja100%