翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Neptune ML のカスタムモデルの概要
Neptune ML でカスタムモデルを使用する時期
Neptune ML の組み込みモデルは、Neptune ML でサポートされているすべての標準タスクを処理しますが、特定のタスクのモデルをより細かく制御したい場合や、モデルトレーニングプロセスをカスタマイズしなければならない場合があります。たとえば、次のような場合は、カスタムモデルが適しています。
非常に大きなテキストモデルのテキスト機能の特徴エンコーディングは GPU で実行する必要があります。
ディープグラフライブラリ (DGL) で開発された独自のカスタムグラフニューラルネットワーク (GNN) モデルを使いたい場合。
ノード分類とリグレッションに表形式モデルまたはアンサンブルモデルを使用したい場合。
Neptune ML でカスタムモデルを開発して使用するためのワークフロー
Neptune ML でのカスタムモデルのサポートは、既存の Neptune ML ワークフローにシームレスに統合するように設計されています。Neptune ML のインフラストラクチャでソースモジュールでカスタムコードを実行してモデルをトレーニングすることで機能します。組み込みモードの場合と同様に、Neptune ML は自動的に SageMaker AI ハイパーパラメータチューニングジョブを起動し、評価メトリクスに従って最適なモデルを選択します。次に、ソースモジュールで提供されている実装を使用して、デプロイ用のモデルアーティファクトを生成します。
カスタムモデルの場合、データのエクスポート、トレーニング設定、およびデータの前処理は、組み込みモデルの場合と同じです。
データの前処理の後は、Python を使用してカスタムモデルの実装を反復的かつ対話的に開発およびテストできるときです。モデルが実稼働状態になったら、作成された Python モジュールを次のようにして Amazon S3 にアップロードできます。
aws s3 cp --recursive (source path to module) s3://(bucket name)/(destination path for your module)
次に、モデルを本番環境にデプロイするためのノーマルなデフォルトまたはインクリメンタルデータワークフローを使うことができ、いくつかの違いがあります。
カスタムモデルを使用したモデルトレーニングの場合、カスタムコードが使用されていることを確認するために、Neptune ML モデルトレーニング API へ customModelTrainingParameters JSON オブジェクトを提供する必要があります。customModelTrainingParameters オブジェクトのフィールドは次のとおりです。
sourceS3DirectoryPath — (必須) モデルを実装する Python モジュールがある Amazon S3 の場所へのパス。これは、少なくともトレーニングスクリプト、変換スクリプト、および model-hpo-configuration.json ファイルを含む有効な既存の Amazon S3 の場所を指定しなければなりません。
-
trainingEntryPointScript — (オプション) モデルトレーニングを実行し、固定ハイパーパラメーターを含むコマンドライン引数としてハイパーパラメーターを取るスクリプトのモジュール内のエントリポイントの名前。
デフォルト: training.py。
-
transformEntryPointScript — (オプション) モデルのデプロイに必要なモデルアーティファクトを計算するために、ハイパーパラメーター検索の最適なモデルが特定された後に実行されるスクリプトのモジュール内のエントリポイントの名前。コマンドライン引数なしで実行できるはずです。
デフォルト: transform.py。
例えば、次のようになります。
- AWS CLI
-
aws neptunedata start-ml-model-training-job \
--endpoint-url https://your-neptune-endpoint:port \
--id "(a unique model-training job ID)" \
--data-processing-job-id "(the data-processing job-id of a completed job)" \
--train-model-s3-location "s3://(your Amazon S3 bucket)/neptune-model-graph-autotrainer" \
--model-name "custom" \
--custom-model-training-parameters '{
"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)"
}'
詳細については、 AWS CLI 「 コマンドリファレンス」のstart-ml-model-training-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_training_job(
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)'
}
)
print(response)
- awscurl
-
awscurl https://your-neptune-endpoint:port/ml/modeltraining \
--region us-east-1 \
--service neptune-db \
-X POST \
-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)"
}
}'
この例では、 AWS 認証情報が 環境で設定されていることを前提としています。us-east-1 を Neptune クラスターのリージョンに置き換えます。
- curl
-
curl \
-X POST https://your-neptune-endpoint:port/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)"
}
}'
同様に、カスタムモデル変換を有効にするには、トレーニングジョブの保存されたモデルパラメータと互換性のあるフィールド値を持つ Neptune ML モデル変換 API へcustomModelTransformParameters JSON オブジェクトを提供する必要があります。customModelTransformParameters オブジェクトには、次のフィールドが含まれます。
sourceS3DirectoryPath — (必須) モデルを実装する Python モジュールがある Amazon S3 の場所へのパス。これは、少なくともトレーニングスクリプト、変換スクリプト、および model-hpo-configuration.json ファイルを含む有効な既存の Amazon S3 の場所を指定しなければなりません。
-
transformEntryPointScript — (オプション) モデルのデプロイに必要なモデルアーティファクトを計算するために、ハイパーパラメーター検索の最適なモデルが特定された後に実行されるスクリプトのモジュール内のエントリポイントの名前。コマンドライン引数なしで実行できるはずです。
デフォルト: transform.py。
例えば、次のようになります。
- 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)"
}
}'