[英]How can we orchestrate and automate data movement and data transformation in AWS sagemaker pipeline
[英]Access Parameter's value directly in AWS Sagemaker Pipeline
在返回管道的函数内部,其中定义了参数,例如(取自此处)
def get_pipeline(...):
foo = ParameterString(
name="Foo", default_value="foo"
)
# pipeline's steps definition here
step = ProcessingStep(name=...,
job_arguments=["--foo", foo]
)
return pipeline = Pipeline(
name=pipeline_name,
parameters=[...],
steps=[...],
sagemaker_session=sagemaker_session,
)
我知道我可以通过简单地调用foo.default_value
来访问参数的默认值,但是当默认值在运行时被覆盖时我如何访问它的值,例如通过使用
pipeline.start(parameters=dict(Foo='bar'))
?
我的假设是,在那种情况下,我不想读取默认值,因为它已被覆盖,但参数 API非常有限,并且没有提供name
和default_value
所需的任何内容。
如文档中所写:
管道参数只能在运行时进行评估。 如果需要在编译时评估管道参数,则会抛出异常。
此外,还有一些限制: 并非所有内置的 Python 操作都可以应用于参数。
从上面的链接中获取的示例:
# An example of what not to do
my_string = "s3://{}/training".format(ParameterString(name="MyBucket", default_value=""))
# Another example of what not to do
int_param = str(ParameterInteger(name="MyBucket", default_value=1))
# Instead, if you want to convert the parameter to string type, do
int_param.to_string()
# A workaround is to use Join
my_string = Join(on="", values=[
"s3://",
ParameterString(name="MyBucket", default_value=""),
"/training"]
)
就个人而言,我更喜欢在开始之前获取管道定义时直接传递值:
def get_pipeline(my_param_hardcoded, ...):
# here you can use my_param_hardcoded
my_param = ParameterString(
name="Foo", default_value="foo"
)
# pipeline's steps definition here
return pipeline = Pipeline(
name=pipeline_name,
parameters=[my_param, ...],
steps=[...],
sagemaker_session=sagemaker_session,
)
return pipeline
pipeline = get_pipeline(my_param_hardcoded, ...)
pipeline.start(parameters=dict(Foo=my_param_hardcoded))
显然这不是一种真正优雅的方式,但我不认为这在概念上是错误的,因为毕竟它是一个将用于操纵管道的参数并且不能预先进行预处理(例如在配置文件中)。
一个使用示例是创建一个名称,该名称可以基于 pipeline_name(在 get_pipeline() 和管道参数中明确传递)。 例如,如果我们想为一个步骤创建一个自定义名称,它可以通过两个字符串的连接来给出,这不能在运行时发生,但必须使用这个技巧来完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.