From 7d0e9f8237daa2af8ca947efe4e5c5fad21c4b60 Mon Sep 17 00:00:00 2001 From: "zzysz@qq.com" Date: Thu, 28 Aug 2025 17:06:45 +0800 Subject: [PATCH] =?UTF-8?q?npu=E7=9A=84=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E5=92=8C=E7=AE=97=E6=B3=95=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- npu/helloworld.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++ npu/input.zip | Bin 0 -> 247 bytes 2 files changed, 49 insertions(+) create mode 100644 npu/helloworld.py create mode 100644 npu/input.zip diff --git a/npu/helloworld.py b/npu/helloworld.py new file mode 100644 index 0000000..410d849 --- /dev/null +++ b/npu/helloworld.py @@ -0,0 +1,49 @@ +import torch +import moxing as mox +import os +import argparse +import torch_npu # 确保安装了 torch_npu + +# 创建参数解析器 +parser = argparse.ArgumentParser(description='Training script with output path option') +parser.add_argument('--input', default=None, type=str, help='input, where the dataset is stored.') +parser.add_argument('--output', type=str, default='', help='Output path for saving the result') +args = parser.parse_args() + +# 检查 NPU 是否可用 +try: + import torch_npu + + if torch_npu.npu.is_available(): + device = torch.device('npu') + print("Using NPU for training.") + else: + device = torch.device('cpu') + print("NPU is not available, using CPU for training.") +except ImportError: + device = torch.device('cpu') + print("torch_npu module not found, using CPU for training.") + +# 模拟一个简单的训练过程 +# 这里其实不涉及真正的模型训练,只是作为示例流程展示 +# 输出 Hello World +result = "Hello World" +print(result) + +# 将结果保存到本地文件 +local_result_path = 'hellworld.pth' +with open(local_result_path, 'w') as f: + f.write(result) + +# 根据参数确定 OBS 路径 +obs_result_path = args.output if args.output else 'obs://nudt-cloudream2/cds/trainResult/model/hellworld.pth' +# 如果传入的路径不是以斜杠结尾,则添加斜杠 +if obs_result_path and not obs_result_path.endswith('/'): + obs_result_path += '/' +obs_result_path += 'hellworld.pth' + +try: + mox.file.copy(local_result_path, obs_result_path) + print(f"Result has been successfully saved to {obs_result_path}") +except Exception as e: + print(f"Failed to save result to OBS: {e}") diff --git a/npu/input.zip b/npu/input.zip new file mode 100644 index 0000000000000000000000000000000000000000..16ed5517a7bc04bd5dcfaa80aacb5add7317c4f8 GIT binary patch literal 247 zcmaFAdw+m8Gm8iV2N1sBzqbsCqZp6?CxZe*W?n&QiC#%XNofT)10xGa7EFYO@G`Ii zHK^%ipphOxJ_P9lDG>H#WC-wP=K!)4AQC)4Q@DUQz?+dtgc;QVn5sA#BtX`J0YpED diQ8eU42(c!K!*i*v$BDdG6JDLkWL117yxVZOjiH^ literal 0 HcmV?d00001