1. Intro
-
到目前为止,已覆盖相当多的领域,若使用Colab,要设置GPU;
-
Runtime ☞ Change Runtime Type ☞ Hardware Acceleration
☞ GPU,若这样做,则会重置Colab运行时,且会丢失保存的变量;
# ==== A:Import ====
# import PyTorch and matplotlib
import torch
# nn contain all of PyTorch building block for neural network
from torch import nn
import matplotlib.pyplot as plt
# check PyTorch Version
print(f"PyTorch Version: {torch.__version__}")
# ==== B:Setup Device Agnostic Code ====
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using Device: {device}")
PyTorch Version: 2.3.0+cu121
Using Device: cuda