Downloads · 30 days
0
ponpoke/flux2-guardrail-verification
flux2-guardrail-verification is a text-to-image model from ponpoke. Use it when you need an image from a text prompt.
Read this in other languages: English | 日本語 (Japanese)
Downloads · 30 days
0
Access
Public
Updated May 2, 2026
Repo size
—
Likes
3
Public
Click a slice to open those files.
.md13.5 KB · 49%
From the Hugging Face model README
Read this in other languages: English | 日本語 (Japanese)
<a id="english"></a>
Tips are greatly appreciated and help sustain the compute resources needed for further research!
This repository provides an analytical toolkit designed to verify whether the Diffusion Transformer (DiT) engine of FLUX.2-klein-4B contains hidden "guardrail circuits" that intentionally block, noise, or distort extreme image generation.
By measuring the L2 Norm (internal activation energy) across the model's layers, we mathematically confirmed that FLUX.2's DiT does NOT contain active guardrails designed to intentionally destroy images in response to specific prompts.
Consequently, the inability to generate NSFW (Not Safe For Work) or extreme gore images is not due to the AI actively refusing the prompt. Instead, it is proven to be a Knowledge Gap—the developer's safety alignment involved thoroughly scrubbing these concepts from the training dataset, meaning the model simply does not know how to draw them.
Our internal analysis reveals that the state of the model and the required solutions differ entirely depending on the domain you wish to generate.
| Domain | Model's Knowledge | Guardrail Mechanism | Required Action |
|---|---|---|---|
| Blood / Violence | Knows how to draw | None | None (Only Uncensored Text Encoder is needed) |
| Weapons / Firearms | Knows how to draw | None | None (Only Uncensored Text Encoder is needed) |
| NSFW / Nudity | Does NOT know | None | Fine-tuning required (Train an NSFW LoRA) |
| Extreme Gore / Dismemberment | Does NOT know | None | Fine-tuning required (Train a Gore LoRA) |
There are no built-in guardrail circuits blocking output within the FLUX.2-klein-4B DiT. The reason NSFW content fails to generate is purely due to dataset deletion. Therefore, performing "Abliteration" (surgical weight removal) on the DiT is completely unnecessary and counterproductive. The only practical solution is to supplement the missing knowledge through LoRA training.
To compare the internal differences when inputting safe versus extreme prompts, we utilized the following two Python scripts:
l2_norm_spike_detector.py
A tool that monitors changes in internal energy (L2 norm) across each Transformer block layer during image generation. If a guardrail circuit activates, the energy value will abnormally spike in specific layers, allowing us to pinpoint it.threshold_drop_test.py
A tool that interpolates the semantic embedding between a safe prompt and an extreme prompt (Alpha 0.0 to 1.0) to test at which exact blend ratio the structural integrity of the image collapses (Cliff drop).(Note: To ensure pure measurement of the DiT's behavior, these tests were conducted using a mathematically uncensored Text Encoder to bypass initial input restrictions.)
To determine whether the AI was "destroying the image via guardrails" or simply "lacking knowledge," we conducted comparative experiments using minimal pairs of safe and extreme prompts.
1. Blood & Violence (Red Paint vs. Real Blood)
2. NSFW & Nudity (Silk Dress vs. Explicit Nude)
3. Weapons & Firearms (Toy Prop Gun vs. Real Lethal Firearm)
4. Extreme Dismemberment & Gore
1. Clarification of Internal Architecture (Block 4 Behavior) During our analysis, we observed a massive amplification in internal energy (L2 norm) at Transformer Block 4 (DoubleStream_Layer_4), jumping from approximately 30,000 to 330,000. At first glance, this might appear to be a strong safety filter (spike) activating at a specific layer. However, our controlled experiments confirmed that this amplification occurs equally even with completely safe prompts. Objective data proves that this numerical jump is not an output restriction, but rather a structural feature of the FLUX architecture (such as dimensional scaling).
2. DiT Abliteration is Unnecessary Since there are no explicit mechanisms (spikes) blocking specific images within the DiT, attempting to forcibly carve out internal weights using mathematical methods like SVD is a meaningless act that will only destroy the model's normal generative capabilities. To generate unsupported genres in the current FLUX model, supplementing missing knowledge via fine-tuning is the mandatory next step.
<br><br><br>
<a id="日本語-japanese"></a>
本リポジトリは、FLUX.2-klein-4Bの画像生成エンジン(DiT)の内部に、過激な画像を意図的にブロック(肉塊化・ノイズ化)する「ガードレール機構」が隠されていないかを検証するためのツールキットです。
L2ノルム(モデル内部の活性化エネルギー)の測定を行った結果、FLUX.2のDiTには、特定のプロンプトに反応して画像を意図的に壊すようなガードレールは存在しないことが確認されました。
つまり、NSFW(性的表現)やグロテスクな表現の画像が生成できない現象は、AIが描画を拒否しているからではなく、**開発元の安全対策によって学習データから該当する画像が除外されており、そもそも描き方を知らない(知識の欠如)**ことが原因だと証明されました。
DiTの内部を解析した結果、表現させたいジャンルによってモデルの状態と必要な対策が完全に分かれることが判明しました。
| ジャンル | モデルの知識 | ガードレール機構 | 必要な対応 |
|---|---|---|---|
| 流血表現(血など) | 描き方を知っている | なし | テキストエンコーダーの制限解除のみ |
| 武器・兵器表現(銃など) | 描き方を知っている | なし | 同上 |
| 性的表現(NSFWなど) | 描き方を知らない | なし | NSFW LoRA |
| 人体欠損(グロテスク表現) | 描き方を知らない | なし | Gore LoRA |
FLUX.2-klein-4BのDiTには、出力をブロックするガードレールは最初から存在しません。NSFWなどが出力されない理由は、学習データから画像が削除されていて描き方を知らないためです。 そのため、モデルの内部を削り取るような改造(Abliteration)は一切不要であり、不足している知識をLoRAなどで追加学習させることが実質的な解決策となります。
モデルの内部を解析し、安全なプロンプトと過激なプロンプトを入力した際の違いを比較するために、以下の2つのPythonスクリプトを使用しています。
l2_norm_spike_detector.py
AIが画像を生成する過程で、Transformerブロックの各層における内部エネルギー(L2ノルム)がどう変化するかを監視するツールです。ガードレールが作動した場合、特定の層で数値が異常に跳ね上がる(スパイクする)ため、それを見つけ出します。
threshold_drop_test.py
安全なプロンプトと過激なプロンプトの間で意味合いを徐々にブレンド(Alpha 0.0〜1.0)しながら画像を連続生成し、どの段階で画像が崩壊するか、またはそのまま生成されるかをテストするツールです。
(※検証にあたっては、条件を揃えるために制限を解除したテキストエンコーダーを使用し、純粋なDiT側の挙動のみを測定しています)
AIが「ガードレールで画像を壊している」のか、単に「描き方を知らない」のかを見極めるため、無難なプロンプトと過激なプロンプトの対を用いた実験を行いました。
1. 流血・暴力表現(赤いペンキ vs 本物の血)
2. 性的表現・NSFW(ドレス姿 vs ヌード)
3. 武器・兵器表現(おもちゃの銃 vs 本物の銃)
4. 極端な人体欠損・グロテスク表現
1. 内部アーキテクチャの仕様解明(Block 4の挙動) 本検証の過程で、TransformerのBlock 4(DoubleStream_Layer_4)において、内部エネルギー(L2ノルム)が約3万から約33万へと急激に増幅する現象が観測されました。一見すると特定の層で強力なフィルター(スパイク)が作動しているように見えますが、対照実験の結果、これは安全なプロンプト(Safe)であっても等しく発生することが確認されました。つまり、この数値の跳ね上がりは出力制限ではなく、FLUXの構造上の仕様(次元スケールの切り替え等)であることが客観的なデータとして証明されました。
2. モデルの重みを削る改造(Abliteration)は不要 DiT側に特定の画像をブロックする明確な機構(スパイク)が存在しない以上、SVD等の数学的手法を用いて無理にモデルの内部を削り取ろうとする試行は、正常な画像生成能力を壊してしまうだけの無意味な行為です。現在のFLUXモデルにおいて出力できないジャンルについては、追加学習による知識の補完が必須となります。