Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPS-6304 Fix dynamic blocks #2

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions examples/titan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.73 |

## Modules

Expand All @@ -20,7 +22,16 @@ No providers.

## Resources

No resources.
| Name | Type |
|------|------|
| [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_s3_bucket.output](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket.training](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_object.data](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
| [aws_iam_policy_document.s3_access](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.trust_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |

## Inputs

Expand Down
85 changes: 73 additions & 12 deletions examples/titan/main.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,89 @@
# Inspired by: https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-code-samples.html

resource "aws_s3_bucket" "training" {
bucket = "bedrock-data-test-training"
}

resource "aws_s3_bucket" "output" {
bucket = "bedrock-data-test-output"
}

data "aws_iam_policy_document" "trust_policy" {
statement {
actions = ["sts:AssumeRole"]

principals {
type = "Service"
identifiers = ["bedrock.amazonaws.com"]
}
}
}

data "aws_iam_policy_document" "s3_access" {
statement {
actions = [
"s3:GetObject",
"s3:ListBucket"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.training.id}",
"arn:aws:s3:::${aws_s3_bucket.training.id}/*"
]
}
statement {
actions = [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.output.id}",
"arn:aws:s3:::${aws_s3_bucket.output.id}/*"
]
}
}

resource "aws_iam_role" "this" {
name = "CustomModelRole"
assume_role_policy = data.aws_iam_policy_document.trust_policy.json
}

resource "aws_iam_policy" "this" {
name = "CustomModelRolePolicy"
policy = data.aws_iam_policy_document.s3_access.json
}

resource "aws_iam_role_policy_attachment" "this" {
role = aws_iam_role.this.name
policy_arn = aws_iam_policy.this.arn
}

resource "aws_s3_object" "data" {
bucket = aws_s3_bucket.training.id
key = "train.jsonl"
source = "train.jsonl"
}

module "model" {
source = "../../"

name = "titan"
job_name = "titan-job-1"
foundation_model_id = "amazon.titan-text-express-v1"
model_role_arn = "arn:aws:iam::123456789101:role/TitanModelRole"
model_role_arn = aws_iam_role.this.arn

model_customization_type = "FINE_TUNING"
model_hyperparameters = {
"epochCount" = "1"
"batchSize" = "1"
"learningRate" = "0.005"
"learningRateWarmupSteps" = "0"
}

output_data_s3_uri = "s3://titan-output-data/data/"
training_data_s3_uri = "s3://titan-training-data/data/train.jsonl"
}

output "custom_model_arn" {
description = "The ARN of the output model."
value = module.model.custom_model_arn
}
output_data_s3_uri = "s3://${aws_s3_bucket.output.id}"
training_data_s3_uri = "s3://${aws_s3_bucket.training.id}/train.jsonl"

output "job_arn" {
description = "The ARN of the customization job."
value = module.model.job_arn
depends_on = [
aws_s3_object.data
]
}
9 changes: 9 additions & 0 deletions examples/titan/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "custom_model_arn" {
description = "The ARN of the output model."
value = module.model.custom_model_arn
}

output "job_arn" {
description = "The ARN of the customization job."
value = module.model.job_arn
}
1 change: 1 addition & 0 deletions examples/titan/train.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"prompt": "what is AWS", "completion": "it's Amazon Web Services"}