Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Limiting threads in TensorFlow

Abierto
#84 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
numpy, python, scikit-learn, tensorflow

Línea de trabajo

Start by reading the threadpoolctl code that discovers and controls native thread pools, then check whether TensorFlow exposes a supported control point in the version discussed (2.5.0). Reproduce the example with threadpool_limits(limits=1) and compare CPU time with and without the limit. Done means TensorFlow work respects the requested limit, or the issue documents why threadpoolctl cannot control it and what limitation users should expect.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

As far as I can tell, limiting the number of threads in TensorFlow with threadpoolctl currently doesn't work.

For instance with the following minimal example with Tensorflow 2.5.0,
example.py

import tensorflow as tf
import numpy as np

from threadpoolctl import threadpool_limits

with threadpool_limits(limits=1):
    X = tf.constant(np.arange(0, 5000**2, dtype=np.int32), shape=(5000, 5000))
    
    tf.matmul(X, X)

running,

time python example.py

on a 64 cores CPU, produces,

real    0m3.781s
user    1m8.685s

so the user (CPU) time is still >> real run time, meaning that many CPU are used.

This becomes an issue if people run scikit-learn's GridSearchCV or cross_validate on a Keras or TensorFlow model, since it then results in CPU over-subscription. I'm surprised there are no more issues about it at scikit-learn.

Tensorflow also regrettably doesn't recognize any environment variables to limit the number of CPU cores either. The only way I found around it is to set the CPU affinity mask with taskset. But then again it wouldn't help for cross-validation for instance, since joblib would then need to set the affinity mask when creating new processes which is currently not supported.

Has anyone looked into this in the past by any chance?

Lenguaje dominante
Python
Estrellas
434
Forks
38
Merge medio
2 d 14 h
PR fusionados (30 d)
8

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de joblib/threadpoolctl

Todos los issues de joblib/threadpoolctl

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.