AI开发平台MODELARTS-示例:从 0 到 1 制作自定义镜像并用于训练(Pytorch+CPU/GPU):Step2 准备训练脚本并上传至OBS

时间:2024-11-12 16:42:18

Step2 准备训练脚本并上传至OBS

准备本案例所需的训练脚本“pytorch-verification.py”文件,并上传至OBS桶的“obs://test-modelarts/pytorch/demo-code/”文件夹下。

“pytorch-verification.py”文件内容如下:

import torch
import torch.nn as nn

x = torch.randn(5, 3)
print(x)

available_dev = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
y = torch.randn(5, 3).to(available_dev)
print(y)
support.huaweicloud.com/bestpractice-modelarts/develop-modelarts-0097.html