You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 299438e
Browse filesBrowse the repository at this point in the historyBrowse files
Installing sagemaker-serve (or the umbrella sagemaker, which depends on
it) pulled torch, and on Linux the ~2.9 GB CUDA/cuDNN/NCCL closure, even
for API-only use. sagemaker-core already declared torch an extra;
sagemaker-serve declared it required, so serve users paid regardless.
The import-time blocker was DEFAULT_SERIALIZERS_BY_FRAMEWORK in
serve/constants.py, which instantiated TorchTensorSerializer() at module
scope, running `from torch import Tensor` on any `import sagemaker.serve`.
Changes:
- Store serializer/deserializer classes (not instances) in
DEFAULT_SERIALIZERS_BY_FRAMEWORK; instantiate on lookup. Removes the
import-time torch dependency.
- Move torch>=2.0.0 to a `torch` extra in sagemaker-serve, matching
sagemaker-core. Add a `torch` extra to the umbrella sagemaker package
(sagemaker-serve[torch]) so `pip install sagemaker[torch]` works.
- Duck-type the tensor check in TorchTensorSerializer: serialization only
needs the object's own detach()/numpy(), so it no longer imports torch
at all and works whenever the caller holds a tensor.
- Make the in-process model server's torch import lazy with a CPU
fallback, so importing it no longer requires torch.
- Fix the error messages that told serve users to install the wrong
package: TorchTensorDeserializer, the Triton translator, and the ONNX
export path now name sagemaker-serve[torch].
- Update and add tests asserting the whole surface imports and serializes
without torch, and that the paths that genuinely construct torch
objects (deserializer, Triton translator) still raise a clear error
naming the extra.
Fixes#5531
Breaking change: users who installed plain sagemaker-serve and relied on
a torch code path (deserializing to tensor/pt, or ONNX/Triton export of a
PyTorch model) must now install sagemaker-serve[torch]. Both paths
inherently require a torch object the caller supplies, so torch is
already present in practice; a GitHub-wide search found no external
callers of these paths that do not already import torch.
---
X-AI-Prompt: address the reviewer concern on whether making torch optional breaks existing customers; find ways to reduce the torch dependency and update pyproject and docs; consolidate all changes in the goelakash93 fork for a possible major version bump.
X-AI-Tool: Claude Code
0 commit comments