Skip to content

fix(serve): handle partial base model metadata - #6466

Open
lucasjia-aws wants to merge 1 commit into
aws:masterfrom
lucasjia-aws:fix/5667-modelbuilder-partial-base-model
Open

lucasjia-aws wants to merge 1 commit into
aws:masterfrom
lucasjia-aws:fix/5667-modelbuilder-partial-base-model

Conversation

@lucasjia-aws

Copy link
Copy Markdown
Collaborator

Summary

Generated BaseModel fields may contain Unassigned when Hub content version or recipe metadata is omitted. Because Unassigned is truthy, ModelBuilder can treat missing metadata as real values, fail recipe matching, or emit invalid resource tags.

This change normalizes absent BaseModel strings, omits missing Hub content versions so the latest version is selected, and adds an optional recipe_name constructor override. When recipe metadata is absent, ModelBuilder first uses top-level HostingConfigs, otherwise infers a recipe only when exactly one deployable candidate exists, and reports all candidates when explicit disambiguation is required.

Unset model and recipe metadata is omitted from generated tags. Existing named-recipe and top-level fallback behavior remains supported.

Testing

  • Added nine tests covering omitted and explicit Hub versions, missing Hub content names, constructor compatibility, top-level precedence, unique recipe inference, explicit override, ambiguous candidates, and safe tag generation.
  • Ran the targeted suite: 9 passed.
  • Ran related ModelBuilder and hosting-config regressions: 88 passed.
  • Black, Flake8, pydocstyle, doc8, and git diff --check passed.
  • Built the sagemaker-serve wheel and source distribution successfully.
  • No AWS integration tests were run.

Fixes #5667

Normalize optional BaseModel fields, preserve latest Hub content lookup,
and safely resolve hosting configurations through an explicit recipe
override or unambiguous inference.

Prevent unset model metadata from leaking into generated resource tags.

Fixes aws#5667

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI code review

This PR hardens ModelBuilder against partially populated generated BaseModel metadata: it normalizes Unassigned/empty strings via _optional_base_model_string, omits an absent HubContentVersion so the latest is chosen, adds a public recipe_name constructor override, reworks _extract_hosting_configs_from_hub to prefer top-level configs and infer a unique recipe (raising on ambiguity), and avoids emitting invalid resource tags. The implementation is coherent and well covered by nine new unit tests. A couple of minor points below; nothing blocking.

Reviewed commit de649e1. Automated review; verify before acting.

base_model = model_package.inference_specification.containers[0].base_model
recipe_name = self._effective_recipe_name(base_model)
if recipe_name is None:
raise ValueError(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Medium: fetch_endpoint_names_for_base_model now raises ValueError when _effective_recipe_name returns None, which is new behavior (previously it read base_model.recipe_name directly). This is a reasonable change, but none of the nine added tests exercise this new raise path, and the method had existing unit coverage (test_model_builder.py::test_fetch_endpoint_names_for_base_model). Please add a test asserting the ValueError is raised when no recipe is resolvable so this contract is pinned.

return None
return value

def _effective_recipe_name(self, base_model: Any) -> Optional[str]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Low: _effective_recipe_name prefers the public self.recipe_name override over the BaseModel's own recipe_name in every call site, including PEFT detection (_fetch_peft, _deploy_model_customization) and _is_nova_model, not just hosting-config disambiguation. The docstring/field help describes recipe_name as a disambiguation override, so a user who sets it to pick a hosting config would also silently change PEFT-type ("lora" in recipe_name) and Nova detection. Consider restricting the override to the hosting-config resolution paths, or documenting that it influences PEFT/Nova inference as well.

This branch was previously deployed

1 inactive deployment
auto-approve — de649e13 Deployed Oct 13, 2026 by lucasjia-aws via wait-for-approval #660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model builder unable to

1 participant