Skip to content

fix: better handling of parametrized types#991

Merged
JohannesMessner merged 8 commits intofeat-rewrite-v2from
fix-bad-torch-subclassing
Jan 12, 2023
Merged

fix: better handling of parametrized types#991
JohannesMessner merged 8 commits intofeat-rewrite-v2from
fix-bad-torch-subclassing

Conversation

@JohannesMessner
Copy link
Copy Markdown
Member

@JohannesMessner JohannesMessner commented Jan 5, 2023

Signed-off-by: Johannes Messner [email protected]

Goals:

fix #988

This fixes the issue by making sure that parametrized types that are equivalent are treated as equal.
For example, the code snippet:

TorchTensor[128, 128]
TorchTensor[128, 128]

creates two different but identical classes.
This PR makes it such that issubclass and isinstance checks treat these two classes as the same class.

This fixes a bunch of downstream bugs, such as #998 and other cases that can be seen in the tests that are added by this PR.

@JohannesMessner JohannesMessner added the DocArray v2 This issue is part of the rewrite; not to be merged into main label Jan 5, 2023
@JohannesMessner JohannesMessner requested a review from samsja January 5, 2023 13:31
@JohannesMessner JohannesMessner self-assigned this Jan 5, 2023
@JohannesMessner JohannesMessner linked an issue Jan 5, 2023 that may be closed by this pull request
@JohannesMessner JohannesMessner marked this pull request as draft January 5, 2023 13:33
@JohannesMessner
Copy link
Copy Markdown
Member Author

I believe there is a deeper issue at hand that we better solve.
Or at the very least, make sure we properly understand the repercussions of this fix.

So let's not merge this for now.

JohannesMessner and others added 6 commits January 12, 2023 13:06
ShapeT = TypeVar('ShapeT')


class _ParametrizedMeta(type):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure that type is needed here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure if it is strictly needed bc in the end the "final" metaclass will only inherit from this one, but I think if we wanted to use _ParametrizedMeta directly as a metaclass we would need it. So I think it is good practice for all metclasses to do it

Signed-off-by: Johannes Messner <[email protected]>
@JohannesMessner JohannesMessner changed the title fix: some hacky stuff that i don't understand fix: better handling of parametrized types Jan 12, 2023
@JohannesMessner JohannesMessner marked this pull request as ready for review January 12, 2023 13:26
@github-actions
Copy link
Copy Markdown

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

@JohannesMessner JohannesMessner merged commit cc3c77c into feat-rewrite-v2 Jan 12, 2023
@JohannesMessner JohannesMessner deleted the fix-bad-torch-subclassing branch January 12, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core area/testing area/typing DocArray v2 This issue is part of the rewrite; not to be merged into main size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Shape info in tensor break forward in some pytorch op

2 participants