Skip to content

Commit 7ecf8b5

Browse files
authored
fix: define LAMBDA_ARN_REGEX in finetune_utils to fix RLVRTrainer NameError (#5988)
`_is_lambda_arn()` in finetune_utils.py referenced `LAMBDA_ARN_REGEX`, but the constant was never defined or imported in the module. Any RLVR training submitted with an evaluator (hub-content) ARN reward function hit the `not _is_lambda_arn(...)` branch in `RLVRTrainer._verify_reward_function` and crashed with: NameError: name 'LAMBDA_ARN_REGEX' is not defined The identical regex already exists in rlvr_reward_verifier.py, and both call sites answer the same question ("is this a Lambda ARN?"). Import the canonical pattern rather than duplicating it so the two paths cannot drift. Adds regression tests covering valid Lambda ARNs (incl. non-aws partitions), evaluator hub-content ARNs, and that both modules share the same compiled regex. Fixes: P467540738
1 parent 3ab2524 commit 7ecf8b5

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎sagemaker-train/src/sagemaker/train/common_utils/finetune_utils.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
from sagemaker.core.helper.session_helper import Session
1313
from sagemaker.core.s3.utils import resolve_s3_uri_placeholders
1414
from sagemaker.train.common_utils.recipe_utils import _get_hub_content_metadata
15+
# Single source of truth for Lambda-ARN detection, shared with the reward verifier
16+
# so both code paths agree on what counts as a Lambda ARN.
17+
from sagemaker.train.common_utils.rlvr_reward_verifier import LAMBDA_ARN_REGEX
1518
from sagemaker.train.common import TrainingType, CustomizationTechnique, JOB_TYPE, FineTuningOptions
1619
from sagemaker.core.shapes import ServerlessJobConfig, Channel, DataSource, ModelPackageConfig, MlflowConfig
1720
from sagemaker.core.training.configs import HyperPodCompute, TrainingJobCompute

‎sagemaker-train/tests/unit/train/common_utils/test_finetune_utils.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
_get_default_s3_output_path,
1717
_extract_dataset_source,
1818
_extract_evaluator_arn,
19+
_is_lambda_arn,
1920
_resolve_model_name,
2021
_resolve_model_package_arn,
2122
_get_fine_tuning_options_and_model_arn,
@@ -1332,3 +1333,33 @@ def test_missing_hyperpod_cli_raises_runtime_error(
13321333
fu.get_hyperpod_recipe_path(
13331334
"nova-lite", "SFT", "LORA", session, job_name="myjob"
13341335
)
1336+
1337+
1338+
class TestIsLambdaArn:
1339+
"""Regression coverage for _is_lambda_arn (the LAMBDA_ARN_REGEX constant
1340+
was previously undefined, raising NameError at call time)."""
1341+
1342+
def test_valid_lambda_arn(self):
1343+
assert _is_lambda_arn(
1344+
"arn:aws:lambda:us-west-2:123456789012:function:my-reward-fn"
1345+
) is True
1346+
1347+
def test_valid_lambda_arn_aws_partition_variants(self):
1348+
assert _is_lambda_arn(
1349+
"arn:aws-us-gov:lambda:us-gov-west-1:123456789012:function:fn"
1350+
) is True
1351+
1352+
def test_evaluator_hub_content_arn_is_not_lambda(self):
1353+
assert _is_lambda_arn(
1354+
"arn:aws:sagemaker:us-west-2:123456789012:hub-content/"
1355+
"SageMakerPublicHub/JsonDoc/my-evaluator/1.0"
1356+
) is False
1357+
1358+
def test_arbitrary_string_is_not_lambda(self):
1359+
assert _is_lambda_arn("not-an-arn") is False
1360+
1361+
def test_uses_shared_regex_from_reward_verifier(self):
1362+
# Both call sites must agree on what a Lambda ARN is; assert they
1363+
# share the same compiled pattern rather than diverging copies.
1364+
from sagemaker.train.common_utils import rlvr_reward_verifier
1365+
assert fu.LAMBDA_ARN_REGEX is rlvr_reward_verifier.LAMBDA_ARN_REGEX

0 commit comments

Comments
 (0)