Views
No views yet
FireRed-Image-Edit-1.0-8bit is an 8-bit quantized edition of FireRed-Image-Edit-1.0 (FireRedTeam), engineered to deliver the same instruction-driven diffusion transformer image editing capabilities with significantly reduced memory footprint and improved inference efficiency. Built upon the original 1.6B-sample training corpus refined into over 100M high-quality text-to-image and editing pairs through cleaning, stratification, auto-labeling, and dual-stage semantic filtering, this quantized release preserves the model’s multi-stage training pipeline, including large-scale pre-training, supervised fine-tuning, and reinforcement learning with techniques such as Multi-Condition Aware Bucket Sampling for variable resolutions, Stochastic Instruction Alignment, Asymmetric Gradient Optimization for stable DPO, DiffusionNFT with layout-OCR rewards for precise text editing, and differentiable Consistency Loss for strong identity preservation. The 8-bit quantization reduces VRAM requirements and accelerates deployment while maintaining high alignment, semantic consistency, and visual fidelity across diverse editing scenarios such as photo restoration, object insertion and modification, style transfer with text fidelity, multi-image virtual try-on, and layout-aware text editing. Optimized for practical workflows and ComfyUI integration, this version enables broader accessibility on consumer-grade GPUs without substantial quality degradation, making it suitable for research, production, and lightweight deployment environments.
1transformers # - transformers@v4.57.6
2torch # - torch@v2.9.1+cu128
3diffusers # - diffusers@v0.37.0.dev0
4bitsandbytes # - bitsandbytes@v0.49.2
5gradio # - gradio@v6.6.0
6accelerate # - accelerate@v1.12.01import os
2import gc
3import gradio as gr
4import numpy as np
5#import spaces # Uncomment the Spaces-related modules if you are using HF ZeroGPU
6
7import torch
8import random
9from PIL import Image
10
11device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
13print("CUDA_VISIBLE_DEVICES=", os.environ.get("CUDA_VISIBLE_DEVICES"))
14print("torch.__version__ =", torch.__version__)
15print("Using device:", device)
16
17from diffusers.models import QwenImageTransformer2DModel
18from diffusers import QwenImageEditPlusPipeline
19from diffusers.utils import load_image
20
21dtype = torch.bfloat16
22
23transformer = QwenImageTransformer2DModel.from_pretrained(
24 "prithivMLmods/FireRed-Image-Edit-1.0-8bit",
25 subfolder="transformer",
26 torch_dtype=dtype
27)
28
29pipe = QwenImageEditPlusPipeline.from_pretrained(
30 "prithivMLmods/FireRed-Image-Edit-1.0-8bit",
31 transformer=transformer,
32 torch_dtype=dtype
33).to(device)
34
35MAX_SEED = np.iinfo(np.int32).max
36
37def update_dimensions_on_upload(image):
38 if image is None:
39 return 1024, 1024
40
41 original_width, original_height = image.size
42
43 if original_width > original_height:
44 new_width = 1024
45 aspect_ratio = original_height / original_width
46 new_height = int(new_width * aspect_ratio)
47 else:
48 new_height = 1024
49 aspect_ratio = original_width / original_height
50 new_width = int(new_height * aspect_ratio)
51
52 new_width = (new_width // 8) * 8
53 new_height = (new_height // 8) * 8
54
55 return new_width, new_height
56
57#@spaces.GPU
58def infer(
59 images,
60 prompt,
61 seed,
62 randomize_seed,
63 guidance_scale,
64 steps,
65 progress=gr.Progress(track_tqdm=True)
66):
67 gc.collect()
68 torch.cuda.empty_cache()
69
70 if not images:
71 raise gr.Error("Please upload at least one image to edit.")
72
73 pil_images = []
74 if images is not None:
75 for item in images:
76 try:
77 if isinstance(item, tuple) or isinstance(item, list):
78 path_or_img = item[0]
79 else:
80 path_or_img = item
81
82 if isinstance(path_or_img, str):
83 pil_images.append(Image.open(path_or_img).convert("RGB"))
84 elif isinstance(path_or_img, Image.Image):
85 pil_images.append(path_or_img.convert("RGB"))
86 else:
87 pil_images.append(Image.open(path_or_img.name).convert("RGB"))
88 except Exception as e:
89 print(f"Skipping invalid image item: {e}")
90 continue
91
92 if not pil_images:
93 raise gr.Error("Could not process uploaded images.")
94
95 if randomize_seed:
96 seed = random.randint(0, MAX_SEED)
97
98 generator = torch.Generator(device=device).manual_seed(seed)
99 negative_prompt = "worst quality, low quality, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry"
100
101 width, height = update_dimensions_on_upload(pil_images[0])
102
103 try:
104 result_image = pipe(
105 image=pil_images,
106 prompt=prompt,
107 negative_prompt=negative_prompt,
108 height=height,
109 width=width,
110 num_inference_steps=steps,
111 generator=generator,
112 true_cfg_scale=guidance_scale,
113 ).images[0]
114
115 return result_image, seed
116
117 except Exception as e:
118 raise e
119 finally:
120 gc.collect()
121 torch.cuda.empty_cache()
122
123#@spaces.GPU
124def infer_example(images, prompt):
125 if not images:
126 return None, 0
127
128 if isinstance(images, str):
129 images_list = [images]
130 else:
131 images_list = images
132
133 result, seed = infer(
134 images=images_list,
135 prompt=prompt,
136 seed=0,
137 randomize_seed=True,
138 guidance_scale=1.0,
139 steps=20
140 )
141 return result, seed
142
143css="""
144#col-container {
145 margin: 0 auto;
146 max-width: 1000px;
147}
148#main-title h1 {font-size: 2.4em !important;}
149"""
150
151with gr.Blocks() as demo:
152 with gr.Column(elem_id="col-container"):
153 gr.Markdown("# **FireRed-Image-Edit-1.0-8bit**", elem_id="main-title")
154
155 with gr.Row(equal_height=True):
156 with gr.Column():
157 images = gr.Gallery(
158 label="Upload Images",
159 type="filepath",
160 columns=2,
161 rows=1,
162 height=300,
163 allow_preview=True
164 )
165
166 with gr.Row():
167 prompt = gr.Text(
168 label="Edit Prompt",
169 show_label=True,
170 placeholder="e.g., transform into anime..",
171 )
172
173 with gr.Row():
174 run_button = gr.Button("Edit Image", variant="primary")
175
176 with gr.Column():
177 output_image = gr.Image(label="Output Image", interactive=False, format="png", height=390)
178
179 with gr.Accordion("Advanced Settings", open=False, visible=True):
180 seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
181 randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
182 guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
183 steps = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=20)
184
185 run_button.click(
186 fn=infer,
187 inputs=[images, prompt, seed, randomize_seed, guidance_scale, steps],
188 outputs=[output_image, seed]
189 )
190
191if __name__ == "__main__":
192 demo.queue(max_size=30).launch(css=css, mcp_server=True, ssr_mode=False, show_error=True)[!IMPORTANT] This repository follows the same release notes, terms and conditions, and license as the original model page, FireRed-Image-Edit-1.0.