Diffusers
Safetensors
qwen3_vl
qwen
qwen3-vl
text-encoder
vision-encoder
heretic
abliteration
prompt-adherence
Instructions to use catplusplus/Qwen21_Text_Encoder_Heretic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use catplusplus/Qwen21_Text_Encoder_Heretic with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("catplusplus/Qwen21_Text_Encoder_Heretic", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
File size: 4,342 Bytes
7b00440 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | # -*- coding: utf-8 -*-
"""Verification & Comparison of Heretic Decensored Text Encoder on Qwen-Image-2.1.
Generates identical text-to-image scenes comparing:
1. Base / Stock Qwen3-VL Text Encoder (Safety Aligned / Blush Vector)
2. Heretic Qwen3-VL Text Encoder (Abliterated / Hesitation-Free)
Target Prompt:
"Two cute anime girls in colorful bikinis playing beach volleyball on a sunny tropical beach,
dynamic action pose, jumping to spike the ball, sharp focus, vibrant anime style,
detailed background with ocean and palm trees"
"""
import os
import sys
import time
import shutil
import torch
from PIL import Image
ROOT_DIR = "/auto/home/amano/olegk/Nikola"
for p in [f"{ROOT_DIR}/packages/nunchaku", f"{ROOT_DIR}/packages/deepcompressor", f"{ROOT_DIR}/src/imagegen", ROOT_DIR]:
if p not in sys.path:
sys.path.insert(0, p)
from QwenImage21NVFP4Backend import QwenImage21NVFP4Backend
PROMPT = (
"Two cute anime girls in colorful bikinis playing beach volleyball on a sunny tropical beach, "
"dynamic action pose, jumping to spike the ball, sharp focus, vibrant anime style, "
"detailed background with ocean and palm trees"
)
SEED = 42
STEPS = 25
GUIDANCE_SCALE = 1.0
HEIGHT = 1024
WIDTH = 1024
TMP_DIR = "/home/olegk/tmp"
ARTIFACT_DIR = "/home/olegk/.gemini/antigravity/brain/19d2cb51-1ef6-42f5-a95f-f814fe6ba720"
HERETIC_PATH = "/home/olegk/Nikola/models/Qwen21_Text_Encoder_Heretic"
def generate_with_backend(backend_name: str, text_encoder_path=None):
print(f"\n{'='*70}")
print(f"๐ RUNNING GENERATION: {backend_name}")
print(f"Text Encoder Path: {text_encoder_path or 'Stock (Base Qwen-Image-2.1)'}")
print(f"{'='*70}")
backend = QwenImage21NVFP4Backend(
model_id="/home/olegk/Nikola/models/Qwen/Qwen-Image-2.1",
optimized_model_path="/home/olegk/Nikola/models/nunchaku-qwen-image-2.1/best_quality_fp4.safetensors",
gpu_id=0,
enable_tiling=True,
dynamic_scale_k=0.0,
stream_text_encoder=True,
text_encoder_path=text_encoder_path,
)
t0 = time.perf_counter()
pipeline, _ = backend.load()
t_load = time.perf_counter() - t0
print(f"Backend loaded in {t_load:.2f} s")
generator = torch.Generator(device="cuda:0").manual_seed(SEED)
torch.cuda.synchronize()
t_gen_start = time.perf_counter()
output = pipeline(
prompt=PROMPT,
height=HEIGHT,
width=WIDTH,
num_inference_steps=STEPS,
true_cfg_scale=GUIDANCE_SCALE,
generator=generator,
)
torch.cuda.synchronize()
t_gen = time.perf_counter() - t_gen_start
print(f"Generation completed in {t_gen:.2f} s")
img = output.images[0]
# Clean up pipeline from GPU memory
del pipeline
del backend
torch.cuda.empty_cache()
return img, t_gen
def main():
os.makedirs(TMP_DIR, exist_ok=True)
os.makedirs(ARTIFACT_DIR, exist_ok=True)
print("=" * 80)
print("๐ ANIME BEACH VOLLEYBALL TEXT ENCODER COMPARISON TEST")
print(f"Prompt: {PROMPT}")
print(f"Seed: {SEED} | Steps: {STEPS} | CFG: {GUIDANCE_SCALE}")
print("=" * 80)
# 1. Run Stock Text Encoder
img_stock, t_stock = generate_with_backend("STOCK (Base Qwen-Image-2.1 Text Encoder)", text_encoder_path=None)
stock_path = os.path.join(TMP_DIR, "qwen21_stock_beach_volleyball.png")
stock_art = os.path.join(ARTIFACT_DIR, "qwen21_stock_beach_volleyball.png")
img_stock.save(stock_path)
shutil.copy(stock_path, stock_art)
print(f"Saved stock image to: {stock_path} and artifact")
# 2. Run Heretic Text Encoder
img_heretic, t_heretic = generate_with_backend(
"HERETIC (Decensored Qwen3-VL Text Encoder)",
text_encoder_path=HERETIC_PATH,
)
heretic_path = os.path.join(TMP_DIR, "qwen21_heretic_beach_volleyball.png")
heretic_art = os.path.join(ARTIFACT_DIR, "qwen21_heretic_beach_volleyball.png")
img_heretic.save(heretic_path)
shutil.copy(heretic_path, heretic_art)
print(f"Saved heretic image to: {heretic_path} and artifact")
print("\n" + "=" * 80)
print("๐ COMPARISON TEST COMPLETED SUCCESSFULLY!")
print(f"Stock Image: {stock_path} ({t_stock:.2f} s)")
print(f"Heretic Image: {heretic_path} ({t_heretic:.2f} s)")
print("=" * 80)
if __name__ == "__main__":
main()
|