It seems like you didn’t properly setup the python interpreter path (for your situation, it is something like <path to anaconda>/env/pytorch/bin/python).
I would recommend to use the integrated terminal (Win: ctrl + j, MacOS: command + j) of VS Code to run the script, where you can activate your conda environment with conda activate pytorch.