Skip to content

fix: fix deepcopy torchtensor #1720

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

Merged
merged 1 commit into from
Jul 21, 2023
Merged

fix: fix deepcopy torchtensor #1720

merged 1 commit into from
Jul 21, 2023

Conversation

JoanFM
Copy link
Member

@JoanFM JoanFM commented Jul 21, 2023

No description provided.

@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.72 🎉

Comparison is base (007f113) 84.84% compared to head (7b1384b) 85.56%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1720      +/-   ##
==========================================
+ Coverage   84.84%   85.56%   +0.72%     
==========================================
  Files         133      133              
  Lines        8583     8585       +2     
==========================================
+ Hits         7282     7346      +64     
+ Misses       1301     1239      -62     
Flag Coverage Δ
docarray 85.56% <100.00%> (+0.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
docarray/typing/tensor/torch_tensor.py 91.08% <100.00%> (+0.18%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Signed-off-by: Joan Fontanals Martinez <[email protected]>
@JoanFM JoanFM force-pushed the fix-torch-tensor-deepcopy branch from 2d79034 to 7b1384b Compare July 21, 2023 07:32
@github-actions
Copy link

📝 Docs are deployed on https://ft-fix-torch-tensor-deepcopy--jina-docs.netlify.app 🎉

@@ -271,3 +271,10 @@ def _docarray_from_ndarray(cls: Type[T], value: np.ndarray) -> T:
def _docarray_to_ndarray(self) -> np.ndarray:
"""cast itself to a numpy array"""
return self.detach().cpu().numpy()

def new_empty(self, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we copy the full signature of the original method ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is always the same, I do not think it makes sense, this is way more mantainable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this break everything related to mypy and pycharm feature. In DocArray v2 we always repeat the full signature of the function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but mypy check passes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method on TorchEmbedding does the same.
This is a method that noone should use
It is easier to forget to update this method than anything else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay oaky

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy pass because it does not look at it. It will only check if there is type hint

@JoanFM JoanFM requested a review from samsja July 21, 2023 11:48
@JoanFM JoanFM merged commit 304a4e9 into main Jul 21, 2023
@JoanFM JoanFM deleted the fix-torch-tensor-deepcopy branch July 21, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TorchTensor cannot be deep copied.
2 participants