Skip to content
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

torch.nn.Module Memory Address Changes After Importing torchdrug #227

Open
benyaminjami opened this issue Oct 11, 2023 · 0 comments
Open

Comments

@benyaminjami
Copy link

Hello,

I've encountered an unexpected behavior when using torchdrug alongside PyTorch. Specifically, after importing torchdrug, the memory address of torch.nn.Module changes, which leads to issues when checking instances of nn.Module.

Here's a simple reproduction of the issue:


import torch.nn as nn

# Print the memory address of nn.Module before importing torchdrug
print(id(nn.Module))  # Outputs: 104525552

import torchdrug

# Print the memory address of nn.Module after importing torchdrug
print(id(nn.Module))  # Outputs: 172015376

As observed, the memory address of nn.Module changes after importing torchdrug, which suggests that the torch.nn.Module class is being shadowed or replaced in some way by torchdrug.

This behavior leads to unexpected issues, such as the isinstance check failing for classes that inherit from nn.Module.

Questions:

Is this behavior intentional? If so, what's the rationale behind it?
Are there any recommended workarounds or solutions to address this issue?
Is this issue known, and are there any plans to address it in future releases?
Thank you for your assistance and looking forward to your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant