Skip to content
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
20 changes: 8 additions & 12 deletions sagemaker-train/tests/integ/train/test_mtrl_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ def _get_test_config():
"""Build test configuration lazily (only when tests actually run)."""
boto_session = boto3.Session(region_name=_REGION)
account_id = boto_session.client("sts").get_caller_identity()["Account"]
from sagemaker.core.helper.session_helper import Session
from sagemaker.train.defaults import TrainDefaults
sagemaker_session = Session(boto_session=boto_session)
role_arn = TrainDefaults.get_role(role=None, sagemaker_session=sagemaker_session)
return {
"base_model": "mock-oss-test",
"agent_arn": f"arn:aws:bedrock-agentcore:{_REGION}:{account_id}:runtime/sagemaker_rft_prod_gsm8k_streaming-Yk6O377mUS",
"dataset": f"s3://sagemaker-rft-{account_id}/prompts/gsm8k_small/prompts.parquet",
"s3_output_path": f"s3://sagemaker-{_REGION}-{account_id}/model-evaluation/output-artifacts/",
"mlflow_resource_arn": f"arn:aws:sagemaker:{_REGION}:{account_id}:mlflow-app/app-TTAUWUNMUHH6",
"model_package_group": f"arn:aws:sagemaker:{_REGION}:{account_id}:model-package-group/openai-reasoning-gpt-oss-20b-mtrl-mpg",
"role": f"arn:aws:iam::{account_id}:role/Admin",
"role": role_arn,
"region": _REGION,
"account_id": account_id,
}
Expand Down Expand Up @@ -172,7 +176,6 @@ def test_bedrock_agent_config_fields(self, mtrl_trainer, test_config):
dataset=test_config["dataset"],
s3_output_path=f'{test_config["s3_output_path"]}integ-fields-bedrock/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
agent_config=test_config["agent_arn"],
agent_qualifier="PROD",
Expand All @@ -182,8 +185,7 @@ def test_bedrock_agent_config_fields(self, mtrl_trainer, test_config):
evaluator._resolve_agent_arn()

ctx = evaluator._build_template_context(
aws_context={"region": test_config["region"], "account_id": test_config["account_id"],
"role_arn": test_config["role"]},
aws_context={"region": test_config["region"], "account_id": test_config["account_id"], "role_arn": test_config["role"]},
artifacts={},
model_package_group_arn=test_config["model_package_group"],
)
Expand All @@ -208,7 +210,6 @@ def test_lambda_agent_config_fields(self, mtrl_trainer, test_config):
dataset=test_config["dataset"],
s3_output_path=f'{test_config["s3_output_path"]}integ-fields-lambda/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
agent_config=lambda_arn,
)
Expand All @@ -217,8 +218,7 @@ def test_lambda_agent_config_fields(self, mtrl_trainer, test_config):
evaluator._resolve_agent_arn()

ctx = evaluator._build_template_context(
aws_context={"region": test_config["region"], "account_id": test_config["account_id"],
"role_arn": test_config["role"]},
aws_context={"region": test_config["region"], "account_id": test_config["account_id"], "role_arn": test_config["role"]},
artifacts={},
model_package_group_arn=test_config["model_package_group"],
)
Expand All @@ -239,7 +239,6 @@ def test_model_package_config_fields(self, mtrl_trainer, test_config):
dataset=test_config["dataset"],
s3_output_path=f'{test_config["s3_output_path"]}integ-fields-mpc/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
agent_config=test_config["agent_arn"],
)
Expand All @@ -248,8 +247,7 @@ def test_model_package_config_fields(self, mtrl_trainer, test_config):
evaluator._resolve_agent_arn()

ctx = evaluator._build_template_context(
aws_context={"region": test_config["region"], "account_id": test_config["account_id"],
"role_arn": test_config["role"]},
aws_context={"region": test_config["region"], "account_id": test_config["account_id"], "role_arn": test_config["role"]},
artifacts={},
model_package_group_arn=test_config["model_package_group"],
)
Expand Down Expand Up @@ -280,7 +278,6 @@ def test_evaluator_construction_with_trainer(self, mtrl_trainer, test_config):
dataset=test_config["dataset"],
s3_output_path=f'{test_config["s3_output_path"]}integ-construct/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
agent_config=test_config["agent_arn"],
)
Expand All @@ -298,7 +295,6 @@ def test_evaluator_construction_with_base_model(self, test_config):
s3_output_path=f'{test_config["s3_output_path"]}integ-base/',
agent_config=test_config["agent_arn"],
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ def _get_3p_test_config():
"MTRL_3P_MLFLOW_ARN",
f"arn:aws:sagemaker:{_REGION}:{account_id}:mlflow-app/app-TTAUWUNMUHH6",
),
"role": os.environ.get(
"MTRL_3P_ROLE",
f"arn:aws:iam::{account_id}:role/Admin",
),
"region": os.environ.get("MTRL_3P_REGION", _REGION),
"account_id": account_id,
}
Expand Down Expand Up @@ -258,7 +254,6 @@ def test_evaluate_with_lambda_agent_wait_for_completion(self, lambda_agent_arn,
agent_config=lambda_agent_arn,
s3_output_path=f'{test_config["s3_output_path"]}lambda-e2e/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
accept_eula=True,
)
Expand Down Expand Up @@ -304,7 +299,6 @@ def test_evaluate_base_model_with_agent_lambda_object(self, lambda_agent_arn, te
agent_config=agent,
s3_output_path=f'{test_config["s3_output_path"]}lambda-object/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
accept_eula=True,
)
Expand Down Expand Up @@ -332,7 +326,6 @@ def test_evaluate_with_attached_trainer(self, lambda_agent_arn, test_config):
agent_config=lambda_agent_arn,
s3_output_path=f'{test_config["s3_output_path"]}attached-trainer/',
mlflow_resource_arn=test_config["mlflow_resource_arn"],
role=test_config["role"],
region=test_config["region"],
accept_eula=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _get_account_id():
boto_session = boto3.Session(region_name=_REGION)
return boto_session.client("sts").get_caller_identity()["Account"]


