Skip to content

Commit 196cce6

Browse files
authored
Add a device argument to the eval script (huggingface#15371)
* Device argument for the eval script * Default to none * isort
1 parent 6beae76 commit 196cce6

File tree

1 file changed

+10
-1
lines changed
  • examples/research_projects/robust-speech-event

1 file changed

+10
-1
lines changed

examples/research_projects/robust-speech-event/eval.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
from typing import Dict
55

6+
import torch
67
from datasets import Audio, Dataset, load_dataset, load_metric
78

89
from transformers import AutoFeatureExtractor, pipeline
@@ -78,7 +79,9 @@ def main(args):
7879
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
7980

8081
# load eval pipeline
81-
asr = pipeline("automatic-speech-recognition", model=args.model_id)
82+
if args.device is None:
83+
args.device = 0 if torch.cuda.is_available() else -1
84+
asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
8285

8386
# map function to decode audio
8487
def map_to_pred(batch):
@@ -123,6 +126,12 @@ def map_to_pred(batch):
123126
parser.add_argument(
124127
"--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
125128
)
129+
parser.add_argument(
130+
"--device",
131+
type=int,
132+
default=None,
133+
help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
134+
)
126135
args = parser.parse_args()
127136

128137
main(args)

0 commit comments

Comments
 (0)