Luigi commited on
Commit
6ffa7d7
·
1 Parent(s): f95c465

add debug msg to choose_file()

Browse files
Files changed (1) hide show
  1. app/asr_worker.py +21 -14
app/asr_worker.py CHANGED
@@ -204,18 +204,13 @@ def resample_audio(audio: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarra
204
  def choose_file(entry: dict, component: str, precision: str) -> str | None:
205
  """
206
  Pick the best file for the given component ('encoder', 'decoder', or 'joiner'),
207
- resolving relative paths to absolute, and only returning ones that actually exist.
208
-
209
- 1) Grab the two candidates from the entry.
210
- 2) If a path is relative, turn it into an absolute via os.path.abspath().
211
- 3) Discard any whose path doesn’t exist on disk.
212
- 4) If neither exists, print an error and return None.
213
- 5) If exactly one exists, return that one.
214
- 6) Otherwise (both exist), if precision=='int8' pick int8, else pick fp32.
215
  """
216
- # 1) grab whatever the entry says
217
- raw8 = entry.get(f'{component}_int8')
218
  raw32 = entry.get(f'{component}_fp32')
 
219
 
220
  # 2) resolve relative paths
221
  def _abs(path: str | None) -> str | None:
@@ -225,25 +220,37 @@ def choose_file(entry: dict, component: str, precision: str) -> str | None:
225
 
226
  e8 = _abs(raw8)
227
  e32 = _abs(raw32)
 
228
 
229
  # 3) sanity: drop any that aren’t real files
230
  if e8 and not os.path.exists(e8):
 
231
  e8 = None
232
  if e32 and not os.path.exists(e32):
 
233
  e32 = None
234
 
 
 
235
  # 4) if neither exists, error out
236
  if e8 is None and e32 is None:
237
- print(f"Error: no available files for component '{component}' (neither int8 nor fp32 found).")
238
  return None
239
 
240
  # 5) if exactly one exists → pick it
241
  if (e8 is None) != (e32 is None):
242
- return e8 or e32
 
 
243
 
244
  # 6) otherwise, both exist → int8 if requested & available, else fp32
245
- return e8 if precision == 'int8' and e8 else e32
246
-
 
 
 
 
 
247
  # Create an online recognizer for a given model and precision
248
  # model_id: full HF repo ID
249
  # precision: "int8" or "fp32"
 
204
  def choose_file(entry: dict, component: str, precision: str) -> str | None:
205
  """
206
  Pick the best file for the given component ('encoder', 'decoder', or 'joiner'),
207
+ resolving relative paths to absolute, only returning ones that actually exist,
208
+ and printing debug info at each step.
 
 
 
 
 
 
209
  """
210
+ # 1) grab the two candidates
211
+ raw8 = entry.get(f'{component}_int8')
212
  raw32 = entry.get(f'{component}_fp32')
213
+ print(f"[DEBUG] [{component}] raw paths → int8: {raw8!r}, fp32: {raw32!r}")
214
 
215
  # 2) resolve relative paths
216
  def _abs(path: str | None) -> str | None:
 
220
 
221
  e8 = _abs(raw8)
222
  e32 = _abs(raw32)
223
+ print(f"[DEBUG] [{component}] abs paths → int8: {e8!r}, fp32: {e32!r}")
224
 
225
  # 3) sanity: drop any that aren’t real files
226
  if e8 and not os.path.exists(e8):
227
+ print(f"[DEBUG] [{component}] int8 path does not exist, dropping: {e8!r}")
228
  e8 = None
229
  if e32 and not os.path.exists(e32):
230
+ print(f"[DEBUG] [{component}] fp32 path does not exist, dropping: {e32!r}")
231
  e32 = None
232
 
233
+ print(f"[DEBUG] [{component}] available after existence check → int8: {e8!r}, fp32: {e32!r}")
234
+
235
  # 4) if neither exists, error out
236
  if e8 is None and e32 is None:
237
+ print(f"[ERROR] [{component}] No available files (neither int8 nor fp32 found).")
238
  return None
239
 
240
  # 5) if exactly one exists → pick it
241
  if (e8 is None) != (e32 is None):
242
+ selected = e8 or e32
243
+ print(f"[DEBUG] [{component}] Only one available, selecting: {selected!r}")
244
+ return selected
245
 
246
  # 6) otherwise, both exist → int8 if requested & available, else fp32
247
+ if precision == 'int8' and e8:
248
+ print(f"[DEBUG] [{component}] Both available, precision='{precision}', selecting int8: {e8!r}")
249
+ return e8
250
+ else:
251
+ print(f"[DEBUG] [{component}] Both available, selecting fp32: {e32!r}")
252
+ return e32
253
+
254
  # Create an online recognizer for a given model and precision
255
  # model_id: full HF repo ID
256
  # precision: "int8" or "fp32"