Skip to content

Commit 8032756

Browse files
committed
refactor: preserve original recipe selection path when sequence_length not provided
Keep the existing `next(...)` logic untouched for the default case (no sequence_length). Only build the candidates list and filter when sequence_length is explicitly requested, ensuring zero behavioral change for existing callers.
1 parent d3f3af0 commit 8032756

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,19 @@ def _get_fine_tuning_options_and_model_arn(
485485
# Collect override_params from ALL matching recipes (standard + subscription)
486486
recipe = None
487487
if (isinstance(training_type, TrainingType) and training_type == TrainingType.LORA) or training_type == "LORA":
488-
candidates = [r for r in recipes_with_template if r.get("Peft") and not r.get("IsSubscriptionModel")]
488+
recipe = next((r for r in recipes_with_template if r.get("Peft") and not r.get("IsSubscriptionModel")), None)
489489
elif (isinstance(training_type, TrainingType) and training_type == TrainingType.FULL) or training_type == "FULL":
490-
candidates = [r for r in recipes_with_template if not r.get("Peft") and not r.get("IsSubscriptionModel")]
491-
else:
492-
candidates = []
490+
recipe = next((r for r in recipes_with_template if not r.get("Peft") and not r.get("IsSubscriptionModel")), None)
491+
492+
# Override recipe selection when sequence_length is explicitly requested
493+
if sequence_length:
494+
if (isinstance(training_type, TrainingType) and training_type == TrainingType.LORA) or training_type == "LORA":
495+
candidates = [r for r in recipes_with_template if r.get("Peft") and not r.get("IsSubscriptionModel")]
496+
elif (isinstance(training_type, TrainingType) and training_type == TrainingType.FULL) or training_type == "FULL":
497+
candidates = [r for r in recipes_with_template if not r.get("Peft") and not r.get("IsSubscriptionModel")]
498+
else:
499+
candidates = []
493500

494-
# Filter by SequenceLength if sequence_length is provided
495-
if sequence_length and candidates:
496501
requested = _parse_context_length(sequence_length)
497502
candidates_with_context = [r for r in candidates if r.get("SequenceLength")]
498503
if candidates_with_context:
@@ -511,8 +516,6 @@ def _get_fine_tuning_options_and_model_arn(
511516
f"No recipes found with Smtj for technique: {customization_technique},training_type:{training_type}, "
512517
f"and sequence length:{sequence_length}"
513518
)
514-
elif candidates:
515-
recipe = candidates[0]
516519

517520
if not recipe:
518521
raise ValueError(f"No recipes found with Smtj for technique: {customization_technique},training_type:{training_type}")

0 commit comments

Comments
 (0)