Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cpu count #2211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions training/coqui_stt_training/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
import sys
from multiprocessing import cpu_count
import psutil

import progressbar
import tensorflow.compat.v1 as tfv1
Expand Down Expand Up @@ -91,7 +91,7 @@ def evaluate(test_csvs, create_model):

# Get number of accessible CPU cores for this process
try:
num_processes = cpu_count()
num_processes = len(psutil.Process().cpu_affinity())
except NotImplementedError:
num_processes = 1

Expand Down
5 changes: 3 additions & 2 deletions training/coqui_stt_training/evaluate_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import wave
import io
from functools import partial
from multiprocessing import JoinableQueue, Manager, Process, cpu_count
from multiprocessing import JoinableQueue, Manager, Process
import psutil

import numpy as np
from coqui_stt_training.util.evaluate_tools import calculate_and_print_report
Expand Down Expand Up @@ -142,7 +143,7 @@ def parse_args():
parser.add_argument(
"--proc",
required=False,
default=cpu_count(),
default=len(psutil.Process().cpu_affinity()),
type=int,
help="Number of processes to spawn, defaulting to number of CPUs",
)
Expand Down
4 changes: 2 additions & 2 deletions training/coqui_stt_training/evaluate_flashlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
import sys
from multiprocessing import cpu_count
import psutil

import progressbar
import tensorflow.compat.v1 as tfv1
Expand Down Expand Up @@ -95,7 +95,7 @@ def evaluate(test_csvs, create_model):

# Get number of accessible CPU cores for this process
try:
num_processes = cpu_count()
num_processes = len(psutil.Process().cpu_affinity())
except NotImplementedError:
num_processes = 1

Expand Down
5 changes: 3 additions & 2 deletions training/coqui_stt_training/evaluate_wav2vec2am.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import os
import sys
from functools import partial
from multiprocessing import JoinableQueue, Manager, Process, cpu_count
from multiprocessing import JoinableQueue, Manager, Process
from pathlib import Path
import psutil

import numpy as np
import onnxruntime
Expand Down Expand Up @@ -274,7 +275,7 @@ def parse_args():
parser.add_argument(
"--proc",
required=False,
default=cpu_count(),
default=len(psutil.Process().cpu_affinity()),
type=int,
help="Number of processes to spawn, defaulting to number of CPUs",
)
Expand Down
3 changes: 2 additions & 1 deletion training/coqui_stt_training/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional, List, Tuple
import psutil

LOG_LEVEL_INDEX = sys.argv.index("--log_level") + 1 if "--log_level" in sys.argv else 0
DESIRED_LOG_LEVEL = (
Expand All @@ -34,7 +35,7 @@


def cpu_count():
return os.cpu_count() or 1
return len(psutil.Process().cpu_affinity()) or 1


class TranscriptionPool(PoolBase):
Expand Down
11 changes: 9 additions & 2 deletions training/coqui_stt_training/util/augmentations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import math
import os
import random
import re
from multiprocessing import Process, Queue
import psutil

import numpy as np
import resampy
Expand Down Expand Up @@ -312,7 +312,14 @@ def __repr__(self):

def start(self, buffering=BUFFER_SIZE):
self.queue = Queue(
max(1, math.floor(self.probability * self.layers[1] * os.cpu_count()))
max(
1,
math.floor(
self.probability
* self.layers[1]
* len(psutil.Process().cpu_affinity())
),
)
)
self.enqueue_process = Process(
target=_enqueue_overlay_samples,
Expand Down
10 changes: 9 additions & 1 deletion training/coqui_stt_training/util/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import heapq
import os
import psutil
import random
import sys
import time
Expand Down Expand Up @@ -134,7 +135,14 @@ def __init__(
process_ahead=None,
sleeping_for=0.1,
):
self.process_ahead = os.cpu_count() if process_ahead is None else process_ahead
if processes is None:
processes = len(psutil.Process().cpu_affinity())

self.process_ahead = (
len(psutil.Process().cpu_affinity())
if process_ahead is None
else process_ahead
)
self.sleeping_for = sleeping_for
self.processed = 0
self.pool = Pool(
Expand Down
4 changes: 2 additions & 2 deletions training/coqui_stt_training/util/lm_optimize_wav2vec2am.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import os
import sys
from dataclasses import dataclass, field
import psutil

import optuna
from clearml import Task
Expand Down Expand Up @@ -103,7 +103,7 @@ class LmOptimizeWav2vec2amConfig(BaseSttConfig):
),
)
num_processes: int = field(
default=os.cpu_count(),
default=len(psutil.Process().cpu_affinity()),
metadata=dict(help="Number of worker processes for evaluation."),
)
clearml_project: str = field(
Expand Down
5 changes: 3 additions & 2 deletions training/coqui_stt_training/util/multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
from contextlib import contextmanager
import psutil


def target_fn(*args, **kwargs):
Expand Down Expand Up @@ -39,7 +40,7 @@ class PoolBase:
all child processes in order to synchronize work between all processes. You
can also use `self.process_id`, which is an integer, unique per process,
increasing in value from 0 to processes-1 (if not specified, processes
defaults to os.cpu_count()).
defaults to len(psutil.Process().cpu_affinity()) ).

`run` will be called, in the child processes, potentially multiple times, in
order to process data.
Expand Down Expand Up @@ -70,7 +71,7 @@ def run(self, x):
@classmethod
def create_impl(cls, processes=None, context=None, initargs=(), *args, **kwargs):
if processes is None:
processes = os.cpu_count()
processes = len(psutil.Process().cpu_affinity())

if context is None:
context = multiprocessing
Expand Down