developerskyebrowse commited on
Commit
9e112ae
·
1 Parent(s): 6dbb9c3

trying again

Browse files
Files changed (1) hide show
  1. app.py +69 -69
app.py CHANGED
@@ -31,79 +31,79 @@ compiled = False
31
 
32
  import spaces
33
 
34
- if gr.NO_RELOAD:
35
- torch.cuda.max_memory_allocated(device="cuda")
36
 
37
- # Controlnet Normal
38
- model_id = "lllyasviel/control_v11p_sd15_normalbae"
39
- print("initializing controlnet")
40
- controlnet = ControlNetModel.from_pretrained(
41
- model_id,
42
- torch_dtype=torch.float16,
43
- attn_implementation="flash_attention_2",
44
- ).to("cuda")
45
-
46
- # Scheduler
47
- scheduler = DPMSolverMultistepScheduler.from_pretrained(
48
- "runwayml/stable-diffusion-v1-5",
49
- solver_order=2,
50
- subfolder="scheduler",
51
- use_karras_sigmas=True,
52
- final_sigmas_type="sigma_min",
53
- algorithm_type="sde-dpmsolver++",
54
- prediction_type="epsilon",
55
- thresholding=False,
56
- denoise_final=True,
57
- device_map="cuda",
58
- torch_dtype=torch.float16,
59
- )
60
 
61
- # Stable Diffusion Pipeline URL
62
- # base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
63
- base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
64
- vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
65
-
66
- vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
67
- vae.to(memory_format=torch.channels_last)
68
-
69
- pipe = StableDiffusionControlNetPipeline.from_single_file(
70
- base_model_url,
71
- # safety_checker=None,
72
- # load_safety_checker=True,
73
- controlnet=controlnet,
74
- scheduler=scheduler,
75
- vae=vae,
76
- torch_dtype=torch.float16,
77
- )
78
 
79
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
80
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
81
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
82
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
83
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
84
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
85
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
86
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
87
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
88
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
89
- pipe.to("cuda")
90
-
91
- # experimental speedup?
92
- # pipe.compile()
93
- # torch.cuda.empty_cache()
94
- # gc.collect()
95
- print("---------------Loaded controlnet pipeline---------------")
96
 
97
- @spaces.GPU(duration=12)
98
- def init(pipe):
99
- pipe.enable_xformers_memory_efficient_attention()
100
- pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
101
- pipe.unet.set_attn_processor(AttnProcessor2_0())
102
- from preprocess import Preprocessor
103
- preprocessor = Preprocessor()
104
- preprocessor.load("NormalBae")
105
- print("Model Compiled!")
106
- init(pipe)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
109
  if randomize_seed:
 
31
 
32
  import spaces
33
 
34
+ # if gr.NO_RELOAD:
35
+ torch.cuda.max_memory_allocated(device="cuda")
36
 
37
+ # Controlnet Normal
38
+ model_id = "lllyasviel/control_v11p_sd15_normalbae"
39
+ print("initializing controlnet")
40
+ controlnet = ControlNetModel.from_pretrained(
41
+ model_id,
42
+ torch_dtype=torch.float16,
43
+ attn_implementation="flash_attention_2",
44
+ ).to("cuda")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ # Scheduler
47
+ scheduler = DPMSolverMultistepScheduler.from_pretrained(
48
+ "runwayml/stable-diffusion-v1-5",
49
+ solver_order=2,
50
+ subfolder="scheduler",
51
+ use_karras_sigmas=True,
52
+ final_sigmas_type="sigma_min",
53
+ algorithm_type="sde-dpmsolver++",
54
+ prediction_type="epsilon",
55
+ thresholding=False,
56
+ denoise_final=True,
57
+ device_map="cuda",
58
+ torch_dtype=torch.float16,
59
+ )
 
 
 
60
 
61
+ # Stable Diffusion Pipeline URL
62
+ # base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
63
+ base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
64
+ vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
67
+ vae.to(memory_format=torch.channels_last)
68
+
69
+ pipe = StableDiffusionControlNetPipeline.from_single_file(
70
+ base_model_url,
71
+ # safety_checker=None,
72
+ # load_safety_checker=True,
73
+ controlnet=controlnet,
74
+ scheduler=scheduler,
75
+ vae=vae,
76
+ torch_dtype=torch.float16,
77
+ )
78
+
79
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
80
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
81
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
82
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
83
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
84
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
85
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
86
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
87
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
88
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
89
+ pipe.to("cuda")
90
+
91
+ # experimental speedup?
92
+ # pipe.compile()
93
+ # torch.cuda.empty_cache()
94
+ # gc.collect()
95
+ print("---------------Loaded controlnet pipeline---------------")
96
+
97
+ @spaces.GPU(duration=12)
98
+ def init(pipe):
99
+ pipe.enable_xformers_memory_efficient_attention()
100
+ pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
101
+ pipe.unet.set_attn_processor(AttnProcessor2_0())
102
+ from preprocess import Preprocessor
103
+ preprocessor = Preprocessor()
104
+ preprocessor.load("NormalBae")
105
+ print("Model Compiled!")
106
+ init(pipe)
107
 
108
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
109
  if randomize_seed: