Skip to content

[Feature] A pydantic tensorclass implementation #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tensordict/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4771,6 +4771,11 @@ def is_cuda(self):
def is_cpu(self):
return self.device is not None and self.device.type == "cpu"

@property
def is_meta(self):
dtype = self.dtype
return dtype is not None and self.dtype == torch.meta

# Serialization functionality
def state_dict(
self,
Expand Down
8 changes: 4 additions & 4 deletions tensordict/tensorclass.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class TensorClass:
lock: bool = False,
**kwargs,
) -> None: ...
@property
def is_meta(self) -> bool: ...
def __bool__(self) -> bool: ...
def __ne__(self, other: object) -> T: ...
def __xor__(self, other: TensorDictBase | float): ...
Expand Down Expand Up @@ -459,9 +457,11 @@ class TensorClass:
def cpu(self, **kwargs) -> T: ...
def cuda(self, device: int | None = None, **kwargs) -> T: ...
@property
def is_cuda(self): ...
def is_cuda(self) -> bool: ...
@property
def is_cpu(self): ...
def is_cpu(self) -> bool: ...
@property
def is_meta(self) -> bool: ...
def state_dict(
self,
destination: Incomplete | None = None,
Expand Down
Loading
Loading