Skip to content

C++ tensor print doesn't show requires_grad and grad_fn like Python tensor print #36004

@yf225

Description

@yf225

In Python, we have the following tensor print behavior:

>>> x=torch.ones(2, 2, requires_grad=True)
>>> x
tensor([[1., 1.],
        [1., 1.]], requires_grad=True)
>>> y=x*2
>>> y
tensor([[2., 2.],
        [2., 2.]], grad_fn=<MulBackward0>)

However in C++, we have the following behavior:

auto x = torch::ones({2, 2}, torch::requires_grad());
std::cout << x << std::endl;
auto y = x * 2;
std::cout << y << std::endl;
 1  1
 1  1
[ CPUFloatType{2,2} ]
 2  2
 2  2
[ CPUFloatType{2,2} ]

It would be nice to show requires_grad and grad_fn in C++ tensor print as well.

cc @yf225

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: cppRelated to C++ APImodule: printingIssues related to the printing format of tensorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions