Day 27 Azure machine learning: Schedule- Azure 为你定期执行任务

Azure machine learning: Schedule- Azure 为你定期执行任务

前面利用pipeline管线把好几个不同的工作项目串接起来了,接下来就可以利用schedule的功能,让整个管线定期执行。这就好比用crontab在本地端让自己的程序码定期执行一样,而 Azure 则是在云端用schedule实验排程的功能,这样一来,所有功能都能在云端执行,自己也不用准备 server 随时待命,Azure machine learning 执行完也会把纪录留下,有需要再到workspace检查即可。接下来就相当单纯了,只要选定之前已经发布的管线,设定好时间与频率,使其定期发动。

示范程序

import os
from azureml.core import Workspace
from azureml.core.authentication import InteractiveLoginAuthentication
from azureml.pipeline.core import PublishedPipeline

from azureml.pipeline.core.schedule import ScheduleRecurrence, Schedule, TimeZone


def main():

    interactive_auth = InteractiveLoginAuthentication(tenant_id=os.getenv("TENANT_ID"))
    work_space = Workspace.from_config(auth=interactive_auth)
    # 只有已发布的 pipeline 才能进行排程
    pipelines = PublishedPipeline.list(work_space)
    pipeline_id = next(
        p_l.id for p_l in pipelines if p_l.name == "pipeline_data_train_deploy"
    )
    # 排程的时候,要注意时区,才能确保在正确的时间执行
    recurrence = ScheduleRecurrence(
        frequency="Week", # 触发排程频率的时间单位,可以是 "Minute"、"Hour"、"Day"、"Week" 或 "Month"。
        interval=1, # 间隔多少时间单位触发
        start_time="2021-07-21T07:00:00", 
        time_zone=TimeZone.TaipeiStandardTime,
        week_days=["Sunday"], # 如果每周执行的话,可以选择某一天执行
        time_of_day="6:00",
    )
    Schedule.create(
        work_space,
        name="pipeline_data_train_deploy",
        description="Get data, train model and deploy service at 6:00 every Sunday",
        pipeline_id=pipeline_id,
        experiment_name="pipeline_data_train_deploy",
        recurrence=recurrence,
    )


if __name__ == "__main__":
    main()

执行python3.7 create_schedule.py之後,其实无法从workspace看到排程的相关资讯,不过可以透过以下做法得知目前所有排程

import os
from azureml.core import Workspace
from azureml.core.authentication import InteractiveLoginAuthentication
from azureml.pipeline.core import PublishedPipeline
from azureml.pipeline.core.schedule import Schedule

interactive_auth = InteractiveLoginAuthentication(tenant_id=os.getenv("TENANT_ID"))
work_space = Workspace.from_config(auth=interactive_auth)

sche_list = Schedule.list(work_space)
print(sche_list)

这样就能看到排程的资讯,其中也包含了详细的执行频率与时间,例如:每周日早上六点执行一次。

另外,如果管线已安排排程,那就必须把schedule删掉,才能删除pipeline。以上述情况为例:


sche = next(s for s in sche_list if s.id == "18ff1269-d837-42b6-85f1-972171ef6216")
sche.disable()
pipe_list = PublishedPipeline.list(work_space)
pipe = next(p_l.id for p_l in pipe_list if p_l.name == "pipeline_data_train_deploy")
pipe.disable()

一开始比较不熟悉,应该会很常删掉管线和排程,重复实验,所以提供大家参考。


经过几篇文章的折腾,现在我们有了一个可以预测汇率并且定期更新模型的服务,实作了MLOps。接下来,我们可以把它整合进 Line chatbot,提供预测汇率的私人服务了。(谜之声:下一篇就是最後一个中头目了~~)


<<:  [Day12] 注册API – urls之user app资料夹

>>:  Day13 跟着官方文件学习Laravel-了解RESTful API

[火锅吃到饱-19] 寿喜烧一丁 - 台中永春店 #甜点区也很赞~

这麽优质的店家,当然要推啦~(所以就再补一篇XD) 检查Youtube的影片,发现有漏网之鱼,这样不...

DAY 9:Worker Pool Pattern,就。很。Pool。

什麽是 Worker Pool Pattern? 设定好 pool 的 goroutine 数量,预...

30天学会C语言: Day 20-元元元运算子

一二三元 什麽叫做三元运算子?有三元运算子那有没有一元和二元运算子? 三元运算子就是运算元有三个的运...

Day15 Composer & Laravel - install

经过了两周的介绍,已经从古代慢慢走到了现代,也将环境准备的5566了,是时候该介绍我的工作核心:La...

[Day 11] Read取得资料

假设现在有资料在ProductController.php中,想要将资料显示给前端 public f...