1

I'm trying to run YOLOv8 inference using Ultralytics on CPU, but I get a RuntimeError: could not create a primitive. I'm using Windows and working in a virtual environment with PyTorch. I'm new to YOLO and would appreciate help understanding this.

🔁 Code I'm using:

from ultralytics import YOLO

model = YOLO('yolov8n')
results = model.predict('input_videos/08fd33_4.mp4', save=True, device='cpu', stream=True)

for r in results:
    print(r)
    print('======================================')
    for box in r.boxes:
        print(box)

Error:

RuntimeError: could not create a primitive  
  File ".../torch/nn/modules/conv.py", line 549, in _conv_forward  
    return F.conv2d(...)

My environment:

OS: Windows 11
Python: 3.12.9
Torch: 2.7.0
Ultralytics: 8.3.133
Device: CPU (no GPU)

My questions:

  • How can I fix this error when running YOLOv8 on CPU?
  • Is it possible the model needs GPU even for basic prediction?
  • Are there config settings to make it work safely on CPU under Windows?

2 Answers 2

0

I think this is a known PyTorch/Windows compatibility issue. Try to install it using:

pip uninstall torch torchvision torchaudio
pip install torch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 --index-url https://download.pytorch.org/whl/cpu

Also, can try to downgrade Ultralytics and test

pip install ultralytics==8.2.7
Sign up to request clarification or add additional context in comments.

Comments

0

You're encountering this error because YOLOv8 (via PyTorch 2.7.0 on Windows 11, CPU-only) hits a known issue related to oneDNN (formerly MKL-DNN) — the CPU backend used by PyTorch to accelerate operations like convolutions. The error:

RuntimeError: could not create a primitive 

means PyTorch fails to initialize a low-level CPU primitive, usually due to an incompatibility between your CPU, PyTorch version, and oneDNN defaults.

Why Does It Happen?

  • PyTorch uses oneDNN (DNNL) for CPU acceleration.

  • Some ops (e.g., conv2d) rely on advanced CPU instructions (AVX2, AVX-512).

  • On some machines (especially Windows or non-Intel CPUs), creating the "primitive" for those ops fails.

This is not a YOLO issue — it’s a PyTorch + oneDNN runtime incompatibility

One simple fix is to downgrade PyTorch to a more compatible version.

I tested it on my local machine on the following configurations:

OS: Windows 11
Python: 3.10.9
Torch: 2.6.0
Ultralytics: 8.3.135
Device: CPU (no GPU)

(It should also work with your Python version).

enter image description here

Use the following steps to downgrade the torch:

  • create a virtual environment:

    python -n venv torch_env
    
  • activate the environment:

    torch_env\Scripts\activate
    
  • install typing-extensions with the given version

    pip install typing-extensions==4.12.2
    
  • Downgrade the torch (I used 2.6.0, use the below versions since all of them have to compatible with eachother)

    pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu
    
  • and finally, install ultralytics:

    pip install ultralytics
    

These are all the steps that I did to setup in order to test your code and it's working.

Now, you're good to go and run your script as it is.

Here's the code:

from ultralytics import YOLO
model = YOLO('yolov8n')
results = model.predict('C:\\Users\\PC\\Downloads\\IMG_4770.MOV', save=True, device='cpu', stream=True)
for r in results:
        print(r)
        print('======================================')
        for box in r.boxes:
            print(box)

output:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.