NANI-Nithin commited on
Commit
51c88b7
·
1 Parent(s): 1e19a89

feat: Improve tensor handling in transcription for better model compatibility

Browse files
Files changed (1) hide show
  1. app/services/asr.py +7 -5
app/services/asr.py CHANGED
@@ -255,17 +255,19 @@ def transcribe(
255
  return_tensors="pt",
256
  language=language,
257
  )
258
- inputs = {
259
- k: v.to(_model.device, dtype=_model.dtype) if hasattr(v, "to") else v
260
- for k, v in inputs.items()
261
- }
262
 
263
  with torch.inference_mode():
264
  outputs = _model.generate(
265
  **inputs,
266
  max_new_tokens=max_new_tokens,
267
  )
268
- text = _processor.decode(outputs[0], skip_special_tokens=True).strip()
 
 
269
 
270
  return {
271
  "transcript": text,
 
255
  return_tensors="pt",
256
  language=language,
257
  )
258
+ # BatchFeature.to() casts only floating-point tensors to model.dtype,
259
+ # leaving integer tensors (masks / ids) intact. Casting every tensor
260
+ # to bf16 (the old behavior) corrupts those and breaks generation.
261
+ inputs = inputs.to(_model.device, dtype=_model.dtype)
262
 
263
  with torch.inference_mode():
264
  outputs = _model.generate(
265
  **inputs,
266
  max_new_tokens=max_new_tokens,
267
  )
268
+ # Cohere's processor.decode expects the generated tensor as-is
269
+ # (per the model card), not a single unwrapped sequence.
270
+ text = _processor.decode(outputs, skip_special_tokens=True).strip()
271
 
272
  return {
273
  "transcript": text,