简体   繁体   English

直接在 AWS Sagemaker Pipeline 中访问参数的值

[英]Access Parameter's value directly in AWS Sagemaker Pipeline

Inside a function that returns a Pipeline, where a Parameter is defined, eg (taken from here )在返回管道的函数内部,其中定义了参数,例如(取自此处

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,
    )

I know I can access the default value of a parameter by simply calling foo.default_value , but how can I access its value when the default value is overridden at the runtime, eg by using我知道我可以通过简单地调用foo.default_value来访问参数的默认值,但是当默认值在运行时被覆盖时我如何访问它的值,例如通过使用

pipeline.start(parameters=dict(Foo='bar'))

?

My assumption is that in that case I don't want to read the default value, since it has been overridden, but the Parameter API is very limited and does not provided anything expect for name and default_value .我的假设是,在那种情况下,我不想读取默认值,因为它已被覆盖,但参数 API非常有限,并且没有提供namedefault_value所需的任何内容。

As written in the documentation :文档中所写:

Pipeline parameters can only be evaluated at run time.管道参数只能在运行时进行评估。 If a pipeline parameter needs to be evaluated at compile time, then it will throw an exception.如果需要在编译时评估管道参数,则会抛出异常。


In addition, there are some limitations: Not all built-in Python operations can be applied to parameters .此外,还有一些限制: 并非所有内置的 Python 操作都可以应用于参数

An example taken from the link above:从上面的链接中获取的示例:

# 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"]
)

A way to use parameters to manipulate the pipeline internally一种使用参数在内部操作管道的方法

Personally, I prefer to pass the value directly when you get the pipeline definition before the start:就个人而言,我更喜欢在开始之前获取管道定义时直接传递值:

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))

Obviously this is not a really elegant way, but I do not think it is conceptually wrong because after all it is a parameter that will be used to manipulate the pipeline and cannot be pre-processed beforehand (eg in a configuration file).显然这不是一种真正优雅的方式,但我不认为这在概念上是错误的,因为毕竟它是一个将用于操纵管道的参数并且不能预先进行预处理(例如在配置文件中)。

An example of use is the creation of a name which can be based on the pipeline_name (which is clearly passed in the get_pipeline() and a pipeline parameter).一个使用示例是创建一个名称,该名称可以基于 pipeline_name(在 get_pipeline() 和管道参数中明确传递)。 For example, if we wanted to create a custom name for a step, it could be given by the concatenation of the two strings, and this cannot happen at runtime but must be done with this trick.例如,如果我们想为一个步骤创建一个自定义名称,它可以通过两个字符串的连接来给出,这不能在运行时发生,但必须使用这个技巧来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何在 AWS sagemaker 管道中编排和自动化数据移动和数据转换 - How can we orchestrate and automate data movement and data transformation in AWS sagemaker pipeline AWS Sagemaker 在线特征存储数据存储 - AWS Sagemaker online feature store data storage SageMaker Studio:我使用的是哪个 AWS 用户配置文件? - SageMaker Studio: which AWS user profile am I using? 如何根据预定义的计划运行 AWS Sagemaker Studio 作业 - How to run AWS Sagemaker Studio job based on pre defined schedule 如何使用 API 网关集成访问 Node js AWS Lambda 中的 POST 参数? - How do I access a POST parameter in Node js AWS Lambda with API Gateway integration? 如何远程连接到 GCP ML Engine/AWS Sagemaker 托管笔记本? - How to remotely connect to GCP ML Engine/AWS Sagemaker managed notebooks? 如何从端点内访问 sagemaker 模型注册表指标 - How to access sagemaker model registry metrics from within the endpoint aws eks bitbucket 管道权限错误 - Aws eks bitbucket pipeline permission error 是否可以将 aws codepipeline 转换为 bitbucket 管道? - Is it possible to convert an aws codepipeline to bitbucket pipeline? AWS/Step 函数:访问传递的标头值 - AWS/Step function: Access passed-over header value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM