multimodalart commited on
Commit
1d1bf1f
·
1 Parent(s): 99702da

Run controller updates inside @spaces.GPU to keep CUDA ops in GPU emulation

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -176,23 +176,18 @@ class MagicTimeController:
176
  height_slider,
177
  seed_textbox,
178
  ):
179
- # Switch adapters on CPU side first (no GPU needed); this also avoids
180
- # pickling `self` into the ZeroGPU worker, which fails because Swift
181
- # adapters attach unpicklable local `device_hook` closures on Linear.
182
- if self.selected_motion_module != motion_module_dropdown: self.update_motion_module(motion_module_dropdown)
183
- if self.selected_motion_module != motion_module_dropdown: self.update_motion_module_2(motion_module_dropdown)
184
- if self.selected_dreambooth != dreambooth_dropdown: self.update_dreambooth(dreambooth_dropdown)
185
-
186
- while self.text_encoder is None or self.unet is None:
187
- self.update_dreambooth(dreambooth_dropdown, motion_module_dropdown)
188
-
189
  return _magictime_gpu(
 
 
190
  prompt_textbox,
191
  negative_prompt_textbox,
192
  int(width_slider),
193
  int(height_slider),
194
  str(seed_textbox),
195
- dreambooth_dropdown,
196
  )
197
 
198
  controller = MagicTimeController()
@@ -200,15 +195,22 @@ controller = MagicTimeController()
200
 
201
  @spaces.GPU(duration=120)
202
  def _magictime_gpu(
 
 
203
  prompt_textbox,
204
  negative_prompt_textbox,
205
  width_slider,
206
  height_slider,
207
  seed_textbox,
208
- dreambooth_dropdown,
209
  ):
210
- # Use the module-level `controller` global so we don't pickle `self`
211
- # (which contains Swift-modified nn.Modules with unpicklable closure hooks).
 
 
 
 
 
 
212
  torch.cuda.empty_cache()
213
  time.sleep(1)
214
 
 
176
  height_slider,
177
  seed_textbox,
178
  ):
179
+ # Delegate to a module-level @spaces.GPU function so `self` (the
180
+ # controller, which contains Swift-modified nn.Modules with unpicklable
181
+ # local `device_hook` closures on Linear) is NOT pickled into the
182
+ # ZeroGPU worker. All GPU work happens via the global `controller`.
 
 
 
 
 
 
183
  return _magictime_gpu(
184
+ dreambooth_dropdown,
185
+ motion_module_dropdown,
186
  prompt_textbox,
187
  negative_prompt_textbox,
188
  int(width_slider),
189
  int(height_slider),
190
  str(seed_textbox),
 
191
  )
192
 
193
  controller = MagicTimeController()
 
195
 
196
  @spaces.GPU(duration=120)
197
  def _magictime_gpu(
198
+ dreambooth_dropdown,
199
+ motion_module_dropdown,
200
  prompt_textbox,
201
  negative_prompt_textbox,
202
  width_slider,
203
  height_slider,
204
  seed_textbox,
 
205
  ):
206
+ # Use the module-level `controller` global so we don't pickle `self`.
207
+ if controller.selected_motion_module != motion_module_dropdown: controller.update_motion_module(motion_module_dropdown)
208
+ if controller.selected_motion_module != motion_module_dropdown: controller.update_motion_module_2(motion_module_dropdown)
209
+ if controller.selected_dreambooth != dreambooth_dropdown: controller.update_dreambooth(dreambooth_dropdown)
210
+
211
+ while controller.text_encoder is None or controller.unet is None:
212
+ controller.update_dreambooth(dreambooth_dropdown, motion_module_dropdown)
213
+
214
  torch.cuda.empty_cache()
215
  time.sleep(1)
216