簡介、安裝、快速開始
## PyTorch 是什麼?
PyTorch 是一套開源的深度學習框架,主要用途包括:
- 建立與訓練神經網路模型
- 電腦視覺、自然語言處理、生成式 AI
- 張量(Tensor)運算與 GPU 加速
- 自動微分與模型推論
## 安裝方式
### 使用 pip(CPU 版本)
```bash
pip install torch torchvision torchaudio
```
### 使用 conda
```bash
conda install pytorch torchvision torchaudio -c pytorch
```
若要使用 NVIDIA GPU,建議到 [PyTorch 官方安裝頁面](https://pytorch.org/get-started/locally/) 依照作業系統、CUDA 版本產生適合的安裝指令。
## 3 行內驗證範例
```python
import torch
print(torch.__version__, torch.tensor([1, 2, 3]) * 2)
print("GPU 可用:", torch.cuda.is_available())
```
若能正常輸出 PyTorch 版本與張量結果,即代表安裝成功;`GPU 可用` 顯示 `True` 則表示 PyTorch 可使用 CUDA GPU。
相關學習地圖、教學課程
Python 人工智慧