Conversation
…il in ModelTrain (5504)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add tests for PipelineVariable support in ModelTrainer hyperparameters
Problem
The
safe_serializefunction insagemaker-train/src/sagemaker/train/utils.pywas previously unable to handlePipelineVariableobjects (e.g.,ParameterInteger,ParameterString) passed as hyperparameter values, causing aTypeError: Object of type ParameterInteger is not JSON serializablewhen building pipelines.While this bug has already been fixed in the codebase (the
safe_serializefunction now has an explicitelif isinstance(data, PipelineVariable): return databranch), there was a test gap: the existingtest_model_trainer_pipeline_variable.pytested PipelineVariable fortraining_image,algorithm_name,training_input_mode, andenvironmentfields but did NOT test PipelineVariable inhyperparameters— which is the exact scenario from the bug report.Changes
Added the following tests to
test_model_trainer_pipeline_variable.py:In
TestModelTrainerPipelineVariableAcceptance:test_hyperparameters_accept_parameter_integer— verifiesParameterIntegercan be used as a hyperparameter valuetest_hyperparameters_accept_parameter_string— verifiesParameterStringcan be used as a hyperparameter valuetest_hyperparameters_accept_mixed_pipeline_and_static_values— verifies a mix of PipelineVariable and static values worksNew
TestSafeSerializePipelineVariableclass:test_safe_serialize_with_parameter_integer— verifiessafe_serializereturnsParameterIntegeras-istest_safe_serialize_with_parameter_string— verifiessafe_serializereturnsParameterStringas-istest_safe_serialize_with_parameter_float— verifiessafe_serializereturnsParameterFloatas-istest_safe_serialize_with_plain_string— regression test for plain string passthroughtest_safe_serialize_with_int— regression test for integer JSON serializationtest_safe_serialize_with_dict— regression test for dict JSON serializationTesting
All new tests validate the fix is properly covered and will prevent regressions.
Related Issue
Related issue: 5504
Changes Made
The bug described in the issue has already been fixed in the current codebase. The
safe_serializefunction insagemaker-train/src/sagemaker/train/utils.pyalready handlesPipelineVariableobjects with an explicitelif isinstance(data, PipelineVariable): return databranch (line ~176). Theserializefunction insagemaker-core/src/sagemaker/core/utils/utils.pyalso handles PipelineVariable by returning it as-is. Both functions correctly prevent theTypeError: Object of type ParameterInteger is not JSON serializableerror. However, there is a test gap: the existingtest_model_trainer_pipeline_variable.pytests PipelineVariable fortraining_image,algorithm_name,training_input_mode, andenvironmentfields but does NOT test PipelineVariable inhyperparameters— which is the exact scenario from the bug report. We should add tests to ensure this scenario stays covered.AI-Generated PR
This PR was automatically generated by the PySDK Issue Agent.
Merge Checklist
prefix: descriptionformat