Limit predictions computing to single CPU core?

I found that doing the following at the top of my python code does properly limit transformers to only a single CPU core:

import os
import tensorflow as tf
tf.config.threading.set_inter_op_parallelism_threads(1)
tf.config.threading.set_intra_op_parallelism_threads(1)
os.environ["OMP_NUM_THREADS"] = "1"
1 Like