ford442 commited on
Commit
e121929
·
verified ·
1 Parent(s): 55c346e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -7,6 +7,18 @@
7
  import spaces
8
 
9
  import os
 
 
 
 
 
 
 
 
 
 
 
 
10
  import random
11
  import uuid
12
  import gradio as gr
@@ -28,25 +40,20 @@ from gradio import themes
28
  from image_gen_aux import UpscaleWithModel
29
  #from diffusers.models.attention_processor import AttnProcessor2_0
30
 
31
- torch.backends.cuda.matmul.allow_tf32 = False
32
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
33
  torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
34
- torch.backends.cudnn.allow_tf32 = False
35
  torch.backends.cudnn.deterministic = False
36
- torch.backends.cudnn.benchmark = False
37
- #torch.backends.cuda.preferred_blas_library="cublas"
38
- # torch.backends.cuda.preferred_linalg_library="cusolver"
39
-
40
  torch.set_float32_matmul_precision("highest")
41
- os.putenv("HF_HUB_ENABLE_HF_TRANSFER","1")
42
-
43
- os.environ["SAFETENSORS_FAST_GPU"] = "1"
44
  FTP_HOST = "1ink.us"
45
  FTP_USER = "ford442"
46
  FTP_PASS = os.getenv("FTP_PASS")
47
  FTP_DIR = "1ink.us/stable_diff/" # Remote directory on FTP server
48
 
49
-
50
  DESCRIPTIONXX = """
51
  ## ⚡⚡⚡⚡ REALVISXL V5.0 BF16 (Tester A) ⚡⚡⚡⚡
52
  """
@@ -116,7 +123,7 @@ def load_and_prepare_model():
116
  #vaeX = AutoencoderKL.from_pretrained('ford442/Juggernaut-XI-v11-fp32',subfolder='vae') # ,use_safetensors=True FAILS
117
  #unetX = UNet2DConditionModel.from_pretrained('ford442/RealVisXL_V5.0_BF16',subfolder='unet').to(torch.bfloat16) # ,use_safetensors=True FAILS
118
  #sched = EulerAncestralDiscreteScheduler.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='scheduler',beta_schedule="scaled_linear", steps_offset=1,timestep_spacing="trailing"))
119
- sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1,use_karras_sigmas=False)
120
  #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear")
121
  #sched = DPMSolverSDEScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler')
122
  #pipeX = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V5.0").to(torch.bfloat16)
@@ -214,7 +221,8 @@ def load_and_prepare_model():
214
  #pipe.unet.set_default_attn_processor()
215
 
216
  #**** BETTER WAY ****#
217
- pipe.to(device, torch.bfloat16)
 
218
  #**** BETTER WAY ****#
219
 
220
  #pipe.to(device)
