虽然上一篇文章有提到,在工作区- workspace
执行实验时,需要先设定环境,也需要上传需要用到的资料,但是这一篇文章要执行的实验十分简单,只是要印出Hello, world!
,所以不需要额外的资料,环境也可以直接用预设的环境。在workspace
预设的环境中,用的Python
版本是3.6.2,套件则是只安装了azureml-defaults
。
在workspace
执行实验时,至少需要两个Python
script:
workspace
利用计算丛集执行的程序码:hello.py
run_experiment.py
在本机执行,用来通知workspace
开始执行上述的 scripthello.py
print("Hello, Azure!")
run_experiment.py
import os
from azureml.core import Workspace, Experiment, ScriptRunConfig
from azureml.core.authentication import InteractiveLoginAuthentication
def main():
"""
Hello on Azure machine learning.
"""
interactive_auth = InteractiveLoginAuthentication(tenant_id=os.getenv("TENANT_ID"))
work_space = Workspace.from_config(auth=interactive_auth)
# 建立实验
experiment = Experiment(workspace=work_space, name="hello-experiment")
# 设定 config
config = ScriptRunConfig(
source_directory=".", # code放在哪个资料夹
script="hello.py", # 要上传的code
compute_target="cpu-cluster" # 指定计算丛集
)
# 让实验依照 config 执行
run = experiment.submit(config)
aml_url = run.get_portal_url()
print(aml_url)# 此连结可以看到 log
run.wait_for_completion(show_output=True)# 过程中的纪录都会列出
if __name__ == "__main__":
main()
准备好上述程序码後,我们就能执行:
python3.7 run_experiment.py
执行之後,程序码会把程序码上传执行。执行的时间大概要十几分钟左右,这时候你会想,为什麽要这麽久?因为......
Azure 会从 build docker image 开始,build 完,然後再推到 Azure Container Registry- ACR 存放,这一步应该就是最花时间的步骤了。到workspace
,进入实验
(下图中,左侧 烧杯 图示)中查看输出 + 纪录档
,可以看到20_image_build_log.txt
,这档案纪录上述过程。
接着,会把 dcoker image 拉到虚拟机器中展开成 container(记录在55_azureml-excution-tvmp_xxxxx.txt
)。
然後,把需要执行的程序码放入 container 之中(记录在65_jobp_prep-tvmp_xxxxx.txt
)。
终於可以执行print("Hello Azure!")
了。如果上传的程序码出错,也可以从这里的纪录发现错误讯息。通常会出问题的地方,多半是在使用者想要执行的程序码上,所以可以透过观察 70_driver_log.txt
发现问题所在。
最後结束实验,把运算资源释放出来。
这篇文章只是先观察执行实验的时候,实际上在workspace
会做些什麽。往後的文章,会从资料上传开始,一一演示每项工作。
>>: Day 15 储存宝石:S3 架构 & 版本控管 (Versioning)
Christopher Alexander 在「建筑的永恒之道」中,开头第一句就说了:「无心之心,道...
前言 所以说LIFF Bluetooth能用在哪里? 最近我买了一台智能电风扇,当觉得热,又觉得伫立...
-SAMM 概述(来源:https : //owaspsamm.org) 软件保障成熟度模型(SA...
结构 主要可以分为四个部分「state」、「getters」、「mutation」、「actions...
为了让元素的边界格线看得更清楚, 这边统一对<body>之外的所有元素加上outline...