primerz commited on
Commit
5e35e8b
·
verified ·
1 Parent(s): 1efce5f

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +25 -29
model.py CHANGED
@@ -129,23 +129,24 @@ class ModelHandler:
129
  # 5. Load Adapters
130
  print("Loading Adapters...")
131
 
132
- # 5a. IP-Adapter (for InstantID)
133
- ip_adapter_filename = "ip-adapter.bin"
134
- ip_adapter_local_path = os.path.join("./models", ip_adapter_filename)
135
- if not os.path.exists(ip_adapter_local_path):
 
 
136
  hf_hub_download(
137
- repo_id=Config.INSTANTID_REPO,
138
- filename=ip_adapter_filename,
139
  local_dir="./models",
140
  local_dir_use_symlinks=False
141
  )
142
- self.pipeline.load_ip_adapter_instantid(ip_adapter_local_path)
143
- print(" [OK] IP-Adapter loaded.")
144
-
145
- # --- FIX: Load LoRAs with adapter_name, DO NOT FUSE ---
146
-
147
- # 5b. TCD LoRA (for speed)
148
- print("Loading TCD-SDXL-LoRA...")
149
  tcd_lora_filename = "pytorch_lora_weights.safetensors"
150
  tcd_lora_path = os.path.join("./models", tcd_lora_filename)
151
  if not os.path.exists(tcd_lora_path):
@@ -155,28 +156,23 @@ class ModelHandler:
155
  local_dir="./models",
156
  local_dir_use_symlinks=False
157
  )
158
- # Load with adapter_name="tcd"
159
- self.pipeline.load_lora_weights("./models", weight_name=tcd_lora_filename, adapter_name="tcd")
160
- print(" [OK] TCD LoRA loaded.")
161
 
162
- # 5c. Style LoRA (lucasart)
163
- print(f"Loading Style LoRA ({Config.LORA_FILENAME})...")
164
- style_lora_path = os.path.join("./models", Config.LORA_FILENAME)
165
- if not os.path.exists(style_lora_path):
166
  hf_hub_download(
167
- repo_id=Config.REPO_ID,
168
- filename=Config.LORA_FILENAME,
169
  local_dir="./models",
170
  local_dir_use_symlinks=False
171
  )
172
- # Load with adapter_name="style"
173
- self.pipeline.load_lora_weights("./models", weight_name=Config.LORA_FILENAME, adapter_name="style")
174
- print(" [OK] Style LoRA loaded.")
175
 
176
- # 6. Set Adapter Weights (TCD + Style)
177
- # This correctly activates both LoRAs simultaneously
178
- print(f"Setting adapter weights: TCD (1.0), Style ({Config.LORA_STRENGTH})")
179
- self.pipeline.set_adapters(["tcd", "style"], adapter_weights=[1.0, Config.LORA_STRENGTH])
180
  # --- END FIX ---
181
 
182
  # 7. Load Preprocessors
 
129
  # 5. Load Adapters
130
  print("Loading Adapters...")
131
 
132
+ # --- FIX: We must FUSE LoRAs in order to avoid TCD/Style adapter conflict ---
133
+
134
+ # 5a. Load and Fuse Style LoRA (lucasart)
135
+ print(f"Loading and Fusing Style LoRA ({Config.LORA_FILENAME})...")
136
+ style_lora_path = os.path.join("./models", Config.LORA_FILENAME)
137
+ if not os.path.exists(style_lora_path):
138
  hf_hub_download(
139
+ repo_id=Config.REPO_ID,
140
+ filename=Config.LORA_FILENAME,
141
  local_dir="./models",
142
  local_dir_use_symlinks=False
143
  )
144
+ self.pipeline.load_lora_weights("./models", weight_name=Config.LORA_FILENAME)
145
+ self.pipeline.fuse_lora(lora_scale=Config.LORA_STRENGTH)
146
+ print(" [OK] Style LoRA fused.")
147
+
148
+ # 5b. Load and Fuse TCD LoRA (for speed)
149
+ print("Loading and Fusing TCD-SDXL-LoRA...")
 
150
  tcd_lora_filename = "pytorch_lora_weights.safetensors"
151
  tcd_lora_path = os.path.join("./models", tcd_lora_filename)
152
  if not os.path.exists(tcd_lora_path):
 
156
  local_dir="./models",
157
  local_dir_use_symlinks=False
158
  )
159
+ self.pipeline.load_lora_weights("./models", weight_name=tcd_lora_filename)
160
+ self.pipeline.fuse_lora(lora_scale=1.0) # TCD must be fused at 1.0
161
+ print(" [OK] TCD LoRA fused.")
162
 
163
+ # 5c. Load IP-Adapter (for InstantID) - *Must be loaded AFTER fusing*
164
+ ip_adapter_filename = "ip-adapter.bin"
165
+ ip_adapter_local_path = os.path.join("./models", ip_adapter_filename)
166
+ if not os.path.exists(ip_adapter_local_path):
167
  hf_hub_download(
168
+ repo_id=Config.INSTANTID_REPO,
169
+ filename=ip_adapter_filename,
170
  local_dir="./models",
171
  local_dir_use_symlinks=False
172
  )
173
+ self.pipeline.load_ip_adapter_instantid(ip_adapter_local_path)
174
+ print(" [OK] IP-Adapter loaded.")
 
175
 
 
 
 
 
176
  # --- END FIX ---
177
 
178
  # 7. Load Preprocessors