

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

# 使用经过训练的模型生成新的模型构件
<a name="machine-learning-model-transform"></a>

使用 Neptune ML 模型转换命令，您可以使用预训练的模型参数计算模型构件，例如已处理的图形数据上的节点嵌入。

## 用于增量推理的模型转换
<a name="machine-learning-model-transform-incremental"></a>

在[增量模型推理工作流程](machine-learning-overview-evolving-data-incremental.md#machine-learning-overview-incremental)中，处理完从 Neptune 导出的更新图形数据后，可以使用如下命令启动模型转换作业：

------
#### [ 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 data-processing job-id of a completed job)}}" \
  --ml-model-training-job-id "{{(the ML model training job-id)}}" \
  --model-transform-output-s3-location "s3://{{(your S3 bucket)}}/neptune-model-transform/"
```

有关更多信息，请参阅《 AWS CLI 命令参考》中的 [start-ml-model-transform-job](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/start-ml-model-transform-job.html)。

------
#### [ 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 data-processing job-id of a completed job)}}',
    mlModelTrainingJobId='{{(the ML model training job-id)}}',
    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 data-processing job-id of a completed job)}}",
        "mlModelTrainingJobId": "{{(the ML model training job-id)}}",
        "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 data-processing job-id of a completed job)}}",
        "mlModelTrainingJobId": "{{(the ML model training job-id)}}",
        "modelTransformOutputS3Location" : "s3://{{(your S3 bucket)}}/neptune-model-transform/"
      }'
```

------

然后，您可以将此任务的 ID 传递给 create-endpoints API 调用，以创建新的端点，或者使用此任务生成的新模型构件更新现有端点。这允许新的或更新的端点为更新后的图形数据提供模型预测。

## 适用于任何训练任务的模型转换
<a name="machine-learning-model-transform-any-job"></a>

您还可以提供一个`trainingJobName`参数来为在 Neptune ML 模型训练期间启动的任何 SageMaker AI 训练作业生成模型工件。由于 Neptune ML 模型训练作业可能会启动许多 SageMaker AI 训练作业，因此您可以灵活地基于任何 SageMaker AI 训练作业创建推理端点。

例如：

------
#### [ 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](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/start-ml-model-transform-job.html)。

------
#### [ 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/"
      }'
```

------

如果原始训练任务是针对用户提供的自定义模型，则在调用模型转换时必须包含一个 `customModelTransformParameters` 对象。有关如何实现和使用自定义模型的信息，请参阅[Neptune ML 中的自定义模型](machine-learning-custom-models.md)。

**注意**  
该`modeltransform`命令始终在最适合该训练的 SageMaker AI 训练作业上运行模型变换。

有关模型转换任务的更多信息，请参阅[modeltransform 命令](machine-learning-api-modeltransform.md)。