3232 _validate_eula_for_gated_model ,
3333 _validate_model_region_availability ,
3434 _validate_s3_path_exists ,
35- _parse_context_length
35+ _parse_sequence_length
3636)
3737from sagemaker .core .resources import ModelPackage , ModelPackageGroup
3838from sagemaker .core .utils .utils import Unassigned
@@ -1045,26 +1045,26 @@ def test__create_serverless_config_without_sequence_length(self):
10451045
10461046 assert config .sequence_length is None
10471047
1048- def test__parse_context_length_with_k_suffix (self ):
1049- assert _parse_context_length ("8K" ) == 8192
1050- assert _parse_context_length ("32K" ) == 32768
1051- assert _parse_context_length ("128K" ) == 131072
1048+ def test__parse_sequence_length_with_k_suffix (self ):
1049+ assert _parse_sequence_length ("8K" ) == 8192
1050+ assert _parse_sequence_length ("32K" ) == 32768
1051+ assert _parse_sequence_length ("128K" ) == 131072
10521052
1053- def test__parse_context_length_with_lowercase (self ):
1054- assert _parse_context_length ("8k" ) == 8192
1053+ def test__parse_sequence_length_with_lowercase (self ):
1054+ assert _parse_sequence_length ("8k" ) == 8192
10551055
1056- def test__parse_context_length_with_integer (self ):
1056+ def test__parse_sequence_length_with_integer (self ):
10571057 with pytest .raises (ValueError , match = "Invalid sequence_length '4096'" ):
1058- _parse_context_length ("4096" )
1058+ _parse_sequence_length ("4096" )
10591059
1060- def test__parse_context_length_with_none (self ):
1061- assert _parse_context_length (None ) == 0
1060+ def test__parse_sequence_length_with_none (self ):
1061+ assert _parse_sequence_length (None ) == 0
10621062
1063- def test__parse_context_length_with_empty (self ):
1064- assert _parse_context_length ("" ) == 0
1063+ def test__parse_sequence_length_with_empty (self ):
1064+ assert _parse_sequence_length ("" ) == 0
10651065
10661066 @patch ('sagemaker.train.common_utils.finetune_utils._get_hub_content_metadata' )
1067- def test__get_fine_tuning_options_filters_by_sequence_length (self , mock_get_hub_content ):
1067+ def test__get_fine_tuning_options_filters_by_exact_sequence_length (self , mock_get_hub_content ):
10681068 mock_session = Mock ()
10691069 mock_session .boto_session .region_name = "us-east-1"
10701070 mock_s3 = Mock ()
@@ -1096,17 +1096,59 @@ def test__get_fine_tuning_options_filters_by_sequence_length(self, mock_get_hub_
10961096 }
10971097 }
10981098
1099- result = _get_fine_tuning_options_and_model_arn ("test-model" , "SFT" , "LORA" , mock_session , sequence_length = "8K " )
1099+ result = _get_fine_tuning_options_and_model_arn ("test-model" , "SFT" , "LORA" , mock_session , sequence_length = "32K " )
11001100
1101- if result is not None :
1102- options , model_arn , is_gated_model = result
1103- # Should pick the 32K recipe (smallest >= 8K)
1104- mock_s3 .get_object .assert_called_once ()
1105- call_args = mock_s3 .get_object .call_args [1 ]
1106- assert "params-32k" in call_args ["Key" ]
1101+ assert result is not None
1102+ options , model_arn , is_gated_model = result
1103+ # Should pick the recipe whose SequenceLength exactly matches the request.
1104+ mock_s3 .get_object .assert_called_once ()
1105+ call_args = mock_s3 .get_object .call_args [1 ]
1106+ assert "params-32k" in call_args ["Key" ]
1107+
1108+ @patch ('sagemaker.train.common_utils.finetune_utils._get_hub_content_metadata' )
1109+ def test__get_fine_tuning_options_keeps_all_recipes_at_same_sequence_length (self , mock_get_hub_content ):
1110+ # Multiple recipes share the same SequenceLength (LORA + FULL). Selection
1111+ # by training_type must resolve to the LORA one, not an arbitrary match.
1112+ mock_session = Mock ()
1113+ mock_session .boto_session .region_name = "us-east-1"
1114+ mock_s3 = Mock ()
1115+ mock_s3 .get_object .return_value = {
1116+ "Body" : Mock (read = Mock (return_value = b'{"max_length": {"default": 32768}}' ))
1117+ }
1118+ mock_session .boto_session .client .return_value = mock_s3
1119+
1120+ mock_get_hub_content .return_value = {
1121+ 'hub_content_arn' : "arn:aws:sagemaker:us-east-1:123456789012:model/test-model" ,
1122+ 'hub_content_document' : {
1123+ "GatedBucket" : False ,
1124+ "RecipeCollection" : [
1125+ {
1126+ "CustomizationTechnique" : "SFT" ,
1127+ "SmtjRecipeTemplateS3Uri" : "s3://bucket/template-32k-full.json" ,
1128+ "SmtjOverrideParamsS3Uri" : "s3://bucket/params-32k-full.json" ,
1129+ "Peft" : False ,
1130+ "SequenceLength" : "32K"
1131+ },
1132+ {
1133+ "CustomizationTechnique" : "SFT" ,
1134+ "SmtjRecipeTemplateS3Uri" : "s3://bucket/template-32k-lora.json" ,
1135+ "SmtjOverrideParamsS3Uri" : "s3://bucket/params-32k-lora.json" ,
1136+ "Peft" : True ,
1137+ "SequenceLength" : "32K"
1138+ }
1139+ ]
1140+ }
1141+ }
1142+
1143+ result = _get_fine_tuning_options_and_model_arn ("test-model" , "SFT" , "LORA" , mock_session , sequence_length = "32K" )
1144+
1145+ assert result is not None
1146+ mock_s3 .get_object .assert_called_once ()
1147+ call_args = mock_s3 .get_object .call_args [1 ]
1148+ assert "params-32k-lora" in call_args ["Key" ]
11071149
11081150 @patch ('sagemaker.train.common_utils.finetune_utils._get_hub_content_metadata' )
1109- def test__get_fine_tuning_options_raises_when_no_sufficient_context_length (self , mock_get_hub_content ):
1151+ def test__get_fine_tuning_options_raises_when_no_exact_sequence_length (self , mock_get_hub_content ):
11101152 mock_session = Mock ()
11111153 mock_session .boto_session .region_name = "us-east-1"
11121154
@@ -1126,8 +1168,8 @@ def test__get_fine_tuning_options_raises_when_no_sufficient_context_length(self,
11261168 }
11271169 }
11281170
1129- # Requesting 128K but only 4K available — should raise
1130- with pytest .raises (ValueError , match = "No recipes found with SequenceLength > = 128K" ):
1171+ # Requesting 128K but only 4K available — no exact match, should raise.
1172+ with pytest .raises (ValueError , match = "No recipes found with SequenceLength = = 128K" ):
11311173 _get_fine_tuning_options_and_model_arn ("test-model" , "SFT" , "LORA" , mock_session , sequence_length = "128K" )
11321174
11331175
0 commit comments