hvoss-techfak commited on
Commit
c7a2403
·
1 Parent(s): 5dba690

fixed gpu spaces?

Browse files
Files changed (1) hide show
  1. app.py +59 -18
app.py CHANGED
@@ -98,7 +98,7 @@ def get_script_args_info(exclude_args=None):
98
  {
99
  "name": "--iterations",
100
  "type": "number",
101
- "default": 4000,
102
  "help": "Number of optimization iterations",
103
  },
104
  {
@@ -159,7 +159,7 @@ def get_script_args_info(exclude_args=None):
159
  {
160
  "name": "--pruning_max_swaps",
161
  "type": "number",
162
- "default": 20,
163
  "precision": 0,
164
  "help": "Max number of swaps allowed after pruning",
165
  },
@@ -182,7 +182,7 @@ def get_script_args_info(exclude_args=None):
182
  {
183
  "name": "--learning_rate_warmup_fraction",
184
  "type": "slider",
185
- "default": 0.2,
186
  "min": 0.0,
187
  "max": 1.0,
188
  "step": 0.01,
@@ -214,7 +214,7 @@ def get_script_args_info(exclude_args=None):
214
  {
215
  "name": "--num_init_rounds",
216
  "type": "number",
217
- "default": 8,
218
  "precision": 0,
219
  "help": "Number of rounds to choose the starting height map from.",
220
  },
@@ -295,17 +295,31 @@ else:
295
  def run_autoforge_process(cmd, log_path):
296
  from joblib import parallel_backend
297
  cli_args = cmd[1:]
298
- autoforge_main = importlib.import_module("autoforge.__main__")
 
 
 
 
 
 
 
 
 
 
299
 
300
  exit_code = 0
301
  with open(log_path, "w", buffering=1, encoding="utf-8") as log_f, \
302
  redirect_stdout(log_f), redirect_stderr(log_f), parallel_backend("threading", n_jobs=-1):
303
  try:
 
304
  sys.argv = ["autoforge"] + cli_args
 
305
  autoforge_main.main()
306
  except SystemExit as e:
307
- exit_code = e.code
 
308
  except Exception as e:
 
309
  log_f.write(f"\nERROR: {e}\n")
310
  exit_code = -1
311
 
@@ -672,7 +686,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
672
  visible=False,
673
  )
674
 
675
- @spaces.GPU(duration=150)
676
  def execute_autoforge_script(
677
  current_filaments_df_state_val, input_image, *accordion_param_values
678
  ):
@@ -774,17 +787,45 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
774
  self.exc = None
775
 
776
  def run(self):
777
- try:
778
- self.returncode = run_autoforge_process(self.cmd, self.log_path)
779
- except Exception as e:
780
- self.exc = e
781
- with open(self.log_path, "a", encoding="utf-8") as lf:
782
- lf.write(
783
- "\nERROR: {}. This usually means there was no GPU or the process took too long.\n".format(
784
- exc_text(e)
785
- )
786
- )
787
- self.returncode = -1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
788
 
789
  try:
790
  worker = Worker(command, log_file)
 
98
  {
99
  "name": "--iterations",
100
  "type": "number",
101
+ "default": 6000,
102
  "help": "Number of optimization iterations",
103
  },
104
  {
 
159
  {
160
  "name": "--pruning_max_swaps",
161
  "type": "number",
162
+ "default": 50,
163
  "precision": 0,
164
  "help": "Max number of swaps allowed after pruning",
165
  },
 
182
  {
183
  "name": "--learning_rate_warmup_fraction",
184
  "type": "slider",
185
+ "default": 0.01,
186
  "min": 0.0,
187
  "max": 1.0,
188
  "step": 0.01,
 
214
  {
215
  "name": "--num_init_rounds",
216
  "type": "number",
217
+ "default": 32,
218
  "precision": 0,
219
  "help": "Number of rounds to choose the starting height map from.",
220
  },
 
295
  def run_autoforge_process(cmd, log_path):
296
  from joblib import parallel_backend
297
  cli_args = cmd[1:]
298
+
299
+ # Import the library's high-level module which contains the main() entrypoint
300
+ # that uses the internal @spaces.GPU decorators (autoforge/auto_forge.py).
301
+ # Do NOT fall back to any other module; require the project module to be present.
302
+ try:
303
+ autoforge_main = importlib.import_module("autoforge.auto_forge")
304
+ except Exception as e:
305
+ # If the direct import fails, write the error to the log and return failure.
306
+ with open(log_path, "a", encoding="utf-8") as log_f:
307
+ log_f.write(f"\nERROR: Could not import autoforge.auto_forge: {e}\n")
308
+ return -1
309
 
310
  exit_code = 0
311
  with open(log_path, "w", buffering=1, encoding="utf-8") as log_f, \
312
  redirect_stdout(log_f), redirect_stderr(log_f), parallel_backend("threading", n_jobs=-1):
313
  try:
314
+ # Provide argv so the autoforge CLI parser sees the same arguments as before.
315
  sys.argv = ["autoforge"] + cli_args
316
+ # Call the library's main() function. It may call sys.exit(); capture that.
317
  autoforge_main.main()
318
  except SystemExit as e:
319
+ # Preserve the exit code behavior from the subprocess-style invocation.
320
+ exit_code = e.code if isinstance(e.code, int) or e.code is None else 0
321
  except Exception as e:
322
+ # Log exceptions to the log file and return a failure code.
323
  log_f.write(f"\nERROR: {e}\n")
324
  exit_code = -1
325
 
 
686
  visible=False,
687
  )
688
 
 
689
  def execute_autoforge_script(
690
  current_filaments_df_state_val, input_image, *accordion_param_values
691
  ):
 
787
  self.exc = None
788
 
789
  def run(self):
790
+ try:
791
+ # Import joblib's parallel_backend to match previous environment setup
792
+ from joblib import parallel_backend
793
+
794
+ # Import the autoforge high-level module which contains main().
795
+ # No fallback allowed; require this module to exist in the package.
796
+ try:
797
+ autoforge_main = importlib.import_module("autoforge.auto_forge")
798
+ except Exception as e:
799
+ # Log and fail the worker if import fails.
800
+ with open(self.log_path, "a", encoding="utf-8") as lf:
801
+ lf.write(f"\nERROR: Could not import autoforge.auto_forge: {e}\n")
802
+ self.exc = e
803
+ self.returncode = -1
804
+ return
805
+
806
+ # Redirect stdout/stderr into the provided log file while running
807
+ with open(self.log_path, "a", encoding="utf-8") as lf, \
808
+ redirect_stdout(lf), redirect_stderr(lf), parallel_backend("threading", n_jobs=-1):
809
+ try:
810
+ # Ensure CLI-like argv for the autoforge parser
811
+ sys.argv = ["autoforge"] + (self.cmd[1:] if len(self.cmd) > 1 else [])
812
+ autoforge_main.main()
813
+ # If main exits normally, treat as success (0)
814
+ self.returncode = 0
815
+ except SystemExit as e:
816
+ # Preserve exit code behavior
817
+ self.returncode = e.code if isinstance(e.code, int) or e.code is None else 0
818
+ except Exception as e:
819
+ # Write exception to log and mark failure
820
+ lf.write(f"\nERROR: {e}\n")
821
+ self.exc = e
822
+ self.returncode = -1
823
+ except Exception as e_outer:
824
+ # If import or log file operations fail, persist exception and code
825
+ self.exc = e_outer
826
+ with open(self.log_path, "a", encoding="utf-8") as lf:
827
+ lf.write("\nERROR: {}\n".format(exc_text(e_outer)))
828
+ self.returncode = -1
829
 
830
  try:
831
  worker = Worker(command, log_file)