Spaces:
Running
on
Zero
Running
on
Zero
Elea Zhong
commited on
Commit
Β·
e63ae25
1
Parent(s):
52b011d
update
Browse files- app.py +2 -2
- qwenimage/experiments/experiments_qwen.py +32 -2
- scripts/lpips_compare.ipynb +0 -0
- scripts/visual_compare.ipynb +45 -44
app.py
CHANGED
|
@@ -34,7 +34,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 34 |
|
| 35 |
print(f"main cuda: {torch.cuda.is_available()=}")
|
| 36 |
|
| 37 |
-
exp = ExperimentRegistry.get("
|
| 38 |
exp.load()
|
| 39 |
|
| 40 |
|
|
@@ -49,7 +49,7 @@ optim_pipe()
|
|
| 49 |
MAX_SEED = np.iinfo(np.int32).max
|
| 50 |
|
| 51 |
|
| 52 |
-
@spaces.GPU
|
| 53 |
# @ftimed
|
| 54 |
def infer_camera_edit(
|
| 55 |
image,
|
|
|
|
| 34 |
|
| 35 |
print(f"main cuda: {torch.cuda.is_available()=}")
|
| 36 |
|
| 37 |
+
exp = ExperimentRegistry.get("qwen_lightning_fa3_aot_int8_fuse_downsize512")()
|
| 38 |
exp.load()
|
| 39 |
|
| 40 |
|
|
|
|
| 49 |
MAX_SEED = np.iinfo(np.int32).max
|
| 50 |
|
| 51 |
|
| 52 |
+
@spaces.GPU(duration=4)
|
| 53 |
# @ftimed
|
| 54 |
def infer_camera_edit(
|
| 55 |
image,
|
qwenimage/experiments/experiments_qwen.py
CHANGED
|
@@ -73,7 +73,7 @@ class ExperimentRegistry:
|
|
| 73 |
|
| 74 |
|
| 75 |
class PipeInputs:
|
| 76 |
-
images = Path("scripts/assets/test_images_v1/").
|
| 77 |
|
| 78 |
camera_params = {
|
| 79 |
"rotate_deg": [-90,-45,0,45,90],
|
|
@@ -807,6 +807,36 @@ class Qwen_Lightning_FA3_AoT_int8_fuse_2step_FBCache055_Downsize512(Qwen_Lightni
|
|
| 807 |
kwargs["num_inference_steps"] = 2
|
| 808 |
return self.pipe(*args, **kwargs).images[0]
|
| 809 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 810 |
@ExperimentRegistry.register(name="qwen_lightning_fa3_aot_int8_fuse_1step_fbcache_055_downsize512")
|
| 811 |
class Qwen_Lightning_FA3_AoT_int8_fuse_1step_FBCache055_Downsize512(Qwen_Lightning_Lora):
|
| 812 |
size = 512
|
|
@@ -814,7 +844,7 @@ class Qwen_Lightning_FA3_AoT_int8_fuse_1step_FBCache055_Downsize512(Qwen_Lightni
|
|
| 814 |
def optimize(self):
|
| 815 |
self.pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 816 |
self.pipe.transformer.fuse_qkv_projections()
|
| 817 |
-
|
| 818 |
optimize_pipeline_(
|
| 819 |
self.pipe,
|
| 820 |
cache_compiled=self.config.cache_compiled,
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
class PipeInputs:
|
| 76 |
+
images = list(Path("scripts/assets/test_images_v1/").glob("*.jpg"))
|
| 77 |
|
| 78 |
camera_params = {
|
| 79 |
"rotate_deg": [-90,-45,0,45,90],
|
|
|
|
| 807 |
kwargs["num_inference_steps"] = 2
|
| 808 |
return self.pipe(*args, **kwargs).images[0]
|
| 809 |
|
| 810 |
+
@ExperimentRegistry.register(name="qwen_lightning_fa3_aot_int8_fuse_downsize512")
|
| 811 |
+
class Qwen_Lightning_FA3_AoT_int8_fuse_Downsize512(Qwen_Lightning_Lora):
|
| 812 |
+
size = 512
|
| 813 |
+
@ftimed
|
| 814 |
+
def optimize(self):
|
| 815 |
+
self.pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 816 |
+
self.pipe.transformer.fuse_qkv_projections()
|
| 817 |
+
optimize_pipeline_(
|
| 818 |
+
self.pipe,
|
| 819 |
+
cache_compiled=self.config.cache_compiled,
|
| 820 |
+
quantize=True,
|
| 821 |
+
suffix="_fa3_fuse",
|
| 822 |
+
pipe_kwargs={
|
| 823 |
+
"image": [Image.new("RGB", (1024, 1024))],
|
| 824 |
+
"prompt":"prompt",
|
| 825 |
+
"num_inference_steps":4
|
| 826 |
+
}
|
| 827 |
+
)
|
| 828 |
+
def run_once(self, *args, **kwargs):
|
| 829 |
+
image = kwargs["image"][0]
|
| 830 |
+
w,h = image.size
|
| 831 |
+
real_w, real_h = calculate_dimensions(1024 * 1024, w / h)
|
| 832 |
+
down_w, down_h = calculate_dimensions(self.size * self.size, w / h)
|
| 833 |
+
image = image.resize((down_w, down_h))
|
| 834 |
+
kwargs["image"] = [image]
|
| 835 |
+
kwargs["vae_image_override"] = self.size * self.size
|
| 836 |
+
kwargs["width"] = real_w
|
| 837 |
+
kwargs["height"] = real_h
|
| 838 |
+
return self.pipe(*args, **kwargs).images[0]
|
| 839 |
+
|
| 840 |
@ExperimentRegistry.register(name="qwen_lightning_fa3_aot_int8_fuse_1step_fbcache_055_downsize512")
|
| 841 |
class Qwen_Lightning_FA3_AoT_int8_fuse_1step_FBCache055_Downsize512(Qwen_Lightning_Lora):
|
| 842 |
size = 512
|
|
|
|
| 844 |
def optimize(self):
|
| 845 |
self.pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 846 |
self.pipe.transformer.fuse_qkv_projections()
|
| 847 |
+
apply_cache_on_pipe(self.pipe, residual_diff_threshold=0.55,)
|
| 848 |
optimize_pipeline_(
|
| 849 |
self.pipe,
|
| 850 |
cache_compiled=self.config.cache_compiled,
|
scripts/lpips_compare.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/visual_compare.ipynb
CHANGED
|
@@ -33,18 +33,18 @@
|
|
| 33 |
" warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n",
|
| 34 |
"Skipping import of cpp extensions due to incompatible torch version 2.9.1+cu128 for torchao version 0.14.1 Please see https://github.com/pytorch/ao/issues/2919 for more info\n",
|
| 35 |
"TMA benchmarks will be running without grid constant TMA descriptor.\n",
|
| 36 |
-
"2025-11-15 00:
|
| 37 |
-
"2025-11-15 00:
|
| 38 |
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
|
| 39 |
-
"E0000 00:00:
|
| 40 |
-
"E0000 00:00:
|
| 41 |
-
"W0000 00:00:
|
| 42 |
-
"W0000 00:00:
|
| 43 |
-
"W0000 00:00:
|
| 44 |
-
"W0000 00:00:
|
| 45 |
-
"2025-11-15 00:
|
| 46 |
"To enable the following instructions: AVX512F AVX512_VNNI AVX512_BF16 AVX512_FP16 AVX_VNNI, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
|
| 47 |
-
"Fetching 7 files: 100%|ββββββββββ| 7/7 [00:00<00:00,
|
| 48 |
]
|
| 49 |
}
|
| 50 |
],
|
|
@@ -68,6 +68,7 @@
|
|
| 68 |
"experiment_names = [\n",
|
| 69 |
" \"qwen_base\",\n",
|
| 70 |
" \"qwen_lightning_fa3_aot_int8_fuse_4step_fbcache_055_downsize512\",\n",
|
|
|
|
| 71 |
" \"qwen_lightning_fa3_aot_int8_fuse_1step_fbcache_055_downsize512\",\n",
|
| 72 |
"]\n",
|
| 73 |
"\n",
|
|
@@ -187,40 +188,40 @@
|
|
| 187 |
"name": "stdout",
|
| 188 |
"output_type": "stream",
|
| 189 |
"text": [
|
| 190 |
-
"Saved comparison grid 1/32 to reports/
|
| 191 |
-
"Saved comparison grid 2/32 to reports/
|
| 192 |
-
"Saved comparison grid 3/32 to reports/
|
| 193 |
-
"Saved comparison grid 4/32 to reports/
|
| 194 |
-
"Saved comparison grid 5/32 to reports/
|
| 195 |
-
"Saved comparison grid 6/32 to reports/
|
| 196 |
-
"Saved comparison grid 7/32 to reports/
|
| 197 |
-
"Saved comparison grid 8/32 to reports/
|
| 198 |
-
"Saved comparison grid 9/32 to reports/
|
| 199 |
-
"Saved comparison grid 10/32 to reports/
|
| 200 |
-
"Saved comparison grid 11/32 to reports/
|
| 201 |
-
"Saved comparison grid 12/32 to reports/
|
| 202 |
-
"Saved comparison grid 13/32 to reports/
|
| 203 |
-
"Saved comparison grid 14/32 to reports/
|
| 204 |
-
"Saved comparison grid 15/32 to reports/
|
| 205 |
-
"Saved comparison grid 16/32 to reports/
|
| 206 |
-
"Saved comparison grid 17/32 to reports/
|
| 207 |
-
"Saved comparison grid 18/32 to reports/
|
| 208 |
-
"Saved comparison grid 19/32 to reports/
|
| 209 |
-
"Saved comparison grid 20/32 to reports/
|
| 210 |
-
"Saved comparison grid 21/32 to reports/
|
| 211 |
-
"Saved comparison grid 22/32 to reports/
|
| 212 |
-
"Saved comparison grid 23/32 to reports/
|
| 213 |
-
"Saved comparison grid 24/32 to reports/
|
| 214 |
-
"Saved comparison grid 25/32 to reports/
|
| 215 |
-
"Saved comparison grid 26/32 to reports/
|
| 216 |
-
"Saved comparison grid 27/32 to reports/
|
| 217 |
-
"Saved comparison grid 28/32 to reports/
|
| 218 |
-
"Saved comparison grid 29/32 to reports/
|
| 219 |
-
"Saved comparison grid 30/32 to reports/
|
| 220 |
-
"Saved comparison grid 31/32 to reports/
|
| 221 |
-
"Saved comparison grid 32/32 to reports/
|
| 222 |
"\n",
|
| 223 |
-
"All comparison grids saved to reports/
|
| 224 |
]
|
| 225 |
}
|
| 226 |
],
|
|
@@ -237,7 +238,7 @@
|
|
| 237 |
"font_path = Path(\"scripts/assets/STSong.ttf\")\n",
|
| 238 |
"chinese_font = fm.FontProperties(fname=str(font_path))\n",
|
| 239 |
"\n",
|
| 240 |
-
"comparison_dir = report_dir / \"
|
| 241 |
"comparison_dir.mkdir(exist_ok=True, parents=True)\n",
|
| 242 |
"\n",
|
| 243 |
"# Create PipeInputs instance to access original images and prompts\n",
|
|
|
|
| 33 |
" warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n",
|
| 34 |
"Skipping import of cpp extensions due to incompatible torch version 2.9.1+cu128 for torchao version 0.14.1 Please see https://github.com/pytorch/ao/issues/2919 for more info\n",
|
| 35 |
"TMA benchmarks will be running without grid constant TMA descriptor.\n",
|
| 36 |
+
"2025-11-15 00:36:46.660289: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
|
| 37 |
+
"2025-11-15 00:36:46.674159: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:467] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
|
| 38 |
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
|
| 39 |
+
"E0000 00:00:1763167006.691103 1407426 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
|
| 40 |
+
"E0000 00:00:1763167006.696561 1407426 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
|
| 41 |
+
"W0000 00:00:1763167006.709712 1407426 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
|
| 42 |
+
"W0000 00:00:1763167006.709728 1407426 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
|
| 43 |
+
"W0000 00:00:1763167006.709731 1407426 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
|
| 44 |
+
"W0000 00:00:1763167006.709732 1407426 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n",
|
| 45 |
+
"2025-11-15 00:36:46.713796: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
|
| 46 |
"To enable the following instructions: AVX512F AVX512_VNNI AVX512_BF16 AVX512_FP16 AVX_VNNI, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
|
| 47 |
+
"Fetching 7 files: 100%|ββββββββββ| 7/7 [00:00<00:00, 77467.36it/s]\n"
|
| 48 |
]
|
| 49 |
}
|
| 50 |
],
|
|
|
|
| 68 |
"experiment_names = [\n",
|
| 69 |
" \"qwen_base\",\n",
|
| 70 |
" \"qwen_lightning_fa3_aot_int8_fuse_4step_fbcache_055_downsize512\",\n",
|
| 71 |
+
" \"qwen_lightning_fa3_aot_int8_fuse_2step_fbcache_055_downsize512\",\n",
|
| 72 |
" \"qwen_lightning_fa3_aot_int8_fuse_1step_fbcache_055_downsize512\",\n",
|
| 73 |
"]\n",
|
| 74 |
"\n",
|
|
|
|
| 188 |
"name": "stdout",
|
| 189 |
"output_type": "stream",
|
| 190 |
"text": [
|
| 191 |
+
"Saved comparison grid 1/32 to reports/comparison_grid_5/comparison_000.jpg\n",
|
| 192 |
+
"Saved comparison grid 2/32 to reports/comparison_grid_5/comparison_001.jpg\n",
|
| 193 |
+
"Saved comparison grid 3/32 to reports/comparison_grid_5/comparison_002.jpg\n",
|
| 194 |
+
"Saved comparison grid 4/32 to reports/comparison_grid_5/comparison_003.jpg\n",
|
| 195 |
+
"Saved comparison grid 5/32 to reports/comparison_grid_5/comparison_004.jpg\n",
|
| 196 |
+
"Saved comparison grid 6/32 to reports/comparison_grid_5/comparison_005.jpg\n",
|
| 197 |
+
"Saved comparison grid 7/32 to reports/comparison_grid_5/comparison_006.jpg\n",
|
| 198 |
+
"Saved comparison grid 8/32 to reports/comparison_grid_5/comparison_007.jpg\n",
|
| 199 |
+
"Saved comparison grid 9/32 to reports/comparison_grid_5/comparison_008.jpg\n",
|
| 200 |
+
"Saved comparison grid 10/32 to reports/comparison_grid_5/comparison_009.jpg\n",
|
| 201 |
+
"Saved comparison grid 11/32 to reports/comparison_grid_5/comparison_010.jpg\n",
|
| 202 |
+
"Saved comparison grid 12/32 to reports/comparison_grid_5/comparison_011.jpg\n",
|
| 203 |
+
"Saved comparison grid 13/32 to reports/comparison_grid_5/comparison_012.jpg\n",
|
| 204 |
+
"Saved comparison grid 14/32 to reports/comparison_grid_5/comparison_013.jpg\n",
|
| 205 |
+
"Saved comparison grid 15/32 to reports/comparison_grid_5/comparison_014.jpg\n",
|
| 206 |
+
"Saved comparison grid 16/32 to reports/comparison_grid_5/comparison_015.jpg\n",
|
| 207 |
+
"Saved comparison grid 17/32 to reports/comparison_grid_5/comparison_016.jpg\n",
|
| 208 |
+
"Saved comparison grid 18/32 to reports/comparison_grid_5/comparison_017.jpg\n",
|
| 209 |
+
"Saved comparison grid 19/32 to reports/comparison_grid_5/comparison_018.jpg\n",
|
| 210 |
+
"Saved comparison grid 20/32 to reports/comparison_grid_5/comparison_019.jpg\n",
|
| 211 |
+
"Saved comparison grid 21/32 to reports/comparison_grid_5/comparison_020.jpg\n",
|
| 212 |
+
"Saved comparison grid 22/32 to reports/comparison_grid_5/comparison_021.jpg\n",
|
| 213 |
+
"Saved comparison grid 23/32 to reports/comparison_grid_5/comparison_022.jpg\n",
|
| 214 |
+
"Saved comparison grid 24/32 to reports/comparison_grid_5/comparison_023.jpg\n",
|
| 215 |
+
"Saved comparison grid 25/32 to reports/comparison_grid_5/comparison_024.jpg\n",
|
| 216 |
+
"Saved comparison grid 26/32 to reports/comparison_grid_5/comparison_025.jpg\n",
|
| 217 |
+
"Saved comparison grid 27/32 to reports/comparison_grid_5/comparison_026.jpg\n",
|
| 218 |
+
"Saved comparison grid 28/32 to reports/comparison_grid_5/comparison_027.jpg\n",
|
| 219 |
+
"Saved comparison grid 29/32 to reports/comparison_grid_5/comparison_028.jpg\n",
|
| 220 |
+
"Saved comparison grid 30/32 to reports/comparison_grid_5/comparison_029.jpg\n",
|
| 221 |
+
"Saved comparison grid 31/32 to reports/comparison_grid_5/comparison_030.jpg\n",
|
| 222 |
+
"Saved comparison grid 32/32 to reports/comparison_grid_5/comparison_031.jpg\n",
|
| 223 |
"\n",
|
| 224 |
+
"All comparison grids saved to reports/comparison_grid_5\n"
|
| 225 |
]
|
| 226 |
}
|
| 227 |
],
|
|
|
|
| 238 |
"font_path = Path(\"scripts/assets/STSong.ttf\")\n",
|
| 239 |
"chinese_font = fm.FontProperties(fname=str(font_path))\n",
|
| 240 |
"\n",
|
| 241 |
+
"comparison_dir = report_dir / \"comparison_grid_5\"\n",
|
| 242 |
"comparison_dir.mkdir(exist_ok=True, parents=True)\n",
|
| 243 |
"\n",
|
| 244 |
"# Create PipeInputs instance to access original images and prompts\n",
|