Repository navigation
fix: set VolumeKmsKeyId on ModelStep runtime repack job - #6537
mohamedzeidan2021 merged 1 commit into
Conversation
ModelBuilder.build() defers source-code repacking to a _RepackModelStep when model data is a pipeline variable. That step built its Compute with only an instance type, so repack_model_step_settings could not set the compute-volume KMS key: unknown settings were forwarded to ModelTrainer rather than the job's Compute. As a result the runtime repack training job could not encrypt its storage volume with a customer-managed key, and the generated request had no ResourceConfig.VolumeKmsKeyId. Thread volume_kms_key_id from repack_model_step_settings into the repack job's Compute (mirroring how instance_type is handled), and default it from the model's KMS key using setdefault so an explicit override wins (mirroring the existing output_data_config logic). Add unit tests covering an explicit key, an omitted key, a user override, and a pipeline-variable key, at both the ModelStep and _RepackModelStep layers. Fixes aws#6536
There was a problem hiding this comment.
🤖 AI code review
This PR fixes GH #6536 by threading volume_kms_key_id through _RepackModelStep into the repack job's Compute (so it lands on ResourceConfig.VolumeKmsKeyId), and defaulting it from the model's KMS key in ModelStep._append_repack_model_step via setdefault so explicit overrides still win. The change mirrors the existing output_data_config wiring pattern (PR #6338), Compute from sagemaker.core.training.configs does accept volume_kms_key_id, and _repack_model_step_settings is always a dict so setdefault is safe. Tests cover the explicit-key, omitted-key, user-override, and pipeline-variable cases at both layers. The change looks clean and I found no issues.
Reviewed commit d604bd0. Automated review; verify before acting.
Issue #, if available
Fixes #6536
Description
ModelBuilder.build()defers source-code repacking to an internal_RepackModelStepwhen the model data is a pipeline variable. That step constructed itsComputewith only an instance type:so
ModelStep.repack_model_step_settingscould not set the compute-volume KMS key — anyvolume_kms_key_idwas forwarded toModelTraineras a stray kwarg instead of being applied to the job'sCompute. As a result the runtime repack training job could not encrypt its storage volume with a customer-managed KMS key, and the generated training request contained noResourceConfig.VolumeKmsKeyId.Fix
_utils.py—_RepackModelStepnow popsvolume_kms_key_idfromkwargsintoCompute(mirroring howinstance_typeis already handled), so it lands onResourceConfig.VolumeKmsKeyId. When omitted it staysNoneand the field is not emitted (legacy behavior preserved).model_step.py—volume_kms_key_idis defaulted from the model's KMS key usingsetdefault, mirroring the existingoutput_data_configlogic, so an explicitrepack_model_step_settingsoverride still wins.Behavior
ResourceConfig.VolumeKmsKeyId{"volume_kms_key_id": K}{"volume_kms_key_id": <PipelineVariable>}Testing done
VolumeKmsKeyIdabsent →KeyError) and confirmed it passes after.ModelStepand_RepackModelSteplayers.pytest sagemaker-mlops/tests/unit/workflow/→ 418 passed.black --checkandflake8(repo config) clean on all changed files.Merge Checklist
Put an
xin the boxes that apply.Tests
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.