shiromiya commited on
Commit
8def2e3
·
verified ·
1 Parent(s): c77036d

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +17 -0
inference.py CHANGED
@@ -26,6 +26,17 @@ import warnings
26
  warnings.filterwarnings("ignore")
27
 
28
 
 
 
 
 
 
 
 
 
 
 
 
29
  def run_folder(model, args, config, device, verbose: bool = False):
30
  """
31
  Process a folder of audio files for source separation.
@@ -174,12 +185,18 @@ def proc_folder(dict_args):
174
  checkpoint = torch.load(args.start_check_point, weights_only=False, map_location='cpu')
175
  load_start_checkpoint(args, model, checkpoint, type_='inference')
176
 
 
 
 
177
  print("Instruments: {}".format(config.training.instruments))
178
 
179
  # in case multiple CUDA GPUs are used and --device_ids arg is passed
180
  if isinstance(args.device_ids, list) and len(args.device_ids) > 1 and not args.force_cpu:
181
  model = nn.DataParallel(model, device_ids=args.device_ids)
182
 
 
 
 
183
  model = model.to(device)
184
 
185
  print("Model load time: {:.2f} sec".format(time.time() - model_load_start_time))
 
26
  warnings.filterwarnings("ignore")
27
 
28
 
29
+ def disable_rnn_flatten_parameters(model: nn.Module) -> None:
30
+ """
31
+ Disable cuDNN RNN weight flattening to avoid inference-mode in-place updates.
32
+ This is a workaround for RuntimeError about inplace updates to inference tensors
33
+ when running RNNs during inference.
34
+ """
35
+ for module in model.modules():
36
+ if isinstance(module, (nn.RNN, nn.GRU, nn.LSTM)):
37
+ module.flatten_parameters = lambda *args, **kwargs: None
38
+
39
+
40
  def run_folder(model, args, config, device, verbose: bool = False):
41
  """
42
  Process a folder of audio files for source separation.
 
185
  checkpoint = torch.load(args.start_check_point, weights_only=False, map_location='cpu')
186
  load_start_checkpoint(args, model, checkpoint, type_='inference')
187
 
188
+ # Workaround for cuDNN RNN flattening with inference tensors
189
+ disable_rnn_flatten_parameters(model)
190
+
191
  print("Instruments: {}".format(config.training.instruments))
192
 
193
  # in case multiple CUDA GPUs are used and --device_ids arg is passed
194
  if isinstance(args.device_ids, list) and len(args.device_ids) > 1 and not args.force_cpu:
195
  model = nn.DataParallel(model, device_ids=args.device_ids)
196
 
197
+ # Ensure flattened parameters are disabled on the wrapped model too
198
+ disable_rnn_flatten_parameters(model)
199
+
200
  model = model.to(device)
201
 
202
  print("Model load time: {:.2f} sec".format(time.time() - model_load_start_time))