Spaces:
Running on Zero
Running on Zero
Commit ·
51c88b7
1
Parent(s): 1e19a89
feat: Improve tensor handling in transcription for better model compatibility
Browse files- 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 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
|
| 263 |
with torch.inference_mode():
|
| 264 |
outputs = _model.generate(
|
| 265 |
**inputs,
|
| 266 |
max_new_tokens=max_new_tokens,
|
| 267 |
)
|
| 268 |
-
|
|
|
|
|
|
|
| 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,
|