初始化项目,由ModelHub XC社区提供模型

Model: DreamFast/gemma-3-12b-it-heretic-v2
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-05-16 01:36:31 +08:00
commit cbb3303332
26 changed files with 52927 additions and 0 deletions

44
.gitattributes vendored Normal file
View File

@@ -0,0 +1,44 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q3_K_M.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q4_K_S.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q5_K_M.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q5_K_S.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q6_K.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
gguf/gemma-3-12b-it-heretic-v2-f16.gguf filter=lfs diff=lfs merge=lfs -text

209
README.md Normal file
View File

@@ -0,0 +1,209 @@
---
license: gemma
library_name: transformers
pipeline_tag: text-generation
base_model: google/gemma-3-12b-it
base_model_relation: quantized
language:
- en
tags:
- abliteration
- heretic
- uncensored
- gemma
- ltx-2
- comfyui
- video-generation
- text-encoder
- nvfp4
- blackwell
---
# Gemma 3 12B IT - Heretic v2 (Abliterated)
An abliterated version of [Google's Gemma 3 12B IT](https://huggingface.co/google/gemma-3-12b-it) created using [Heretic](https://github.com/p-e-w/heretic) v1.2.0. This model has reduced refusals while maintaining model quality, making it suitable as an uncensored text encoder for video generation models like LTX-2.
You can see the docker, scripts and configurations used to make these files on [Heretic Docker Github](https://github.com/dreamfast/heretic-docker).
## What's new in v2
- **Heretic v1.2.0** with 200 trials (v1 used v1.1.0 with 100 trials)
- **Better trial selection**: Trial 174 — 8/100 refusals at KL 0.0801 (v1: Trial 99, 7/100 refusals at KL 0.0826)
- **Vision preserved**: All ComfyUI variants keep `vision_model` and `multi_modal_projector` keys for I2V prompt enhancement
- **NVFP4 quantization**: ComfyUI-native 4-bit format for Blackwell GPUs (~3x smaller than bf16)
- **Updated GGUF support**: ComfyUI-GGUF now has merged Gemma 3 support ([PR #402](https://github.com/city96/ComfyUI-GGUF/pull/402))
## Model Details
- **Base Model:** google/gemma-3-12b-it
- **Abliteration Method:** [Heretic](https://github.com/p-e-w/heretic) v1.2.0
- **Trials:** 200
- **Trial Selected:** Trial 174
- **Refusals:** 8/100 (vs 100/100 original)
- **KL Divergence:** 0.0801 (minimal model damage)
## Files
### HuggingFace Format (for transformers, llama.cpp conversion)
```
model-00001-of-00005.safetensors
model-00002-of-00005.safetensors
model-00003-of-00005.safetensors
model-00004-of-00005.safetensors
model-00005-of-00005.safetensors
config.json
tokenizer.model
tokenizer.json
tokenizer_config.json
```
### ComfyUI Format (with vision, for LTX-2 T2V and I2V)
```
comfyui/gemma-3-12b-it-heretic-v2.safetensors # bf16, 23GB
comfyui/gemma-3-12b-it-heretic-v2_fp8_e4m3fn.safetensors # fp8, 12GB
comfyui/gemma-3-12b-it-heretic-v2_nvfp4.safetensors # nvfp4, 7.8GB
```
All ComfyUI variants include vision (`vision_model` and `multi_modal_projector` weights). The vision weights are unused during T2V (text-to-video) and add minimal overhead (~1 GB). For I2V (image-to-video) workflows using `TextGenerateLTX2Prompt` with an image input, the vision weights are required.
### GGUF Format (for llama.cpp and ComfyUI-GGUF)
| Quant | Size | Notes |
|-------|------|-------|
| F16 | 22GB | Lossless reference |
| Q8_0 | 12GB | Excellent quality |
| Q6_K | 9.0GB | Very good quality |
| Q5_K_M | 7.9GB | Good quality |
| Q5_K_S | 7.7GB | Slightly smaller Q5 |
| **Q4_K_M** | **6.8GB** | **Recommended balance** |
| Q4_K_S | 6.5GB | Smaller Q4 variant |
| Q3_K_M | 5.6GB | For low VRAM only |
```
gguf/gemma-3-12b-it-heretic-v2-f16.gguf
gguf/gemma-3-12b-it-heretic-v2-Q8_0.gguf
gguf/gemma-3-12b-it-heretic-v2-Q6_K.gguf
gguf/gemma-3-12b-it-heretic-v2-Q5_K_M.gguf
gguf/gemma-3-12b-it-heretic-v2-Q5_K_S.gguf
gguf/gemma-3-12b-it-heretic-v2-Q4_K_M.gguf
gguf/gemma-3-12b-it-heretic-v2-Q4_K_S.gguf
gguf/gemma-3-12b-it-heretic-v2-Q3_K_M.gguf
```
### NVFP4 Notes
The NVFP4 (4-bit floating point, E2M1) variants use ComfyUI's native quantization format. They are ~3x smaller than bf16 and load natively in ComfyUI without any plugins. Blackwell GPUs (RTX 5090/5080, SM100+) can use native FP4 tensor cores for best performance, but ComfyUI also supports software dequantization on older GPUs (tested working on RTX 4090).
## Do abliterated models make a difference for LTX-2?
I had a [deep dive into this topic](https://nathan.sapwell.net/posts/heretic-gemma-12b/) and found that the impact is nuanced. Abliteration does alter the embeddings Gemma produces, which slightly changes the generated video. However, there are fundamental limitations:
- **Gemma doesn't know what it wasn't trained on.** The base model was never trained on more taboo content. Abliteration removes refusals, but the model simply doesn't have knowledge of things it was never exposed to. Even chatting with the heretic model in llama.cpp, it doesn't refuse — it just doesn't know.
- **LTX-2 was trained on original Gemma embeddings.** The DiT expects the embedding distribution from the unmodified text encoder. Fine-tuning the text encoder itself would break the DiT, as it wouldn't know what to do with the new embedding distribution and would produce strange results.
- **Most abliteration happens on layer 48** (the final decision-making layer), but LTX-2 averages across all layers, which may wash out the difference.
A potential approach would be combining a fine-tuned abliterated text encoder with a LoRA trained to understand the new embeddings. LoRAs for LTX exist, but no fine-tuned text encoders have been released yet as far as I know.
That said, abliteration still removes the soft censorship in the embeddings, which can result in more faithful prompt encoding for creative content.
## Usage
### With Transformers
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model = AutoModelForCausalLM.from_pretrained(
"DreamFast/gemma-3-12b-it-heretic-v2",
device_map="auto",
torch_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained("DreamFast/gemma-3-12b-it-heretic-v2")
prompt = "Write a story about a bank heist"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
### With ComfyUI (LTX-2)
1. Download a ComfyUI format file:
- **FP8** (recommended): `comfyui/gemma-3-12b-it-heretic-v2_fp8_e4m3fn.safetensors` (12GB)
- **NVFP4** (smallest): `comfyui/gemma-3-12b-it-heretic-v2_nvfp4.safetensors` (7.8GB)
- **bf16** (full precision): `comfyui/gemma-3-12b-it-heretic-v2.safetensors` (23GB)
2. Place in `ComfyUI/models/text_encoders/`
3. In your LTX-2 workflow, use the `LTXAVTextEncoderLoader` node and select the heretic file
**Tip:** For multi-GPU setups or CPU offloading, check out [ComfyUI-LTX2-MultiGPU](https://github.com/dreamfast/ComfyUI-LTX2-MultiGPU) for optimized LTX-2 workflows.
### With ComfyUI-GGUF
GGUF support for Gemma 3 text encoders is now merged in [ComfyUI-GGUF](https://github.com/city96/ComfyUI-GGUF) ([PR #402](https://github.com/city96/ComfyUI-GGUF/pull/402)).
1. Download a GGUF file (Q4_K_M recommended for most setups)
2. Place in `ComfyUI/models/text_encoders/`
3. Use the `DualClipLoader (GGUF)` node:
- CLIP 1: the Gemma 3 GGUF file
- CLIP 2: embedding connectors from [Kijai/LTXV2_comfy](https://huggingface.co/Kijai/LTXV2_comfy/tree/main/text_encoders) (use the **dev** connectors, not distilled)
**Note:** GGUF text encoders are text-only (no vision). For I2V prompt enhancement with image input, use the safetensors variants.
### With llama.cpp
```bash
# Using llama-server
llama-server -m gemma-3-12b-it-heretic-v2-Q4_K_M.gguf
# Or with llama-cli
llama-cli -m gemma-3-12b-it-heretic-v2-Q4_K_M.gguf -p "Write a story about a bank heist"
```
## Why Abliterate?
Even when Gemma doesn't outright refuse a prompt, it may "sanitize" or weaken certain concepts in the embeddings. For video generation with LTX-2, this can result in:
- Weaker adherence to creative prompts
- Softened or altered visual outputs
- Less faithful representation of requested content
Abliteration removes this soft censorship, resulting in more faithful prompt encoding.
## Abliteration Process
Created using Heretic v1.2.0 with 200 optimization trials:
```
? Which trial do you want to use?
[Trial 80] Refusals: 0/100, KL divergence: 0.6098
[Trial 66] Refusals: 2/100, KL divergence: 0.2087
[Trial 75] Refusals: 3/100, KL divergence: 0.1378
[Trial 67] Refusals: 6/100, KL divergence: 0.1108
[Trial 180] Refusals: 7/100, KL divergence: 0.0996
> [Trial 174] Refusals: 8/100, KL divergence: 0.0801 <-- selected
[Trial 178] Refusals: 10/100, KL divergence: 0.0801
[Trial 172] Refusals: 11/100, KL divergence: 0.0708
...
```
Trial 174 was selected for its low KL divergence (0.0801), indicating minimal model damage, while achieving 8/100 refusals (92% of previously-refused prompts now work).
## Limitations
- This model inherits all limitations of the base Gemma 3 12B model
- Abliteration reduces but does not completely eliminate refusals
- NVFP4 quantization works best on Blackwell GPUs (RTX 5090/5080) with native FP4 tensor cores, but also works on older GPUs via software dequantization
## License
This model is subject to the [Gemma license](https://ai.google.dev/gemma/terms).
## Acknowledgments
- [Google](https://huggingface.co/google) for the Gemma 3 12B model
- [Heretic](https://github.com/p-e-w/heretic) by p-e-w for the abliteration tool
- [Lightricks](https://huggingface.co/Lightricks) for LTX-2
- [llama.cpp](https://github.com/ggerganov/llama.cpp) for GGUF conversion
- [ComfyUI-GGUF](https://github.com/city96/ComfyUI-GGUF) for Gemma 3 GGUF support

47
chat_template.jinja Normal file
View File

@@ -0,0 +1,47 @@
{{ bos_token }}
{%- if messages[0]['role'] == 'system' -%}
{%- if messages[0]['content'] is string -%}
{%- set first_user_prefix = messages[0]['content'] + '
' -%}
{%- else -%}
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
' -%}
{%- endif -%}
{%- set loop_messages = messages[1:] -%}
{%- else -%}
{%- set first_user_prefix = "" -%}
{%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_messages -%}
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif -%}
{%- if (message['role'] == 'assistant') -%}
{%- set role = "model" -%}
{%- else -%}
{%- set role = message['role'] -%}
{%- endif -%}
{{ '<start_of_turn>' + role + '
' + (first_user_prefix if loop.first else "") }}
{%- if message['content'] is string -%}
{{ message['content'] | trim }}
{%- elif message['content'] is iterable -%}
{%- for item in message['content'] -%}
{%- if item['type'] == 'image' -%}
{{ '<start_of_image>' }}
{%- elif item['type'] == 'text' -%}
{{ item['text'] | trim }}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{ raise_exception("Invalid content type") }}
{%- endif -%}
{{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{'<start_of_turn>model
'}}
{%- endif -%}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6a764889494d5a4c8c060e5f8e72f611d22bbc87410d51b9c1dbbf61a8089d73
size 24379468890

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:da86b974e3654d6c85ef294bc12143e9e2676a5b14227add39be62206d15b9f5
size 13205585346

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:26024289e2808bd4cf0ddc3676bfc5e2745c53b7675a03bd60d0b2ea56b16062
size 8323737296

110
config.json Normal file
View File

@@ -0,0 +1,110 @@
{
"architectures": [
"Gemma3ForConditionalGeneration"
],
"boi_token_index": 255999,
"dtype": "bfloat16",
"eoi_token_index": 256000,
"eos_token_id": [
1,
106
],
"image_token_index": 262144,
"initializer_range": 0.02,
"mm_tokens_per_image": 256,
"model_type": "gemma3",
"text_config": {
"_sliding_window_pattern": 6,
"attention_bias": false,
"attention_dropout": 0.0,
"attn_logit_softcapping": null,
"final_logit_softcapping": null,
"head_dim": 256,
"hidden_activation": "gelu_pytorch_tanh",
"hidden_size": 3840,
"initializer_range": 0.02,
"intermediate_size": 15360,
"layer_types": [
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention"
],
"max_position_embeddings": 131072,
"model_type": "gemma3_text",
"num_attention_heads": 16,
"num_hidden_layers": 48,
"num_key_value_heads": 8,
"query_pre_attn_scalar": 256,
"rms_norm_eps": 1e-06,
"rope_local_base_freq": 10000.0,
"rope_scaling": {
"factor": 8.0,
"rope_type": "linear"
},
"rope_theta": 1000000.0,
"sliding_window": 1024,
"use_bidirectional_attention": false,
"use_cache": true,
"vocab_size": 262208
},
"transformers_version": "4.57.6",
"vision_config": {
"attention_dropout": 0.0,
"hidden_act": "gelu_pytorch_tanh",
"hidden_size": 1152,
"image_size": 896,
"intermediate_size": 4304,
"layer_norm_eps": 1e-06,
"model_type": "siglip_vision_model",
"num_attention_heads": 16,
"num_channels": 3,
"num_hidden_layers": 27,
"patch_size": 14,
"vision_use_head": false
}
}

12
generation_config.json Normal file
View File

@@ -0,0 +1,12 @@
{
"bos_token_id": 2,
"do_sample": true,
"eos_token_id": [
1,
106
],
"pad_token_id": 0,
"top_k": 64,
"top_p": 0.95,
"transformers_version": "4.57.6"
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:71510a84117f8fea23cf1fac75fb4e8c1fbd972703414ead5a5b3444f9352817
size 6008817856

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:28a51c6344d11d3a86c10d412ede3effb3be3287a8f31f338cfb0b63ec45b5c8
size 7300778176

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:deebeb94aa8b5a2f577b0bbcb093304764fa7572e7d9fbbb5bb57d2be9291612
size 6935333056

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:356671c77cd08331cc1c400ec8a32b09945dcda1cd2c992bcb6554123f3479cb
size 8445036736

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:82fb79a7b6a573e481b77c245ce4e1d573fbbf4f106233c02a471bd241ab97dc
size 8231962816

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ab137e4508166b748691dc69f5230da0e9a063dbd10f9052086cd3b864c27dbb
size 9660811456

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fa99f3146e5a7e16de7a28f4f60dc34b66de9e5280b0a131e8830d1f9fb40882
size 12510212416

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4d364e5cdaa053cb9e0d491f37bb484b77d687ac00cf5fb0f99a52089675ab8f
size 23540151616

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4847447e92599833e8dbaa3067cd201c3bb5c052efa91f11ba891e43234f7832
size 4979902192

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:891bd54eed03cba9ee1e705533a02a8217fcc29f356e4a1f53e5fd0d178883ad
size 4931296592

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4cec79d4b38251251e845dbcf124a9a583f311ab7f8f34f4372bf2f1b0256b7b
size 4931296656

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d43c838a6a46725969ffb9f5c2ac8a1bad4e2b1b5c6376f5bde710ef7789865a
size 4931296656

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b61932a8389a77a644c5e1fb74480105c1d9e5f183f0255a5f92f9afde9eb50a
size 4601000928

1073
model.safetensors.index.json Normal file

File diff suppressed because it is too large Load Diff

33
special_tokens_map.json Normal file
View File

@@ -0,0 +1,33 @@
{
"boi_token": "<start_of_image>",
"bos_token": {
"content": "<bos>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"eoi_token": "<end_of_image>",
"eos_token": {
"content": "<eos>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"image_token": "<image_soft_token>",
"pad_token": {
"content": "<pad>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"unk_token": {
"content": "<unk>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d786405177734910d7a3db625c2826640964a0b4e5cdbbd70620ae3313a01bef
size 33384722

3
tokenizer.model Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c
size 4689074

51345
tokenizer_config.json Normal file

File diff suppressed because it is too large Load Diff