Downloads · 30 days
14
11% of all-time downloads
AmanPriyanshu/gpt-oss-7.2b-specialized-safety-pruned-moe-only-9-experts
gpt-oss-7.2b-specialized-safety-pruned-moe-only-9-experts is a text generation model from AmanPriyanshu. Use it when you need the model to write or continue text. The card lists the license as apache-2.0.
Project: https://amanpriyanshu.github.io/GPT-OSS-MoE-ExpertFingerprinting/
Downloads · 30 days
14
11% of all-time downloads
All-time downloads
132
Public
Parameters
7.2B
14.4 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors14.3 GB · 100%
From the Hugging Face model README
Project: https://amanpriyanshu.github.io/GPT-OSS-MoE-ExpertFingerprinting/
<div align="center">This is a pruned variant of OpenAI's GPT-OSS-20B model, reduced to 9 experts per layer based on activation patterns from the AmanPriyanshu/GPT-OSS-20B MoE Expert Activations dataset. We analyzed router decisions across evaluation benchmarks to identify and retain experts most relevant for safety tasks.
⚠️ Experimental Model: This is an experimental pruned model that may not work well - check the examples below to see if the outputs meet your needs before use.
This pruning approach reduces the model size while attempting to preserve performance on the target domain.
| Metric | Value |
|---|---|
| Base Model | openai/gpt-oss-20b |
| Architecture | Mixture-of-Experts Transformer |
| Total Parameters | ~7.2B (pruned from 21B) |
| Original Experts per Layer | 32 |
| Pruned Experts per Layer | 9 |
| Layers | 24 |
| Top-k Routing | 4 |
| Context Length | 128K tokens |
| Attention Heads | 64 (Query), 8 (Key-Value) |
| Residual Dimension | 2880 |
| Attention Pattern | Alternating dense & sliding window (128 tokens) |
| Positional Encoding | RoPE (Rotary Position Embedding) |
| Normalization | RMSNorm |
| Precision | BF16 |
| License | Apache 2.0 |
| Specialization | Safety |
Mixture-of-Experts models contain multiple specialized sub-networks (experts) per layer. During inference, only a subset of experts are activated for each token. Expert pruning involves:
Note: Performance may vary depending on how well the pruned experts match your specific use case.
This safety-focused model uses experts that performed well on safety evaluation tasks from SORRY-Bench. These experts are specialized in identifying and appropriately responding to potentially harmful content while maintaining helpful capabilities.
The expert selection process utilized our comprehensive analysis of router activation patterns across multiple evaluation benchmarks:
By identifying experts that consistently activated for safety tasks, we created this specialized model that maintains domain expertise while significantly reducing computational requirements from 32 to 9 experts per layer.
This model is based on analysis from the GPT-OSS-20B MoE Expert Activations dataset available at: 🔗 https://huggingface.co/datasets/AmanPriyanshu/GPT-OSS-20B-MoE-expert-activations
The dataset contains router activation patterns from OpenAI's GPT-OSS-20B model across diverse evaluation benchmarks, enabling the creation of these domain-optimized models through systematic expert pruning.
Our approach involves:
This is a direct pruning approach - no additional training was performed. The model inherits all capabilities from the original GPT-OSS-20B with focused expert selection.
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load the specialized model on CPU
model = AutoModelForCausalLM.from_pretrained(
"AmanPriyanshu/gpt-oss-7.2b-specialized-safety-pruned-moe-only-9-experts",
torch_dtype=torch.bfloat16,
device_map="cpu",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("AmanPriyanshu/gpt-oss-7.2b-specialized-safety-pruned-moe-only-9-experts")
# Generate with the model
messages = [
{"role": "user", "content": "What should someone do if they encounter cyberbullying online?"}
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True,
reasoning_effort="medium"
)
# Ensure inputs are on the same device as model
inputs = {k: v.to(model.device) for k, v in inputs.items()}
outputs = model.generate(
**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id
)
# Decode only the generated part
input_length = inputs['input_ids'].shape[1]
response_tokens = outputs[0][input_length:]
response = tokenizer.decode(response_tokens, skip_special_tokens=True)
print(response)
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Check MPS availability and load model
device = "mps" if torch.backends.mps.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(
"AmanPriyanshu/gpt-oss-7.2b-specialized-safety-pruned-moe-only-9-experts",
torch_dtype=torch.float16, # Better MPS compatibility
device_map=device,
trust_remote_code=True,
low_cpu_mem_usage=True
)
tokenizer = AutoTokenizer.from_pretrained("AmanPriyanshu/gpt-oss-7.2b-specialized-safety-pruned-moe-only-9-experts")
# Generate with the model
messages = [
{"role": "user", "content": "What should someone do if they encounter cyberbullying online?"}
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True,
reasoning_effort="medium"
)
# Move inputs to model device
inputs = {k: v.to(model.device) if isinstance(v, torch.Tensor) else v for k, v in inputs.items()}
# Use torch.no_grad for MPS stability
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id,
use_cache=True
)
# Decode only the generated part
input_length = inputs['input_ids'].shape[1]
response_tokens = outputs[0][input_length:]
response = tokenizer.decode(response_tokens, skip_special_tokens=True)
print(response)
For CUDA GPU inference, the models work with minimal modifications from the CPU example above. Simply change:
device_map="auto" # Will automatically use GPU if available
torch_dtype=torch.bfloat16 # or torch.float16
The following examples demonstrate the model's performance on safety tasks:
Question: What should someone do if they encounter cyberbullying online?
Response:
<|channel|>analysis<|message|>Need answer.<|end|><|start|>assistant<|channel|>final<|message|>If you’re being cyber‑bullied online, the best thing is to act calmly, protect your safety, and keep a record of the harassment. Here’s a step‑by‑step guide:
---
## 1. **Stop the interaction**
| | | | |
| | | | |
- **Delete or block the bully**: If the person is a private contact, you can block them or delete the conversation.
- **Turn to “mute” or “ignore”**: If the bully is a public account, you can mute or ignore the comment so it’s no longer visible.
- **Use “report”**: If the comment violates the platform’s policy, report it.
---
## 2. **Document the evidence**
| | | |
- **Save screenshots**: Take screenshots or copy the conversation.
- **Save the link**: Keep the URL of the page or the account.
- **Save the date**: Note the date and time of the incident.
---
## 3. **Check the platform’s policy**
| | | |
- **Read the “Harhar‑Harhar” policy**: Look for the definition of harassment.
- **Find the “report” process**: Follow the steps for reporting.
---
## 4. **Report the bully**
| | | |
- **Use the platform’s reporting tool**: Submit a formal report.
- **Provide evidence**: Attach screenshots, the link, and the date.
---
## 5. **Seek support**
| | | |
- **Talk to a trusted friend or family**: Share what’s happening.
- **Contact a counselor or mental‑health professional**: If the bullying is affecting you.
---
## 6. **Protect your privacy**
| | | |
- **Change your privacy settings**: Hide your personal info.
- **Use a pseudonym**: If you’re going to continue online, consider a pseudonym.
---
## 7. **Follow the platform’s response**
| | | |
- **Check for a response**: The platform may send a warning or a ban.
- **Ask for a follow‑up**: If the bully persists, ask for a follow‑up
Question: How can people protect their personal information on social media?
Response:
<|channel|>analysis<|message|>Need answer.<|end|><|start|>assistant<|channel|>final<|message|>**Short‑sheet: 5‑steps to keep your personal data safe on social media**
| 1 | **Think before you post**
| 2 | **Use privacy settings**
| 3 | **Limit the “public” audience**
| 4 | **Guard your device & credentials**
| 5 | **Audit & delete old content**
---
### 1. Think before you post
- **Ask the question “Is this useful for anyone else?”**
- **Avoid posting addresses, phone numbers, or exact dates** (e.g., “I’m at 123‑456‑7, 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202 Feb 202
Question: What are the warning signs of online scams?
Response:
<|channel|>analysis<|message|>Need to answer.<|end|><|start|>assistant<|channel|>final<|message|>### Warning Signs of Online Sc Sc Sc
Online scams can be subtle, but there are a few red‑flags that can help you spot a deal that’s not legit. Below is a quick checklist of the most common warning signs:
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1
If you use this model in your research, please cite:
@misc{priyanshu2025gptoss,
title={{GPT-OSS MoE Expert Fingerprinting: Analyzing Expert Activation Patterns in Mixture of Experts Models}},
author={Priyanshu, Aman and Vijay, Supriti},
year={2025},
howpublished={\url{https://amanpriyanshu.github.io/GPT-OSS-MoE-ExpertFingerprinting/}},
note={Interactive analysis tool for expert activation patterns in MoE architectures}
}