@@ -326,7 +334,8 @@ def generate_30(
326
  #gc.collect()
327
  torch.set_float32_matmul_precision("medium")
328
  with torch.no_grad():
329
- upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
 
330
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
331
  downscale_path = f"rv50_upscale_{timestamp}.png"
332
  downscale1.save(downscale_path,optimize=False,compress_level=0)
@@ -382,7 +391,8 @@ def generate_60(
382
  #gc.collect()
383
  torch.set_float32_matmul_precision("medium")
384
  with torch.no_grad():
385
- upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
 
386
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
387
  downscale_path = f"rv50_upscale_{timestamp}.png"
388
  downscale1.save(downscale_path,optimize=False,compress_level=0)
@@ -438,7 +448,8 @@ def generate_90(
438
  #gc.collect()
439
  torch.set_float32_matmul_precision("medium")
440
  with torch.no_grad():
441
- upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
 
442
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
443
  downscale_path = f"rv50_upscale_{timestamp}.png"
444
  downscale1.save(downscale_path,optimize=False,compress_level=0)
 
7
  import spaces
8
 
9
  import os
10
+
11
+ os.putenv('PYTORCH_NVML_BASED_CUDA_CHECK','1')
12
+ os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
13
+ alloc_conf_parts = [
14
+ 'expandable_segments:True',
15
+ 'pinned_use_background_threads:True' # Specific to pinned memory.
16
+ ]
17
+ os.environ['PYTORCH_CUDA_ALLOC_CONF'] = ','.join(alloc_conf_parts)
18
+ os.environ["SAFETENSORS_FAST_GPU"] = "1"
19
+ os.putenv('HF_HUB_ENABLE_HF_TRANSFER','1')
20
+
21
+
22
  import random
23
  import uuid
24
  import gradio as gr
 
40
  from image_gen_aux import UpscaleWithModel
41
  #from diffusers.models.attention_processor import AttnProcessor2_0
42
 
43
+ torch.backends.cuda.matmul.allow_tf32 = True
44
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
45
  torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
46
+ torch.backends.cudnn.allow_tf32 = True
47
  torch.backends.cudnn.deterministic = False
48
+ torch.backends.cudnn.benchmark = True
49
+ torch.backends.cuda.preferred_blas_library="cublas"
50
+ torch.backends.cuda.preferred_linalg_library="cusolver"
 
51
  torch.set_float32_matmul_precision("highest")
 
 
 
52
  FTP_HOST = "1ink.us"
53
  FTP_USER = "ford442"
54
  FTP_PASS = os.getenv("FTP_PASS")
55
  FTP_DIR = "1ink.us/stable_diff/" # Remote directory on FTP server
56
 
 
57
  DESCRIPTIONXX = """
58
  ## ⚡⚡⚡⚡ REALVISXL V5.0 BF16 (Tester A) ⚡⚡⚡⚡
59
  """
 
123
  #vaeX = AutoencoderKL.from_pretrained('ford442/Juggernaut-XI-v11-fp32',subfolder='vae') # ,use_safetensors=True FAILS
124
  #unetX = UNet2DConditionModel.from_pretrained('ford442/RealVisXL_V5.0_BF16',subfolder='unet').to(torch.bfloat16) # ,use_safetensors=True FAILS
125
  #sched = EulerAncestralDiscreteScheduler.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='scheduler',beta_schedule="scaled_linear", steps_offset=1,timestep_spacing="trailing"))
126
+ sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler') #,beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1,use_karras_sigmas=False)
127
  #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear")
128
  #sched = DPMSolverSDEScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler')
129
  #pipeX = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V5.0").to(torch.bfloat16)
 
221
  #pipe.unet.set_default_attn_processor()
222
 
223
  #**** BETTER WAY ****#
224
+ #pipe.to(device, torch.bfloat16)
225
+ pipe.to(device)
226
  #**** BETTER WAY ****#
227
 
228
  #pipe.to(device)
 
334
  #gc.collect()
335
  torch.set_float32_matmul_precision("medium")
336
  with torch.no_grad():
337
+ upscalea = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
338
+ upscale = upscaler(upscalea, tiling=True, tile_width=256, tile_height=256)
339
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
340
  downscale_path = f"rv50_upscale_{timestamp}.png"
341
  downscale1.save(downscale_path,optimize=False,compress_level=0)
 
391
  #gc.collect()
392
  torch.set_float32_matmul_precision("medium")
393
  with torch.no_grad():
394
+ upscalea = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
395
+ upscale = upscaler(upscalea, tiling=True, tile_width=256, tile_height=256)
396
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
397
  downscale_path = f"rv50_upscale_{timestamp}.png"
398
  downscale1.save(downscale_path,optimize=False,compress_level=0)
 
448
  #gc.collect()
449
  torch.set_float32_matmul_precision("medium")
450
  with torch.no_grad():
451
+ upscalea = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
452
+ upscale = upscaler(upscalea, tiling=True, tile_width=256, tile_height=256)
453
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
454
  downscale_path = f"rv50_upscale_{timestamp}.png"
455
  downscale1.save(downscale_path,optimize=False,compress_level=0)