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

Possible to only inline preview of the first line for each variable #1855

Closed
zhuoqun-chen opened this issue Mar 4, 2025 · 4 comments
Closed
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@zhuoqun-chen
Copy link

zhuoqun-chen commented Mar 4, 2025

I have a use case where I need to know the shapes of each torch.Tensor, I have a custom hack for pytorch in python:

import torch
torch_available = True
def torch_custom_repr(self):
    return f">>> {tuple(self.shape)}\n{torch_original_repr(self)}\non <{self.device}>\n<<< {tuple(self.shape)}"

torch_original_repr = torch.Tensor.__repr__
torch.Tensor.__repr__ = torch_custom_repr

Now it looks like this in debug mode:

Image

Is it possible to make it shorter like this:

Image
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Mar 4, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Mar 4, 2025

Not sure what the question is. You've created your own custom __repr__, if you want it to output something different, change it again?

@zhuoqun-chen
Copy link
Author

zhuoqun-chen commented Mar 4, 2025

Hi @rchiodo , thx for your quick replay, do you mean that no matter how I implement __repr__, it will not affect the debug window like this right?

Image

If that is the case, I think my problem is solved. Because I just don't want it to print the actual values of the array, it's kind messy, I only need to print the shape of the tensors in inline preview.

@rchiodo
Copy link
Contributor

rchiodo commented Mar 4, 2025

Changing __repr__ should change the first level of an object when viewed in the debugger, but yes it shouldn't affect the children.

Your original screen shot showed the first level of a tensor, you'd change your custom __repr__ if you wanted that to look different.

@zhuoqun-chen
Copy link
Author

Thank you very much! My problem is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants