Unverified Commit 196cce6e authored by Anton Lozhkov's avatar Anton Lozhkov Committed by GitHub
Browse files

Add a device argument to the eval script (#15371)

* Device argument for the eval script

* Default to none

* isort
parent 6beae766
...@@ -3,6 +3,7 @@ import argparse ...@@ -3,6 +3,7 @@ import argparse
import re import re
from typing import Dict from typing import Dict
import torch
from datasets import Audio, Dataset, load_dataset, load_metric from datasets import Audio, Dataset, load_dataset, load_metric
from transformers import AutoFeatureExtractor, pipeline from transformers import AutoFeatureExtractor, pipeline
...@@ -78,7 +79,9 @@ def main(args): ...@@ -78,7 +79,9 @@ def main(args):
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate)) dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
# load eval pipeline # load eval pipeline
asr = pipeline("automatic-speech-recognition", model=args.model_id) if args.device is None:
args.device = 0 if torch.cuda.is_available() else -1
asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
# map function to decode audio # map function to decode audio
def map_to_pred(batch): def map_to_pred(batch):
...@@ -123,6 +126,12 @@ if __name__ == "__main__": ...@@ -123,6 +126,12 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis." "--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
) )
parser.add_argument(
"--device",
type=int,
default=None,
help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
)
args = parser.parse_args() args = parser.parse_args()
main(args) main(args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment