feature: Torch dependency in sagameker-core to be made optional (5457)#5714
Draft
aviruthen wants to merge 5 commits intoaws:masterfrom
Draft
feature: Torch dependency in sagameker-core to be made optional (5457)#5714aviruthen wants to merge 5 commits intoaws:masterfrom
aviruthen wants to merge 5 commits intoaws:masterfrom
Conversation
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
The torch dependency in sagemaker-core/pyproject.toml is declared as a required dependency ('torch>=1.9.0') but torch is only actually used in two client-side classes: TorchTensorSerializer and TorchTensorDeserializer, both of which already use lazy imports inside init. The torchrun_driver.py imports torch but runs inside the SageMaker training container (not client-side). All other files only reference 'pytorch' as a string. The fix is to: (1) move torch from required dependencies to an optional extras group in pyproject.toml, (2) ensure torch imports in serializer/deserializer use DeferredError pattern (deserializer already has try/except but raises immediately - should use DeferredError), and (3) update the serializer implementations.py and deserializer implementations.py to not eagerly import TorchTensorSerializer/TorchTensorDeserializer at module level.
Related Issue
Related issue: 5457
Changes Made
sagemaker-core/pyproject.tomlsagemaker-core/src/sagemaker/core/serializers/base.pysagemaker-core/src/sagemaker/core/deserializers/base.pysagemaker-core/tests/unit/serializers/test_torch_optional.pyAI-Generated PR
This PR was automatically generated by the PySDK Issue Agent.
Merge Checklist
prefix: descriptionformat