smartdigitalnetworks commited on
Commit
1d4da0f
·
verified ·
1 Parent(s): 2eed2fb

Update classic.py

Browse files
Files changed (1) hide show
  1. classic.py +24 -7
classic.py CHANGED
@@ -208,8 +208,6 @@ model_ledger = ModelLedger(
208
  )
209
 
210
  canny_processor = CannyDetector()
211
-
212
- # 2. Set these to None globally. Do NOT load them here.
213
  depth_processor = None
214
  text_encoder = None
215
 
@@ -217,15 +215,33 @@ def ensure_models_loaded():
217
  """Helper function to load CUDA models safely inside the ZeroGPU environment."""
218
  global depth_processor, text_encoder
219
 
 
 
 
 
 
 
220
  if depth_processor is None:
221
  print("Loading Depth Processor to GPU...")
222
  depth_processor = MidasDetector.from_pretrained("lllyasviel/Annotators").to("cuda")
223
 
 
224
  if text_encoder is None:
225
  print("Loading Text Encoder to GPU...")
226
  text_encoder = model_ledger.text_encoder()
227
- print("=" * 80)
228
- print("Text encoder loaded and ready!")
 
 
 
 
 
 
 
 
 
 
 
229
  print("=" * 80)
230
 
231
  def on_lora_change(selected: str):
@@ -730,11 +746,12 @@ pipeline = DistilledPipeline(
730
  local_files_only=False,
731
  )
732
 
733
- pipeline._video_encoder = pipeline.model_ledger.video_encoder()
734
- pipeline._transformer = pipeline.model_ledger.transformer()
 
735
 
736
  print("=" * 80)
737
- print("Pipeline fully loaded and ready!")
738
  print("=" * 80)
739
 
740
  class RadioAnimated(gr.HTML):
 
208
  )
209
 
210
  canny_processor = CannyDetector()
 
 
211
  depth_processor = None
212
  text_encoder = None
213
 
 
215
  """Helper function to load CUDA models safely inside the ZeroGPU environment."""
216
  global depth_processor, text_encoder
217
 
218
+ # 1. Ensure the pipeline itself is switched to CUDA
219
+ if pipeline.device.type == "cpu":
220
+ print("Moving base pipeline to GPU...")
221
+ pipeline.device = torch.device("cuda")
222
+
223
+ # 2. Load Depth Processor
224
  if depth_processor is None:
225
  print("Loading Depth Processor to GPU...")
226
  depth_processor = MidasDetector.from_pretrained("lllyasviel/Annotators").to("cuda")
227
 
228
+ # 3. Load Text Encoder
229
  if text_encoder is None:
230
  print("Loading Text Encoder to GPU...")
231
  text_encoder = model_ledger.text_encoder()
232
+ print(" Text encoder loaded!")
233
+
234
+ # 4. Load Video Encoder
235
+ if not hasattr(pipeline, '_video_encoder') or pipeline._video_encoder is None:
236
+ print("Loading Video Encoder to GPU...")
237
+ pipeline._video_encoder = pipeline.model_ledger.video_encoder()
238
+ print("✓ Video encoder loaded!")
239
+
240
+ # 5. Load the Transformer (this was your hidden culprit!)
241
+ if not hasattr(pipeline, '_transformer') or pipeline._transformer is None:
242
+ print("Loading Transformer to GPU...")
243
+ pipeline._transformer = pipeline.model_ledger.transformer()
244
+ print("✓ Transformer loaded!")
245
  print("=" * 80)
246
 
247
  def on_lora_change(selected: str):
 
746
  local_files_only=False,
747
  )
748
 
749
+ # DELETE or COMMENT OUT these two lines from the global scope:
750
+ # pipeline._video_encoder = pipeline.model_ledger.video_encoder()
751
+ # pipeline._transformer = pipeline.model_ledger.transformer()
752
 
753
  print("=" * 80)
754
+ print("Pipeline framework initialized on CPU (waiting for ZeroGPU allocation)...")
755
  print("=" * 80)
756
 
757
  class RadioAnimated(gr.HTML):