Skip to content

Commit 80af104

Browse files
[Wav2Vec2ProcessorWithLM] improve multi processing (huggingface#15247)
* [Wav2Vec2ProcessorWithLM] improve multi processing * close pool
1 parent 4cff3fa commit 80af104

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/transformers/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
from contextlib import contextmanager
2020
from dataclasses import dataclass
21-
from multiprocessing import Pool
21+
from multiprocessing import get_context
2222
from typing import TYPE_CHECKING, Iterable, List, Optional, Union
2323

2424
import numpy as np
@@ -300,7 +300,7 @@ def batch_decode(
300300

301301
# create multiprocessing pool and list numpy arrays
302302
logits_list = [array for array in logits]
303-
pool = Pool(num_processes)
303+
pool = get_context("fork").Pool(num_processes)
304304

305305
# pyctcdecode
306306
decoded_beams = self.decoder.decode_beams_batch(
@@ -313,6 +313,9 @@ def batch_decode(
313313
hotword_weight=hotword_weight,
314314
)
315315

316+
# clone multi-processing pool
317+
pool.close()
318+
316319
# extract text
317320
batch_texts = [d[0][0] for d in decoded_beams]
318321

0 commit comments

Comments
 (0)