I am running a simple while loop for inference on CPU. I want the inference to run only on 1 CPU, but it seems like PyTorch changes the process affinity. I can see from htop that jobs are being scheduled on multiple CPUs that I do not expect.
My python program.
import os
import torch
from torchvision.models import resnet50

os.sched_setaffinity(os.getpid(), {0})
print('Set PID-{} to affinity: {}'.format(os.getpid(), os.sched_getaffinity(os.getpid())))

net = resnet50()
net.eval()
while True:
    with torch.no_grad():
        net(torch.randn(1, 3, 224, 224))

Output from affinity setting and my htop monitoring.

Screen Shot 2020-02-22 at 3.09.51 PM939×27 1.8 KB



Screen Shot 2020-02-22 at 3.10.07 PM949×964 135 KB

Is this a bug or misuse from my side?