《PyTorch 2.5重磅更新:性能優(yōu)化+新特性》中的一個(gè)新特性就是:正式支持在英特爾獨(dú)立顯卡上訓(xùn)練模型!
PyTorch2.5 | |
獨(dú)立顯卡類(lèi)型 | 支持的操作系統(tǒng) |
英特爾數(shù)據(jù)中心 GPUMax系列 |
Linux |
英特爾 銳炫 系列 | Linux/Windows |
本文將在英特爾 酷睿 Ultra 7 155H自帶的銳炫 集成顯卡上展示使用Pytorch2.5搭建并訓(xùn)練AI模型的全流程。
1搭建開(kāi)發(fā)環(huán)境
首先,請(qǐng)安裝顯卡驅(qū)動(dòng),參考指南:
https://dgpu-docs.intel.com/driver/client/overview.html
并用下面的命令創(chuàng)建并激活名為pytorch_arc的虛擬環(huán)境:
conda create -n pytorch_arc python=3.11 #創(chuàng)建虛擬環(huán)境 conda activate pytorch_arc #激活虛擬環(huán)境 python -m pip install --upgrade pip #升級(jí)pip到最新版本
接著,安裝Pytorch XPU版;
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/xpu
最后,執(zhí)行命令,驗(yàn)證安裝。看到返回結(jié)果為“True”,證明環(huán)境搭建成功!
>>> import torch >>> torch.xpu.is_available()
2訓(xùn)練ResNet模型
執(zhí)行下載的訓(xùn)練代碼,實(shí)現(xiàn)在英特爾 銳炫 集成顯卡上訓(xùn)練ResNet50模型。代碼下載鏈接:
https://gitee.com/Pauntech/Pytorch-2.5
import torchimport torchvision LR = 0.001DOWNLOAD = TrueDATA = "datasets/cifar10/" transform = torchvision.transforms.Compose( [ torchvision.transforms.Resize((224, 224)), torchvision.transforms.ToTensor(), torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)), ])train_dataset = torchvision.datasets.CIFAR10( root=DATA, train=True, transform=transform, download=DOWNLOAD,)train_loader = torch.utils.data.DataLoader(dataset=train_dataset, batch_size=128)train_len = len(train_loader) model = torchvision.models.resnet50()criterion = torch.nn.CrossEntropyLoss()optimizer = torch.optim.SGD(model.parameters(), lr=LR, momentum=0.9)model.train()model = model.to("xpu")criterion = criterion.to("xpu") print(f"Initiating training")for batch_idx, (data, target) in enumerate(train_loader): data = data.to("xpu") target = target.to("xpu") optimizer.zero_grad() output = model(data) loss = criterion(output, target) loss.backward() optimizer.step() if (batch_idx + 1) % 10 == 0: iteration_loss = loss.item() print(f"Iteration [{batch_idx+1}/{train_len}], Loss: {iteration_loss:.4f}")torch.save( { "model_state_dict": model.state_dict(), "optimizer_state_dict": optimizer.state_dict(), }, "checkpoint.pth",) print("Execution finished")
3總結(jié)
使用PyTorch在英特爾獨(dú)立顯卡上訓(xùn)練模型將為AI行業(yè)新增計(jì)算硬件選擇!
-
英特爾
+關(guān)注
關(guān)注
61文章
10197瀏覽量
174764 -
顯卡
+關(guān)注
關(guān)注
16文章
2505瀏覽量
69574 -
AI
+關(guān)注
關(guān)注
88文章
35194瀏覽量
280312 -
模型
+關(guān)注
關(guān)注
1文章
3522瀏覽量
50452 -
pytorch
+關(guān)注
關(guān)注
2文章
809瀏覽量
13978
原文標(biāo)題:PyTorch 2.5 現(xiàn)已支持英特爾獨(dú)立顯卡訓(xùn)練
文章出處:【微信號(hào):英特爾物聯(lián)網(wǎng),微信公眾號(hào):英特爾物聯(lián)網(wǎng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
基于C#和OpenVINO?在英特爾獨(dú)立顯卡上部署PP-TinyPose模型
將英特爾?獨(dú)立顯卡與OpenVINO?工具套件結(jié)合使用時(shí),無(wú)法運(yùn)行推理怎么解決?
宿敵相爭(zhēng) AMD向英特爾授權(quán)顯卡芯片技術(shù)的可能性不大
英特爾高清顯卡4600幫助
在英特爾NUC上推出獨(dú)立游戲
英特爾推出了英特爾銳炬Xe MAX獨(dú)立顯卡
英特爾Iris Xe MAX獨(dú)立顯卡性能公布
英特爾推出面向OEM市場(chǎng)的入門(mén)級(jí)Xe獨(dú)立顯卡
英特爾推出銳炫A系列獨(dú)立顯卡 微星推出GeForce RTX 3090 Ti系列顯卡
在英特爾獨(dú)立顯卡上部署YOLOv5 v7.0版實(shí)時(shí)實(shí)例分割模型
英特爾銳炫Pro圖形顯卡上新!
如何在英特爾? 平臺(tái)上實(shí)現(xiàn)高效的大語(yǔ)言模型訓(xùn)練后量化

使用OpenVINO優(yōu)化并部署訓(xùn)練好的YOLOv7模型

使用英特爾AI PC為YOLO模型訓(xùn)練加速

評(píng)論