Install pytorch and use the code in both mac and linux

I have a python repository with a script that uses torch. I am dockerizing it (installing all packages in requirements.txt) and want to run it:

  1. on Mac, which does not use GPU
  2. on Linux, which does use GPU.

According to the website, in order to install it on a mac I should do:
pip3 install torch
In order to install it on a Linux machine I should do:
pip3 install torch --index-url https://download.pytorch.org/whl/cu118

My question: how can I install it (what should I specify in the requirements.txt - I am actually using pyenv locally when developing on a Mac) such that when I dockerize it on either Mac or Linux it will use cpu only (if on a Mac) and GPU if on the Linux?

Thanks,
Yuval