View a markdown version of this page

使用 modeltransform 命令进行模型转换 - Amazon Neptune

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 modeltransform 命令进行模型转换

您可以使用 Neptune ML modeltransform 命令创建模型转换任务、检查其状态、停止它或列出所有活动的模型转换任务。

使用 Neptune ML modeltransform 命令创建模型转换任务

用于创建增量转换任务的 Neptune ML modeltransform 命令(无需重新训练模型)如下所示:

AWS CLI
aws neptunedata start-ml-model-transform-job \ --endpoint-url https://your-neptune-endpoint:port \ --id "(a unique model-transform job ID)" \ --data-processing-job-id "(the job-id of a completed data-processing job)" \ --ml-model-training-job-id "(the job-id of a completed model-training job)" \ --model-transform-output-s3-location "s3://(your S3 bucket)/neptune-model-transform"

有关更多信息,请参阅《 AWS CLI 命令参考》中的 start-ml-model-transform-job

SDK
import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.start_ml_model_transform_job( id='(a unique model-transform job ID)', dataProcessingJobId='(the job-id of a completed data-processing job)', mlModelTrainingJobId='(the job-id of a completed model-training job)', modelTransformOutputS3Location='s3://(your S3 bucket)/neptune-model-transform' ) print(response)
awscurl
awscurl https://your-neptune-endpoint:port/ml/modeltransform \ --region us-east-1 \ --service neptune-db \ -X POST \ -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-transform job ID)", "dataProcessingJobId" : "(the job-id of a completed data-processing job)", "mlModelTrainingJobId" : "(the job-id of a completed model-training job)", "modelTransformOutputS3Location" : "s3://(your S3 bucket)/neptune-model-transform" }'
注意

此示例假设您的 AWS 证书是在您的环境中配置的。us-east-1替换为 Neptune 集群的区域。

curl
curl \ -X POST https://your-neptune-endpoint:port/ml/modeltransform \ -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-transform job ID)", "dataProcessingJobId" : "(the job-id of a completed data-processing job)", "mlModelTrainingJobId" : "(the job-id of a completed model-training job)", "modelTransformOutputS3Location" : "s3://(your S3 bucket)/neptune-model-transform" }'

用于从已完成的 SageMaker AI 训练作业中创建任务的 Neptune ML modeltransform 命令如下所示:

AWS CLI
aws neptunedata start-ml-model-transform-job \ --endpoint-url https://your-neptune-endpoint:port \ --id "(a unique model-transform job ID)" \ --training-job-name "(name of a completed SageMaker training job)" \ --model-transform-output-s3-location "s3://(your S3 bucket)/neptune-model-transform"

有关更多信息,请参阅《 AWS CLI 命令参考》中的 start-ml-model-transform-job

SDK
import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.start_ml_model_transform_job( id='(a unique model-transform job ID)', trainingJobName='(name of a completed SageMaker training job)', modelTransformOutputS3Location='s3://(your S3 bucket)/neptune-model-transform' ) print(response)
awscurl
awscurl https://your-neptune-endpoint:port/ml/modeltransform \ --region us-east-1 \ --service neptune-db \ -X POST \ -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-transform job ID)", "trainingJobName" : "(name of a completed SageMaker training job)", "modelTransformOutputS3Location" : "s3://(your S3 bucket)/neptune-model-transform" }'
注意

此示例假设您的 AWS 证书是在您的环境中配置的。us-east-1替换为 Neptune 集群的区域。

curl
curl \ -X POST https://your-neptune-endpoint:port/ml/modeltransform \ -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-transform job ID)", "trainingJobName" : "(name of a completed SageMaker training job)", "modelTransformOutputS3Location" : "s3://(your S3 bucket)/neptune-model-transform" }'

用于创建使用自定义模型实现的任务的 Neptune ML modeltransform 命令如下所示:

AWS CLI
aws neptunedata start-ml-model-transform-job \ --endpoint-url https://your-neptune-endpoint:port \ --id "(a unique model-transform job ID)" \ --training-job-name "(name of a completed SageMaker training job)" \ --model-transform-output-s3-location "s3://(your Amazon S3 bucket)/neptune-model-transform/" \ --custom-model-transform-parameters '{ "sourceS3DirectoryPath": "s3://(your Amazon S3 bucket)/(path to your Python module)", "transformEntryPointScript": "(your transform script entry-point name in the Python module)" }'

有关更多信息,请参阅《 AWS CLI 命令参考》中的 start-ml-model-transform-job

