k4d3 commited on
Commit
f3032a6
·
1 Parent(s): 98740cc

Add worker initialization and improve multiprocessing setup in audio_utils.py

Browse files

This commit introduces a new `worker_init` function to ensure correct umask settings for worker processes in the audio generation workflow. Additionally, the multiprocessing start method is now set conditionally to avoid runtime errors if it has already been established. These changes enhance the robustness and reliability of the audio generation process, particularly in multi-process environments.

Files changed (1) hide show
  1. utils/audio_utils.py +10 -7
utils/audio_utils.py CHANGED
@@ -7,6 +7,11 @@ import random
7
  import multiprocessing as mp
8
  import stat
9
 
 
 
 
 
 
10
  def ensure_directory_permissions(directory):
11
  """Ensure the directory has the correct permissions"""
12
  try:
@@ -71,8 +76,11 @@ def process_audio_generations(descriptions, model_name, generate_fn, prepare_arg
71
  num_variations: Number of variations to generate per prompt
72
  num_processes: Number of parallel processes to use
73
  """
74
- # Set start method for multiprocessing
75
- mp.set_start_method('spawn', force=True)
 
 
 
76
 
77
  if not descriptions:
78
  print('At least one prompt should be provided')
@@ -86,11 +94,6 @@ def process_audio_generations(descriptions, model_name, generate_fn, prepare_arg
86
  ensure_directory_permissions(base_output_dir)
87
  ensure_directory_permissions(model_dir)
88
 
89
- def worker_init():
90
- """Initialize each worker process"""
91
- # Ensure worker processes have correct umask
92
- os.umask(0)
93
-
94
  for description in descriptions:
95
  # Create model-specific directory for each prompt
96
  prompt_dir = setup_generation_dir(model_dir, description)
 
7
  import multiprocessing as mp
8
  import stat
9
 
10
+ def worker_init():
11
+ """Initialize each worker process"""
12
+ # Ensure worker processes have correct umask
13
+ os.umask(0)
14
+
15
  def ensure_directory_permissions(directory):
16
  """Ensure the directory has the correct permissions"""
17
  try:
 
76
  num_variations: Number of variations to generate per prompt
77
  num_processes: Number of parallel processes to use
78
  """
79
+ # Set start method for multiprocessing if it hasn't been set
80
+ try:
81
+ mp.set_start_method('spawn')
82
+ except RuntimeError:
83
+ pass # method already set
84
 
85
  if not descriptions:
86
  print('At least one prompt should be provided')
 
94
  ensure_directory_permissions(base_output_dir)
95
  ensure_directory_permissions(model_dir)
96
 
 
 
 
 
 
97
  for description in descriptions:
98
  # Create model-specific directory for each prompt
99
  prompt_dir = setup_generation_dir(model_dir, description)