# ============================================================
# Per-account resource configuration
# ============================================================
Expand All @@ -60,7 +61,6 @@ def _get_account_id():
"s3_output_path": "s3://sagemaker-us-west-2-729646638167/mtrl-integ/eval-output/",
"mlflow_resource_arn": "arn:aws:sagemaker:us-west-2:729646638167:mlflow-app/app-TTAUWUNMUHH6",
"model_package_group": "arn:aws:sagemaker:us-west-2:729646638167:model-package-group/openai-reasoning-gpt-oss-20b-mtrl-mpg",
"role": "arn:aws:iam::729646638167:role/Admin",
},
# PREPROD — Staging account (391266019386)
"391266019386": {
Expand All @@ -72,7 +72,6 @@ def _get_account_id():
"s3_output_path": "s3://sagemaker-us-west-2-391266019386/mtrl-integ/eval-output/",
"mlflow_resource_arn": "arn:aws:sagemaker:us-west-2:391266019386:mlflow-app/app-P3FRQFRQTNGI",
"model_package_group": "arn:aws:sagemaker:us-west-2:391266019386:model-package-group/mtrl-integ-gpt-oss-agentcore",
"role": "arn:aws:iam::391266019386:role/Admin",
},
# BETA — Dev/test account (742774200982)
"742774200982": {
Expand All @@ -84,7 +83,6 @@ def _get_account_id():
"s3_output_path": "s3://sagemaker-us-west-2-742774200982/mtrl-integ/eval-output/",
"mlflow_resource_arn": "arn:aws:sagemaker:us-west-2:742774200982:mlflow-app/app-6ZU5TXXH2GUX",
"model_package_group": "arn:aws:sagemaker:us-west-2:742774200982:model-package-group/openai-reasoning-gpt-oss-20b-mtrl-mpg",
"role": "arn:aws:iam::742774200982:role/Admin",
},
}

Expand Down Expand Up @@ -133,7 +131,6 @@ def attached_trainer(config):
output_model_package_group=config["model_package_group"],
mlflow_app_arn=config["mlflow_resource_arn"],
s3_output_path=config["s3_output_path"],
role=config["role"],
accept_eula=True,
)
trainer._latest_job = job
Expand Down Expand Up @@ -165,7 +162,6 @@ def test_evaluate_finetuned_model(self, attached_trainer, config):
dataset=config["dataset"],
s3_output_path=f'{config["s3_output_path"]}finetuned/',
mlflow_resource_arn=config["mlflow_resource_arn"],
role=config["role"],
region=_REGION,
)

Expand Down Expand Up @@ -195,7 +191,6 @@ def test_evaluate_base_model(self, config):
agent_config=config["agent_core_arn"],
s3_output_path=f'{config["s3_output_path"]}basemodel/',
mlflow_resource_arn=config["mlflow_resource_arn"],
role=config["role"],
region=_REGION,
)

Expand Down Expand Up @@ -225,7 +220,6 @@ def test_evaluate_comparison(self, attached_trainer, config):
dataset=config["dataset"],
s3_output_path=f'{config["s3_output_path"]}comparison/',
mlflow_resource_arn=config["mlflow_resource_arn"],
role=config["role"],
region=_REGION,
evaluate_base_model=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def test_resources():
"""Resolve account-specific resource ARNs lazily."""
account_id = _get_account_id()
return {
"role_arn": f"arn:aws:iam::{account_id}:role/Admin",
"mlflow_arn": f"arn:aws:sagemaker:{_REGION}:{account_id}:mlflow-app/app-TTAUWUNMUHH6",
"s3_input_path": f"s3://sagemaker-rft-{account_id}/prompts/gsm8k_small/prompts.parquet",
"s3_output_path": f"s3://sagemaker-{_REGION}-{account_id}/model-evaluation/mtrl-trainer-integ/",
Expand All @@ -77,7 +76,6 @@ def test_train_and_wait(self, sagemaker_session, test_resources):
training_dataset=test_resources["s3_input_path"],
mlflow_app_arn=test_resources["mlflow_arn"],
s3_output_path=test_resources["s3_output_path"],
role=test_resources["role_arn"],
accept_eula=True,
sagemaker_session=sagemaker_session,
)
Expand All @@ -101,7 +99,6 @@ def test_train_and_stop(self, sagemaker_session, test_resources):
agent_env=AGENT_RUNTIME_ID,
training_dataset=test_resources["s3_input_path"],
mlflow_app_arn=test_resources["mlflow_arn"],
role=test_resources["role_arn"],
accept_eula=True,
sagemaker_session=sagemaker_session,
)
Expand Down Expand Up @@ -132,7 +129,6 @@ def test_train_with_lambda_arn(self, sagemaker_session, test_resources):
mlflow_app_arn=test_resources["mlflow_arn"],
s3_output_path=test_resources["s3_output_path"],
accept_eula=True,
role=test_resources["role_arn"],
sagemaker_session=sagemaker_session,
)
trainer.hyperparameters.global_batch_size = 32
Expand Down
Loading