SDK
import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.start_ml_model_transform_job( id='(a unique model-transform job ID)', trainingJobName='(name of a completed SageMaker training job)', modelTransformOutputS3Location='s3://(your Amazon S3 bucket)/neptune-model-transform/', customModelTransformParameters={ 'sourceS3DirectoryPath': 's3://(your Amazon S3 bucket)/(path to your Python module)', 'transformEntryPointScript': '(your transform script entry-point name in the Python module)' } ) print(response)
awscurl
awscurl https://your-neptune-endpoint:port/ml/modeltransform \ --region us-east-1 \ --service neptune-db \ -X POST \ -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-transform job ID)", "trainingJobName" : "(name of a completed SageMaker training job)", "modelTransformOutputS3Location" : "s3://(your Amazon S3 bucket)/neptune-model-transform/", "customModelTransformParameters" : { "sourceS3DirectoryPath": "s3://(your Amazon S3 bucket)/(path to your Python module)", "transformEntryPointScript": "(your transform script entry-point name in the Python module)" } }'
注意

此示例假设您的 AWS 证书是在您的环境中配置的。us-east-1替换为 Neptune 集群的区域。

curl
curl \ -X POST https://your-neptune-endpoint:port/ml/modeltransform \ -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-transform job ID)", "trainingJobName" : "(name of a completed SageMaker training job)", "modelTransformOutputS3Location" : "s3://(your Amazon S3 bucket)/neptune-model-transform/", "customModelTransformParameters" : { "sourceS3DirectoryPath": "s3://(your Amazon S3 bucket)/(path to your Python module)", "transformEntryPointScript": "(your transform script entry-point name in the Python module)" } }'
用于创建 modeltransform 任务的参数
  • id –(可选)新任务的唯一标识符。

    类型:字符串。默认:自动生成的 UUID。

  • dataProcessingJobId– 已完成的数据处理任务的任务 ID。

    类型:字符串。

    注意:必须同时包含 dataProcessingJobIdmlModelTrainingJobIdtrainingJobName

  • mlModelTrainingJobId – 已完成的模型训练任务的任务 ID。

    类型:字符串。

    注意:必须同时包含 dataProcessingJobIdmlModelTrainingJobIdtrainingJobName

  • trainingJobName— 已完成的 A SageMaker I 训练作业的名称。

    类型:字符串。

    注意:必须同时包含 dataProcessingJobIdmlModelTrainingJobId 参数或 trainingJobName 参数。

  • sagemakerIamRoleArn—(可选)用于 A SageMaker I 执行的 IAM 角色的 ARN。

    类型:字符串。注意:必须将其列在您的数据库集群参数组中,否则将发生错误。

  • neptuneIamRoleArn—(可选)向 Neptune 提供 AI 和 A SageMaker mazon S3 资源访问权限的 IAM 角色的 ARN。

    类型:字符串。注意:必须将其列在您的数据库集群参数组中,否则将发生错误。

  • customModelTransformParameters –(可选)使用自定义模型进行模型转换的配置信息。customModelTransformParameters 对象包含以下字段,这些字段的值必须与训练任务中保存的模型参数兼容:

    • sourceS3DirectoryPath –(必需)实现您的模型的 Python 模块所在的 Amazon S3 位置的路径。这必须指向有效的现有 Amazon S3 位置,其中至少包含训练脚本、转换脚本和 model-hpo-configuration.json 文件。

    • transformEntryPointScript –(可选)脚本模块中入口点的名称,该脚本应在确定超参数搜索中的最佳模型之后运行,以计算模型部署所需的模型构件。它应该能够在没有命令行参数的情况下运行。

      默认值transform.py

  • baseProcessingInstanceType –(可选)用于准备和管理机器学习模型训练的机器学习实例的类型。

    类型:字符串。注意:这是根据用于处理转换数据和模型的内存要求选择的 CPU 实例。请参阅为模型训练和模型转换选择实例

  • baseProcessingInstanceVolumeSizeInGB –(可选)训练实例的磁盘卷大小。输入数据和输出模型都存储在磁盘上,因此卷大小必须足够大,以容纳两个数据集。

    类型:整数。默认值0

    注意:如果未指定或为 0,Neptune ML 会根据数据处理步骤中生成的建议选择磁盘卷大小。请参阅为模型训练和模型转换选择实例

  • subnets—(可选)Ne IDs ptune VPC 中的子网。

    类型:字符串列表。默认值

  • securityGroupIds—(可选)VPC 安全组 IDs。

    类型:字符串列表。默认值

  • volumeEncryptionKMSKey—(可选) SageMaker AI 用来加密连接到运行转换作业的 ML 计算实例的存储卷上的数据的 AWS Key Management Service (AWS KMS) 密钥。

    类型:字符串。默认值

  • enableInterContainerTrafficEncryption –(可选)在训练或超参数调整任务中启用或禁用容器间流量加密。

    类型:布尔值。默认值True

    注意

    enableInterContainerTrafficEncryption 参数仅在引擎版本 1.2.0.2.R3 中可用。

  • s3OutputEncryptionKMSKey—(可选AWS KMS) SageMaker AI 用来加密处理作业输出的 AWS Key Management Service () 密钥。

    类型:字符串。默认值

使用 Neptune ML modeltransform 命令获取模型转换任务的状态

用于显示任务状态的示例 Neptune ML modeltransform 命令如下所示:

