套用動態量化
你已成功訓練好一個要部署的神經網路模型,接下來想用動態量化來最佳化。這一步對於在資源受限的環境中高效部署模型非常關鍵。
model 已預先載入。
本練習屬於課程
Scalable AI Models with PyTorch Lightning
練習說明
- 從 PyTorch 匯入需要的量化模組。
- 以線性層為目標套用動態量化,並使用 8 位元整數精度。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import torch
# Import the necessary quantization module
from torch.quantization import ____
# Apply dynamic quantization targeting linear layers
model_quantized = torch.quantization.____(
____, {torch.nn.____}, dtype=torch.____
)