

# Customize a model with distillation in Amazon Bedrock
Distillation

*Model distillation* is the process of transferring knowledge from a larger more intelligent model (known as teacher) to a smaller, faster, cost-efficient model (known as student). In this process, the student model's performance improves for a specific use case. Amazon Bedrock Model Distillation uses the latest data synthesis techniques to generate diverse, high-quality responses (known as synthetic data) from the teacher model, and fine-tunes the student model.

## How to use Amazon Bedrock Model Distillation


 To use Amazon Bedrock Model Distillation, you do the following: 

1. **Choose a teacher model and a student model** – For more information, see [Prerequisites for model distillation](prequisites-model-distillation.md).

1. **Prepare your training data for distillation** – Your training data is a collection of prompts stored in `.jsonl` files. Amazon Bedrock uses the input data to generate responses from the teacher model and uses the responses to fine-tune the student model.
   + **Optimize prompts** – Format your input prompts for the use case that you want. For more information, see [Optimize your input prompts for synthetic data generation](distillation-prepare-datasets.md#distillation-data-prep-prompt-optimization). 
   + **Use labeled examples** – Prepare labeled input data as prompt-response pairs. Amazon Bedrock can use these pairs as golden examples while generating responses from the teacher model. For more information, see [Option 1: Provide your own prompts for data preparation](distillation-data-prep-option-1.md). 
   + **Use invocation logs** – If you enable CloudWatch Logs invocation logging, you can use existing teacher responses from invocation logs stored in Amazon S3 as training data. An invocation log in Amazon Bedrock is a detailed record of model invocations. For more information, see [Option 2: Use invocation logs for data preparation](distillation-data-prep-option-2.md). 

1. **Create a distillation job** – This job creates a smaller, faster, and more cost-effective model for your use case. Only you can access the final distilled model. Amazon Bedrock doesn't use your data to train any other teacher or student model for public use. For more information, see [Submit a model distillation job in Amazon Bedrock](submit-model-distillation-job.md). For more information on setting up on demand inference, see [Set up inference for a custom model](model-customization-use.md).

## How Amazon Bedrock Model Distillation works
How Amazon Bedrock Model Distillation works

Amazon Bedrock Model Distillation is a single workflow that automates the process of creating a distilled model. In this workflow, Amazon Bedrock generates responses from a teacher model, adds data synthesis techniques to improve response generation, and fine-tunes the student model with the generated responses. The augmented dataset is split into separate datasets to use for training and validation. Amazon Bedrock uses only the data in the training dataset to fine-tune the student model.

After you've identified your teacher and student models, you can choose how you want Amazon Bedrock to create a distilled model for your use case. Amazon Bedrock can either generate teacher responses by using the prompts that you provide, or you can use responses from your production data via invocation logs. Amazon Bedrock Model Distillation uses these responses to fine-tune the student model.

**Note**  
If Amazon Bedrock Model Distillation uses its proprietary data synthesis techniques to generate higher-quality teacher responses, then your AWS account will incur additional charges for inference calls to the teacher model. These charges will be billed at the on-demand inference rates of the teacher model. Data synthesis techniques may increase the size of the fine-tuning dataset to a maximum of 15k prompt-response pairs. For more information about Amazon Bedrock charges, see [Amazon Bedrock Pricing](https://aws.amazon.com/bedrock/pricing/).

### Creating a distilled model using prompts that you provide
Creating a distilled model with prompts you provide

Amazon Bedrock uses the input prompts that you provide to generate responses from the teacher model. Amazon Bedrock then uses the responses to fine-tune the student model that you've identified. Depending on your use case, Amazon Bedrock might add proprietary data synthesis techniques to generate diverse and higher-quality responses. For example, Amazon Bedrock might generate similar prompts to generate more diverse responses from the teacher model. Or, if you optionally provide a handful of labeled input data as prompt-response pairs, then Amazon Bedrock might use these pairs as golden examples to instruct the teacher to generate similar high-quality responses.

### Creating a distilled model using production data
Creating a distilled model with production data

If you already have responses generated by the teacher model and stored them in the invocation logs, you can use those existing teacher responses to fine-tune the student model. For this, you will need to provide Amazon Bedrock access to your invocation logs. An invocation log in Amazon Bedrock is a detailed record of model invocations. For more information, see [Monitor model invocation using CloudWatch Logs](https://docs.aws.amazon.com//bedrock/latest/userguide/model-invocation-logging.html).

If you choose this option, then you can continue to use Amazon Bedrocks inference API operations, such as [InvokeModel](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_runtime_InvokeModel.html) or [Converse](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_runtime_Converse.html) API, and collect the invocation logs, model input data (prompts), and model output data (responses) for all invocations used in Amazon Bedrock.

When you generate responses from the model using the `InvokeModel` or `Converse` API operations, you can optionally add `requestMetadata` to the responses. When you create a Distillation job, you can filter by this metadata as part of the invocation logs configuration. You can filter by your specific use cases, and then Amazon Bedrock only uses the filtered responses to fine-tune your student model. When you choose to use invocation logs to fine-tune your student model, you can have Amazon Bedrock use the prompts only, or use prompt-response pairs. 

------
#### [ Choosing prompts with invocation logs ]

If you choose to have Amazon Bedrock use only the prompts from the invocation logs, then Amazon Bedrock uses the prompts to generate responses from the teacher model. In this case, Amazon Bedrock uses the responses to fine-tune the student model that you've identified. Depending on your use case, Amazon Bedrock Model Distillation might add proprietary data synthesis techniques to generate diverse and higher-quality responses. 

------
#### [ Choosing prompt-response pairs with invocation logs ]

If you choose to have Amazon Bedrock use prompt-response pairs from the invocation logs, then Amazon Bedrock won't re-generate responses from the teacher model and use the responses from the invocation log to fine-tune the student model. For Amazon Bedrock to read the responses from the invocation logs, the teacher model specified in your model distillation job must match the model used in the invocation log. If they don't match, the invocation logs aren't used. If you've added request metadata to the responses in the invocation log, then to fine-tune the student model, you can specify the request metadata filters so that Amazon Bedrock reads only specific logs that are valid for your use case.

------

# Prerequisites for model distillation
Prerequisites

Before you can begin, make sure that you understand access and security controls for Model Distillation. You must also choose a teacher and student model for your distillation job.

## Permissions


Before you can begin, make sure that you understand access and security controls for Model Distillation. You must have an IAM service role that can access the Amazon S3 bucket where you want to store your Model Distillation training and validation data. Amazon Bedrock also has options for encrypting and further securing your distillation jobs and artifacts. For more information, see [Model customization access and security](custom-model-job-access-security.md). 

To use a cross-region inference profile for a teacher model in a Distillation job, your service role must have permissions to invoke the inference profile in an AWS Region, in addition to the model in each Region in the inference profile. For a policy example, see [(Optional) Permissions to create a Distillation job with a cross-region inference profile](custom-model-job-access-security.md#custom-models-cross-region-inference-profile-permissions). For more information about cross-region inference, see [Increase throughput with cross-Region inference](cross-region-inference.md).

## Choose teacher and student models for distillation



****  

| Model Type | Selection Criteria | Key Considerations | Requirements | 
| --- | --- | --- | --- | 
| Teacher Model | Choose a teacher model that's significantly larger and more capable than the student model, and whose accuracy you want to achieve for your use case. | To make distillation more effective, choose a model that's already trained on tasks similar to your use case. For some teacher models, you can choose a Cross-Region inference profile. | Must have permissions to invoke inference profiles and models in each Region. See cross-region inference documentation for policy examples. | 
| Student Model | Choose a student model that's significantly smaller in size than the teacher model. | The student model must be one of the student models paired with your teacher model in the supported models table. | Must be compatible with selected teacher model as shown in the following table. | 

The following section lists the supported models and regions for Amazon Bedrock Model Distillation. After you choose your teacher and student models, you prepare and optimize your training datasets for distillation. For more information, see [Prepare your training datasets for distillation](distillation-prepare-datasets.md).

### Supported models and Regions for Amazon Bedrock Model Distillation
Supported models and Regions for distillation

The following table shows which models and AWS Regions Amazon Bedrock Model Distillation supports for teacher and student models. If you use a Cross Region Inference Profile, only System Inference Profiles are supported for model distillation. For more information, see [Increase throughput with cross-Region inference](cross-region-inference.md). 


****  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/bedrock/latest/userguide/prequisites-model-distillation.html)

**Note**  
For Claude  and Llama models, the distillation job is run in US West (Oregon). You can either buy [provisioned throughput](https://docs.aws.amazon.com//bedrock/latest/userguide/prov-throughput.html) in US West (Oregon) or [copy distilled model](https://docs.aws.amazon.com//bedrock/latest/userguide/copy-model.html) to another Region and then buy [provisioned throughput](https://docs.aws.amazon.com//bedrock/latest/userguide/prov-throughput.html).
For Nova models, you run distillation job in US East (N. Virginia). For inference, you need to buy [provisioned throughput](https://docs.aws.amazon.com//bedrock/latest/userguide/prov-throughput.html) in US East (N. Virginia). You can't copy Nova models to other Regions.

# Prepare your training datasets for distillation
Prepare data

Before you can begin a model customization job, you need to minimally prepare a training dataset. To prepare input datasets for your custom model, you create `.jsonl` files, each line of which is a JSON object corresponding to a record. The files you create must conform to the format for model distillation and model that you choose. The records in it must also conform to size requirements.

Provide the input data as prompts. Amazon Bedrock uses the input data to generate responses from the teacher model and uses the generated responses to fine-tune the student model. For more information about inputs Amazon Bedrock uses, and for choosing an option that works best for your use case, see [How Amazon Bedrock Model Distillation works](model-distillation.md#how-md-works). There are a couple options for preparing your input dataset.

**Note**  
Amazon Nova models have different requirements for distillation. For more information, see [Distilling Amazon Nova models](https://docs.aws.amazon.com/nova/latest/userguide/customize-distill.html).

## Supported modalities for distillation


The models listed in [Supported models and Regions for Amazon Bedrock Model Distillation](prequisites-model-distillation.md#model-distillation-supported) support only the text-to-text modality.

## Optimize your input prompts for synthetic data generation


During model distillation, Amazon Bedrock generates a synthetic dataset that it uses to fine tune your student model for your specific use case. For more information, see [How Amazon Bedrock Model Distillation works](model-distillation.md#how-md-works).

You can optimize the synthetic data generation process by formatting your input prompts for the use case that you want. For example, if your distilled model's use case is retrieval augmented generation (RAG), you would format your prompts differently than if you want the model to focus on agent use cases.

The following are examples for how you can format your input prompts for RAG or agent use cases.

------
#### [ RAG prompt example ]

```
{
  "schemaVersion": "bedrock-conversation-2024",
  "system": [
    {
      "text": "You are a financial analyst charged with answering questions about 10K and 10Q SEC filings. Given the context below, answer the following question."
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "text": "<context>\nDocument 1: Multiple legal actions have been filed against us as a result of the October 29, 2018 accident of Lion Air Flight 610 and the March 10, 2019 accident of Ethiopian Airlines Flight 302.\n</context>\n\n<question>Has Boeing reported any materially important ongoing legal battles from FY2022?</question>"
        }
      ]
    }
  ]
}
```

------
#### [ Agent prompt example ]

```
{
    "schemaVersion": "bedrock-conversation-2024",
    "system": [
        {
            "text": 'You are an expert in composing functions. You are given a question and a set of possible functions. Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
                    Here is a list of functions in JSON format that you can invoke.
                    [
                        {
                            "name": "lookup_weather",
                            "description: "Lookup weather to a specific location",
                            "parameters": {
                                "type": "dict",
                                "required": [
                                    "city"
                                ],
                                "properties": {
                                    "location": {
                                        "type": "string",
                                    },
                                    "date": {
                                        "type": "string",
                                    }
                                }
                            }
                        }
                    ]'
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "text": "What's the weather tomorrow?"
                }
            ]
        },
        {
            "role": "assistant",
            "content": [
               {
                   "text": "[lookup_weather(location=\"san francisco\", date=\"tomorrow\")]"
               }
            ]
        }
    ]
}
```

------

# Option 1: Provide your own prompts for data preparation
Option 1: Provide your own prompts for data preparation

Collect your prompts and store them in `.jsonl` file format. Each record in the JSONL must use the following structure.
+ Include the `schemaVersion` field that must have the value `bedrock-conversion-2024`.
+ [Optional] Include a system prompt that indicates the role assigned to the model.
+ In `messages` field, include the user role containing the input prompt provided to the model.
+ [Optional] In the `messages` field, include assistant role containing the desired response.

Anthropic and Meta Llama models support only single-turn conversation prompts, meaning you can only have one user prompt. The Amazon Nova models support multi-turn conversations, allowing you to provide multiple user and assistant exchanges within one record.

**Example format**

```
{
    "schemaVersion": "bedrock-conversation-2024",
    "system": [{
        "text": "A chat between a curious User and an artificial intelligence Bot. The Bot gives helpful, detailed, and polite answers to the User's questions."
    }],
    "messages": [{
            "role": "user",
            "content": [{
                "text": "why is the sky blue"
            }]
        },
        {
            "role": "assistant",
            "content": [{
                "text": "The sky is blue because molecules in the air scatter blue light from the Sun more than other colors."
            }]
        }
    ]
}}
```

## Validate your dataset


Before you run your distillation job, you can validate your input dataset using a [Python script](https://github.com/aws-samples/amazon-bedrock-samples/blob/main/custom-models/model_distillation/dataset-validation/README.md).

# Option 2: Use invocation logs for data preparation
Option 2: Use invocation logs for data preparation

When you create a distillation job, you can have Amazon Bedrock use existing teacher responses from CloudWatch Logs invocation logs as training data. For Amazon Bedrock, an invocation log is a detailed record of model invocations. 

To use invocation logs for model distillation, set the model invocation logging on, use one of the model invocation operations, and make sure that you've set up an Amazon S3 bucket as the destination for the logs. Before you can start the model distillation job, you must provide Amazon Bedrock permissions to access the logs. For more information about setting up the invocation logs, see [Monitor model invocation using Amazon CloudWatch Logs](https://docs.aws.amazon.com//bedrock/latest/userguide/model-invocation-logging.html).

With this option, you can specify if you want Amazon Bedrock to use only the prompts, or to use prompt-response pairs from the invocation log. If you want Amazon Bedrock to use only prompts, then Amazon Bedrock might add proprietary data synthesis techniques to generate diverse and higher-quality responses from the teacher model. If you want Amazon Bedrock to use prompt-response pairs, then Amazon Bedrock won't re-generate responses from the teacher model. Amazon Bedrock will directly use the responses from the invocation log to fine-tune the student model.

**Important**  
You can provide a maximum of 15K prompts or prompt-response pairs to Amazon Bedrock for fine-tuning the student model. To ensure that the student model is fine-tuned to meet your specific requirements, we highly recommend the following:  
If you want Amazon Bedrock to use prompts only, make sure that there are at least 100 prompt-response pairs generated from across all models.
If you want Amazon Bedrock to use responses from your invocation logs, make sure that you have at least 100 prompt-response pairs generated from the model in your invocation logs that exactly match with the teacher model you've chosen.

You can optionally [add request metadata](#add-metadata-to-prompts) to the prompt-response pairs in the invocation log using one of the model invocation operations and then later use it to filter the logs. Amazon Bedrock can use the filtered logs to fine-tune the student model.

To filter the logs using multiple request metadata, use a single operation Boolean operator AND, OR, or NOT. You cannot combine operations. For single request metadata filtering, use the Boolean operator NOT.

## Add request metadata to prompts and responses in your invocation logs for model distillation
Add request metadata to prompts and responses

The model invocation logging collects invocation logs, model input data (prompts), and model output data(responses) for all invocations used in Amazon Bedrock. If you've enabled logging, you can collect the logs whenever you interact with Amazon Bedrock foundation models through any `Invoke` or `Converse` API operations. If you want Amazon Bedrock to use the prompts and associated responses from the invocation log to fine-tune the student model, then you must give Amazon Bedrock access to these logs. Using the responses that a model has already generated makes it quicker to fine-tune the student model. Using responses from the invocation logs also makes model distillation more cost-effective, however, Amazon Bedrock's proprietary data synthesis techniques are not added which may result in a more performant distilled model. 

With invocation logs, you can identify the prompt-response pairs that you want Amazon Bedrock to use for model distillation. These prompt-response pairs can be for specific use cases. To be able to identify the prompt-response pairs to use for distillation, you must add a request metadata string to the prompt-response pairs when you invoke a model or use the `Converse` API operation. The request metadata is provided in the format: `"priority" : "High"`. 

As you continue to interact with the model using the `Invoke` or `Converse` API operations, the interactions and the request metadata are logged in the invocation logs. The following is an example of an invocation log from an `InvokeModel` call that shows the request metadata:

```
{
    "schemaType": "ModelInvocationLog",
    "schemaVersion": "1.0",
    "timestamp": "2024-09-11T17:16:18Z",
    "accountId": "XXXXX",
    "identity": {
        "arn": "arn:aws:sts::XXXXXXX:assumed-role/Admin/XXXXXX"
    },
    "region": "us-east-1",
    "requestId": "7ee514f3-9eff-467c-af75-8fd564ce58e5",
    "operation": "InvokeModel",
    "modelId": "meta.llama3-1-405b-instruct-v1:0",
    "input": {
        "inputContentType": "application/json",
        "inputBodyJson": {
            "prompt": "story of two dogs",
            "max_tokens_to_sample": 300
        },
        "inputTokenCount": 13
    },
    "output": {
        "outputContentType": "application/json",
        "outputBodyJson": {
            "type": "completion",
            "completion": " Here is a story about two dogs:\n\nRex and Charlie were best friends who lived next door to each other. Every morning, their owners would let them out into the backyard to play. Rex was a golden retriever with long, shaggy fur. He loved to run and chase sticks. Charlie was a corgi with short legs and a big smile. He was happy just sniffing the grass and rolling around. \n\nThe two dogs spent every day playing together. Rex would grab a stick and bring it over to Charlie, wagging his tail excitedly. Charlie would take the other end of the stick in his mouth and they'd have a friendly game of tug-of-war. After tiring themselves out, they'd flop down in the warm sunshine for a nap. \n\nAt lunchtime, their owners would call them in for food. Rex would gobble up his kibble hungrily while Charlie ate his at a more leisurely pace. After lunch, it was right back outside for more playtime. The afternoon sunbeams would light up their fur as they chased each other around the yard. \n\nWhen it started getting late, their owners called them in for the night. Rex and Charlie would head inside, tired but happy after another fun day of play. After slurping up fresh water from their bowls, they'd curl up on their beds, Rex's fluffy golden tail tucked over his nose and little",
            "stop_reason": "max_tokens",
            "stop": null
        },
        "outputTokenCount": 300
    },
    "requestMetadata": {
        "project": "CustomerService",
        "intent": "ComplaintResolution",
        "priority": "High"
    }
}
```

You can specify the invocation log as your input data source when you start a model distillation job. You can start model distillation job in the Amazon Bedrock console, using the API, AWS CLI, or AWS SDK. 

**Requirements for providing request metadata**

The request metadata must meet the following requirements:
+ Provided in the JSON `key:value` format.
+ Key and value pair must be a string of 256 characters maximum.
+ Provide a maximum of 16 key-value pairs.

### Using request metadata filters
Using request metadata filters

You can apply filters to the request metadata to selectively choose which prompt-response pairs to include in distillation for fine-tuning the student model. For example, you might want to include only those with "project" : "CustomerService" and "priority" : "High" request metadata.

To filter the logs using multiple request metadata, use a single Boolean operator AND, OR, or NOT. You cannot combine operations. For single request metadata filtering, use the Boolean operator NOT. 

You can specify the invocation log as your input data source and what filters to use to select the prompt-response pairs when you start a model distillation job. You can start model distillation job in the Amazon Bedrock console, using the API, AWS CLI, or AWS SDK. For more information, see [Submit a model distillation job in Amazon Bedrock](submit-model-distillation-job.md).

## Validate your dataset


Before you run your distillation job, you can validate your input dataset using a [Python script](https://github.com/aws-samples/amazon-bedrock-samples/blob/main/custom-models/model_distillation/dataset-validation/README.md).

# Submit a model distillation job in Amazon Bedrock
Submit a model distillation job

You can perform model distillation through the Amazon Bedrock console or by sending a [CreateModelCustomizationJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) request with an [Amazon Bedrock control plane endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#br-cp).

## Prerequisites

+ Create an IAM service role with the required permissions. For comprehensive security and permissions information, see [Model customization access and security](custom-model-job-access-security.md).
+ (Optional) Encrypt input and output data, your customization job, or inference requests made to custom models. For more information, see [Encryption of custom models](encryption-custom-job.md).
+ (Optional) Create a Virtual Private Cloud (VPC) to protect your customization job. For more information, see [(Optional) Protect your model customization jobs using a VPC](custom-model-job-access-security.md#vpc-model-customization).

For more information on setting up on demand inference, see [Set up inference for a custom model](model-customization-use.md).

## Submit your job


------
#### [ Console ]

1. Sign in to the AWS Management Console with an IAM identity that has permissions to use the Amazon Bedrock console. Then, open the Amazon Bedrock console at [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock).

1. From the left navigation pane, choose **Custom models** under **Tune**.

1. Choose **Create distillation job**.

1. For **Distilled model details**, do the following:

   1. For **Distilled model name**, enter a name for your distilled model.

   1. (Optional) For **Model encryption**, select the checkbox if you want to provide a KMS key for encrypting your job and its related artifacts. 

      For more information, see [Encryption of custom models](encryption-custom-job.md).

   1. (Optional) Apply **Tags** to your distilled model.

1. For **Job configuration**, do the following:

   1. For **Job name**, enter a name for your distillation job.

   1. (Optional) For **Model encryption**, select the checkbox if you want to provide a KMS key for encrypting your job and its related artifacts. 

      For more information, see [Encryption of custom models](encryption-custom-job.md).

   1. (Optional) Apply **Tags** to your job.

1. For **Teacher model – Student model details**, choose the teacher and student models for creating your distilled model.

   For more information, see [Prerequisites for model distillation](prequisites-model-distillation.md).

1. For **Synthetic data generation**, do the following:

   1. For **Max response length**, specify the maximum length of the synthetic responses generated by the teacher model.

   1. For **Distillation input dataset**, choose one of the following options:
      + **Directly upload to S3 location** – Specify the S3 location where you're storing the input dataset (prompts) that'll be used for distillation. For more information, see [Option 1: Provide your own prompts for data preparation](distillation-data-prep-option-1.md).
      + **Provide access to invocation logs** – Specify the S3 location where you're storing the invocation logs with the input dataset (prompts) that'll be used for distillation. For more information, see [Option 2: Use invocation logs for data preparation](distillation-data-prep-option-2.md).
        + (Optional) For **Request Metadata Filters**, specify filters if you want Amazon Bedrock to only use certain prompts in your logs for distillation.
        + Choose **Read prompts** or **Read prompt-response pairs** depending on what you want Amazon Bedrock to access from your logs. Keep in mind that responses are read only if your teacher model matches the model in your logs.

1. For **Distillation output**, specify the S3 location where you want to upload the metrics and reports about your distillation job.

   For more information, see [Analyze the results of a model customization jobAnalyze model customization job results](model-customization-analyze.md).

1. For **VPC settings**, choose a VPC configuration for accessing the S3 bucket with your training data.

   For more information, see [(Optional) Protect your model customization jobs using a VPC](custom-model-job-access-security.md#vpc-model-customization).

1. For **Service access**, specify the IAM role for accessing the S3 bucket with your training data. Unless you use a Cross Region inference profile or VPC configurations, you can create the role in the Amazon Bedrock console with the correct permissions automatically configured. Or you can use an existing service role. 

    For a job that has Amazon VPC configurations or uses a Cross Region inference profile, you must create a new service role in IAM that has the required permissions. 

   For more information, see [Create an IAM service role for model customization](custom-model-job-access-security.md#custom-model-job-service-role).

1. Choose **Create distillation job** to start the distillation job. After you customize a model, you can set up inference for the model. For more information, see [Set up inference for a custom model](model-customization-use.md). 

------
#### [ API ]

At minimum, you must provide the following fields to submit your model distillation job when using the Amazon Bedrock API.


****  

| Field | Description | 
| --- | --- | 
| baseModelIdentifier | The model identifier of the student model | 
| customModelName | The name of the new distilled model | 
| jobName | The name of the model distillation job | 
| roleArn | Role that gives Amazon Bedrock permissions to read training and validation files and write to the output path | 
| trainingDataConfig | The Amazon S3 path that has your training data | 
| outputDataConfig | The Amazon S3 path that contains your training and validation metrics | 
| distillationConfig | Inputs required for distillation job | 
| customModelKmsKeyId | To encrypt the custom model | 
| clientRequestToken | Token to prevent the request from completing more than once | 

The following fields are optional:


****  

| Field | Description | 
| --- | --- | 
| customizationType | Set to DISTILLATION  by default for distillation jobs | 
| validationDataConfig | List of validation data Amazon S3 paths | 
| jobTags | To associate tags with the job | 
| customModelTags | To associate tags with the resulting custom model | 
| vpcConfig | VPC to protect your training data and distillation job | 

To prevent the request from completing more than once, include a `clientRequestToken`.

You can include the following optional fields for extra configurations.
+ `jobTags` and/or `customModelTags` – Associate [tags](tagging.md) with the customization job or resulting custom model.
+ `vpcConfig` – Include the configuration for a [virtual private cloud (VPC) to protect your training data and customization job](custom-model-job-access-security.md#vpc-model-customization).

The following is an example snippet from [CreateModelCustomizationJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelCustomizationJob.html) API. This example uses the prompt-response pairs in the invocation log as the input data source and specifies the filter for selecting prompt-response pairs. 

```
"trainingDataConfig": {
    "invocationLogsConfig": {
        "usePromptResponse": true,
        "invocationLogSource": {
            "s3Uri": "string"
        },
        "requestMetadataFilters": {
            "equals": {
                "priority": "High"
            }
        }
    }
}
```

**Response**

The response returns a `jobArn` of the model distillation job.

------

## Next steps

+ [Monitor your distillation job](model-customization-monitor.md). For more information on setting up on demand inference, see [Set up inference for a custom model](model-customization-use.md).

# Clone a distillation job


You can use the Amazon Bedrock console to clone your distillation job. Clone your distillation job to run multiple jobs with similar settings. Use cloning to try again with a job that you stopped or had an issue. The new job inherits all settings except Service access configuration, any VPC settings, and any Tags.

1. Sign in to the AWS Management Console with an IAM identity that has permissions to use the Amazon Bedrock console. Then, open the Amazon Bedrock console at [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock).

1. From the left navigation pane, choose **Custom models** under **Tune**.

1. Choose the distillation job that you want to clone, then choose **Clone job**.

1. If needed, adjust your job's settings. 

1. Choose **Create distillation job** to start the new job.