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

时间:2024-06-28 17:22:12

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/docker-modelarts/develop-modelarts-0097.html