mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
Add a device argument to the eval script (#15371)
* Device argument for the eval script * Default to none * isort
This commit is contained in:
parent
6beae766ee
commit
196cce6e9b
@ -3,6 +3,7 @@ import argparse
|
||||
import re
|
||||
from typing import Dict
|
||||
|
||||
import torch
|
||||
from datasets import Audio, Dataset, load_dataset, load_metric
|
||||
|
||||
from transformers import AutoFeatureExtractor, pipeline
|
||||
@ -78,7 +79,9 @@ def main(args):
|
||||
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
|
||||
|
||||
# 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
|
||||
def map_to_pred(batch):
|
||||
@ -123,6 +126,12 @@ if __name__ == "__main__":
|
||||
parser.add_argument(
|
||||
"--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()
|
||||
|
||||
main(args)
|
||||
|
Loading…
Reference in New Issue
Block a user