本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Neptune ML 中的自定义模型概述
何时在 Neptune ML 中使用自定义模型
Neptune ML 的内置模型可处理 Neptune ML 支持的所有标准任务,但在某些情况下,您可能希望对特定任务的模型进行更精细的控制,或者需要自定义模型训练过程。例如,自定义模型在以下情况是合适的:
非常大型文本模型的文本功能的功能编码需要在 GPU 上运行。
你想使用在深图库 (DGL) 中开发的自定义图形神经网络 (GNN) 模型。
您想要使用表格模型或集成模型进行节点分类和回归。
在 Neptune ML 中开发和使用自定义模型的工作流
Neptune ML 中的自定义模型支持旨在无缝集成到现有的 Neptune ML 工作流程中。它的工作原理是在 Neptune ML 基础设施上的源模块中运行自定义代码来训练模型。就像内置模式一样,Neptune ML 会自动启动 SageMaker HyperParameter 调整作业,并根据评估指标选择最佳模型。然后,它使用源模块中提供的实现来生成用于部署的模型工件。
自定义模型的数据导出、训练配置和数据预处理与内置模型相同。
在数据预处理之后,您可以使用 Python 以迭代方式交互式开发和测试自定义模型实现。当您的模型处于生产状态时,您可以像下面这样将生成的 Python 模块上传到 Amazon S3:
aws s3 cp --recursive
(source path to module)
s3://(bucket name)
/(destination path for your module)
然后,你可以使用普通默认或者递增的将模型部署到生产环境的数据工作流程,但有一些差异。
对于使用自定义模型进行模型训练,必须提供customModelTrainingParameters
JSON 对象指向 Neptune ML 模型训练 API,以确保使用自定义代码。中的字段customModelTrainingParameters
对象如下所示:
sourceS3DirectoryPath
— (必需) 实现模型的 Python 模块所在的 Amazon S3 位置的路径。这必须指向一个有效的现有 Amazon S3 位置,该位置至少包含训练脚本、转换脚本和model-hpo-configuration.json
文件。-
trainingEntryPointScript
— (可选) 脚本模块中的入口点名称,该脚本执行模型训练并将超参数作为命令行参数,包括固定的超参数。默认值:
training.py
. -
transformEntryPointScript
— (可选) 脚本模块中的入口点名称,该脚本的入口点名称,该脚本应在确定超参数搜索中的最佳模型后运行,以计算模型部署所需的模型工件。它应该能够在没有命令行参数的情况下运行。默认值:
transform.py
.
例如:
curl \ -X POST https://
(your Neptune endpoint)
/ml/modeltraining -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-training job ID)
", "dataProcessingJobId" : "(the data-processing job-id of a completed job)
", "trainModelS3Location" : "s3://(your Amazon S3 bucket)
/neptune-model-graph-autotrainer" "modelName": "custom", "customModelTrainingParameters" : { "sourceS3DirectoryPath": "s3://(your Amazon S3 bucket)
/(path to your Python module)
", "trainingEntryPointScript": "(your training script entry-point name in the Python module)
", "transformEntryPointScript": "(your transform script entry-point name in the Python module)
" } }'
同样,要启用自定义模型转换,必须提供customModelTransformParameters
Neptune ML 模型转换 API 的 JSON 对象,其字段值与训练作业中保存的模型参数兼容。这些区域有:customModelTransformParameters
对象包含以下字段:
sourceS3DirectoryPath
— (必需) 实现模型的 Python 模块所在的 Amazon S3 位置的路径。这必须指向一个有效的现有 Amazon S3 位置,该位置至少包含训练脚本、转换脚本和model-hpo-configuration.json
文件。-
transformEntryPointScript
— (可选) 脚本模块中的入口点名称,该脚本的入口点名称,该脚本应在确定超参数搜索中的最佳模型后运行,以计算模型部署所需的模型工件。它应该能够在没有命令行参数的情况下运行。默认值:
transform.py
.
例如:
curl \ -X POST https://
(your Neptune endpoint)
/ml/modeltransform -H 'Content-Type: application/json' \ -d '{ "id" : "(a unique model-training 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)
" } }'