AWS CLI
aws neptunedata get-ml-model-transform-job \ --endpoint-url https://your-neptune-endpoint:port \ --id "(the job ID)"

有关更多信息,请参阅《 AWS CLI 命令参考》中的 get-ml-model-transform-job

SDK
import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.get_ml_model_transform_job( id='(the job ID)' ) print(response)
awscurl
awscurl https://your-neptune-endpoint:port/ml/modeltransform/(the job ID) \ --region us-east-1 \ --service neptune-db \ -X GET
注意

此示例假设您的 AWS 证书是在您的环境中配置的。us-east-1替换为 Neptune 集群的区域。

curl
curl -s \ "https://your-neptune-endpoint:port/ml/modeltransform/(the job ID)" \ | python -m json.tool
modeltransform 任务状态的参数
  • id –(必需)模型转换任务的唯一标识符。

    类型:字符串。

  • neptuneIamRoleArn—(可选)向 Neptune 提供 AI 和 A SageMaker mazon S3 资源访问权限的 IAM 角色的 ARN。

    类型:字符串。注意:必须将其列在您的数据库集群参数组中,否则将发生错误。

使用 Neptune ML modeltransform 命令停止模型转换任务

用于停止任务的示例 Neptune ML modeltransform 命令如下所示:

AWS CLI
aws neptunedata cancel-ml-model-transform-job \ --endpoint-url https://your-neptune-endpoint:port \ --id "(the job ID)"

要同时清理 Amazon S3 工件,请执行以下操作:

aws neptunedata cancel-ml-model-transform-job \ --endpoint-url https://your-neptune-endpoint:port \ --id "(the job ID)" \ --clean

有关更多信息,请参阅《 AWS CLI 命令参考》中的 cancel-ml-model-transform-job

SDK
import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.cancel_ml_model_transform_job( id='(the job ID)', clean=True ) print(response)
awscurl
awscurl https://your-neptune-endpoint:port/ml/modeltransform/(the job ID) \ --region us-east-1 \ --service neptune-db \ -X DELETE

要同时清理 Amazon S3 工件,请执行以下操作:

awscurl "https://your-neptune-endpoint:port/ml/modeltransform/(the job ID)?clean=true" \ --region us-east-1 \ --service neptune-db \ -X DELETE
注意

此示例假设您的 AWS 证书是在您的环境中配置的。us-east-1替换为 Neptune 集群的区域。

curl
curl -s \ -X DELETE "https://your-neptune-endpoint:port/ml/modeltransform/(the job ID)"

或者:

curl -s \ -X DELETE "https://your-neptune-endpoint:port/ml/modeltransform/(the job ID)?clean=true"
modeltransform 停止任务的参数
  • id –(必需)模型转换任务的唯一标识符。

    类型:字符串。

  • neptuneIamRoleArn—(可选)向 Neptune 提供 AI 和 A SageMaker mazon S3 资源访问权限的 IAM 角色的 ARN。

    类型:字符串。注意:必须将其列在您的数据库集群参数组中,否则将发生错误。

  • clean –(可选)此标志指定在任务停止时应删除所有 Amazon S3 构件。

    类型:布尔值。默认值FALSE

使用 Neptune ML modeltransform 命令列出活动的模型转换任务

用于列出活动任务的示例 Neptune ML modeltransform 命令如下所示:

AWS CLI
aws neptunedata list-ml-model-transform-jobs \ --endpoint-url https://your-neptune-endpoint:port

要限制结果数量,请执行以下操作:

aws neptunedata list-ml-model-transform-jobs \ --endpoint-url https://your-neptune-endpoint:port \ --max-items 3

有关更多信息,请参阅《 AWS CLI 命令参考》中的 list-ml-model-transform-job s。

SDK
import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://your-neptune-endpoint:port', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.list_ml_model_transform_jobs( maxItems=3 ) print(response)
awscurl
awscurl https://your-neptune-endpoint:port/ml/modeltransform \ --region us-east-1 \ --service neptune-db \ -X GET

要限制结果数量,请执行以下操作:

awscurl "https://your-neptune-endpoint:port/ml/modeltransform?maxItems=3" \ --region us-east-1 \ --service neptune-db \ -X GET
注意

此示例假设您的 AWS 证书是在您的环境中配置的。us-east-1替换为 Neptune 集群的区域。

curl
curl -s "https://your-neptune-endpoint:port/ml/modeltransform" | python -m json.tool

或者:

curl -s "https://your-neptune-endpoint:port/ml/modeltransform?maxItems=3" | python -m json.tool
modeltransform 列出任务的参数
  • maxItems –(可选),表示要返回的最大项目数。

    类型:整数。默认值10允许的最大值1024

  • neptuneIamRoleArn—(可选)向 Neptune 提供 AI 和 A SageMaker mazon S3 资源访问权限的 IAM 角色的 ARN。

    类型:字符串。注意:必须将其列在您的数据库集群参数组中,否则将发生错误。