fix: generate repack step for ModelBuilder.register/build in ModelStep (#5828, #5829) - #6338
mohamedzeidan2021 wants to merge 1 commit into
Conversation
…ws#5828, aws#5829) In v2, Model.register()/create() placed the Model instance (carrying sagemaker_session, role, model_data, entry_point, source_dir, ...) into the pipeline context, so ModelStep repacked it. In v3, ModelBuilder.register()/build() place the ModelBuilder into the context, but ModelStep._append_repack_model_step only accepted sagemaker.core.resources.Model, so a ModelBuilder fell through to 'No models to repack' and the model was never repacked with the user's source_code (aws#5828). The v3 core Model is a pydantic model with extra='forbid' and no sagemaker_session field, so it could never satisfy ModelStep's reads (aws#5829). Make the repack path ModelBuilder-aware: accept a ModelBuilder in the repack gate and map its attributes (model_name/role_arn/s3_model_data_url/source_code.requirements) to _RepackModelStep's parameters. Also stop passing v2-era args (dependencies/ output_path/output_kms_key) that are not part of the v3 _RepackModelStep signature and would leak into ModelTrainer; pass 'requirements' as the v3 step expects.
|
Claude finished @mohamedzeidan2021's task in 3m 27s —— View job Code Review — repack step for
|
Issues
Fixes #5828 and #5829.
In v2,
Model.register()/.create()placed the Model instance (carryingsagemaker_session,role,model_data,entry_point,source_dir, …) into the pipeline context, soModelStepgenerated a repack step and repacked the model with the user'ssource_code.In v3,
ModelBuilder.register()/.build()place the ModelBuilder into the pipeline context, butModelStep._append_repack_model_stepstill gated onisinstance(self._model, sagemaker.core.resources.Model). AModelBuilderfails that check, so the step logged "No models to repack" and no repack step was generated — the registered model was never repacked with the source code (#5828). Separately, the v3 coreModelis a pydantic model (extra="forbid") with nosagemaker_sessionfield, so it can never satisfy the attribute readsModelStepperforms (#5829). The result was a v3-only regression of working v2 behavior; the v3 repack path was effectively dead (it also still passed v2-era_RepackModelStepargs —dependencies/output_path/output_kms_key— that don't exist on the v3_RepackModelStepsignature and leaked intoModelTrainer).Fix
Make the repack path ModelBuilder-aware (additive; the legacy
Modelbranch is unchanged):(Model, ModelBuilder)._repack_inputs_for(model)maps aModelBuilder's attributes to_RepackModelStep's parameters (model_name→name,role_arn→role,s3_model_data_url→model_data,entry_point,source_dir,source_code.requirements→requirements).requirements=(what the v3_RepackModelStepexpects) and drop the v2-era args that were leaking intoModelTrainer.need_runtime_repackholdsid(model_builder), so the loop still iterates the raw builder for the identity match.Validation
sagemaker-mlops/tests/unit/workflow/test_model_step.py): new tests assert a repack step is generated and the containerModelDataUrlis rewired to the repacked artifact; and that an unrecognized model type still yields no repack step. Fails on master (0 repack steps), passes with the fix.ModelBuilder.register()→ModelStepproduced aRepackModelTraining step; the pipeline executed to Succeeded, the RepackModel step ran, and the registered model package's containerModelDataUrlpointed to the repacked artifact (differing from the original input).black/flake8clean; broadertests/unit/workflowsubset: 332 passed.Backwards compatibility
Additive — the existing core-
Modelrepack branch is unchanged, thebuild()dict path (model=None) is unaffected, and_resolve_repack_model_step_vpc_configsnow usesgetattr(..., "vpc_config", None)(safe for both types). No public API change.