[TOC]

概述

文章参考:https://pytorch.org/

文章参考:https://pytorch123.com/FirstSection/InstallIutorial/#12

安装教程

安装网址:https://pytorch.org/get-started/locally/

1
2
# MPS acceleration is available on MacOS 12.3+
pip3 install torch torchvision torchaudio

安装CPU版本

安装GPU版本

测试环境

输出结果如下,表明环境安装成功:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from __future__ import print_function
import torch


def print_hi(name):
# 在下面的代码行中使用断点来调试脚本。
print(f'Hi, {name}') # 按 Ctrl+F8 切换断点。


# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
print_hi('Hello Pytorch World')
print_hi(torch.__version__)
x = torch.rand(5, 3)

print(x)