SIGN IN SIGN UP

Remove NJT (nested jagged tensor) from weights_only safe globals (#194380)

NestedTensors are no longer allowlisted by default for `weights_only` loads, and `torch.nested` no longer registers them via `add_safe_globals` on import. Loading a checkpoint containing an NJT now raises the generic unsupported-global error.

NJTs can still be loaded by explicitly opting in with the `safe_globals` context manager:
```python
from torch.nested._internal.nested_tensor import _rebuild_njt, NestedTensor
with torch.serialization.safe_globals([_rebuild_njt, NestedTensor]):
    njt = torch.load(path, weights_only=True)
```

Authored with assistance from Claude (Anthropic AI assistant).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/194380
Approved by: https://github.com/albanD
N
Nikita Shulga committed
66eef30319a680c8238ec162d5f1b8bfa7370716
Parent: b6b0c8c
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com> on 8/24/2026, 1:38:42 AM