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

Refine the format of printing tensor #27673

Merged
merged 12 commits into from
Oct 13, 2020

Conversation

zhiqiu
Copy link
Contributor

@zhiqiu zhiqiu commented Sep 28, 2020

PR types

Others

PR changes

Others

Describe

Refine the format of printing tensor

  • Provides a new API, paddle.set_printoptions(precision=None, threshold=None, edgeitems=None, sci_mode=None), which is similar with numpy.set_printoptions. See details in the code comments.

  • Print short forms when the size of the Tensor exceeds the threshold.

For example, the following example code,

  • Before
import paddle
print(paddle.rand([10,10]))

Tensor: eager_tmp_0
  - place: CPUPlace
  - shape: [10, 10]
  - layout: NCHW
  - dtype: float
  - data: [0.533863 0.0797833 0.221516 0.812535 0.886828 0.0622117 0.0192084 0.20787 0.0820772 0.948683 0.888249 0.67202 0.0943131 0.589427 0.232097 0.561007 0.39321 0.649692 0.261727 0.810542 0.671124 0.830243 0.658425 0.825302 0.129626 0.17518 0.106716 0.268798 0.135505 0.972766 0.391849 0.931962 0.716626 0.259243 0.902846 0.302401 0.208576 0.182095 0.915462 0.25003 0.21024 0.484252 0.319637 0.216295 0.798256 0.61407 0.753209 0.168424 0.988953 0.735267 0.0641483 0.501011 0.283179 0.330886 0.218066 0.260493 0.237336 0.426256 0.824428 0.965626 0.732239 0.896424 0.293316 0.669529 0.847223 0.315755 0.787443 0.646005 0.320226 0.644231 0.676818 0.659425 0.101772 0.616528 0.40214 0.719995 0.864722 0.98008 0.454678 0.753384 0.601966 0.483612 0.421961 0.482417 0.736744 0.36805 0.140307 0.781247 0.55052 0.16105 0.0330559 0.642412 0.889036 0.664003 0.089531 0.749408 0.696497 0.608919 0.148653 0.637941]
  • After
import paddle

paddle.manual_seed(10)
a = paddle.rand([10, 20])
paddle.set_printoptions(4, 100, 3)
print(a)

linear = paddle.nn.Linear(3, 5)
print(linear.weight)

Tensor(shape=[10, 20], dtype=float32, place=CPUPlace, stop_gradient=True,
       [[0.2727, 0.5489, 0.8655, ..., 0.2916, 0.8525, 0.9000],
        [0.3806, 0.8996, 0.0928, ..., 0.9535, 0.8378, 0.6409],
        [0.1484, 0.4038, 0.8294, ..., 0.0148, 0.6520, 0.4250],
        ...,
        [0.3426, 0.1909, 0.7240, ..., 0.4218, 0.2676, 0.5679],
        [0.5561, 0.2081, 0.0676, ..., 0.9778, 0.3302, 0.9559],
        [0.2665, 0.8483, 0.5389, ..., 0.4956, 0.6862, 0.9178]])

Parameter containing:
Tensor(shape=[3, 5], dtype=float32, place=CPUPlace, stop_gradient=False,
       [[-0.5238,  0.1450, -0.1731, -0.1135,  0.6033],
        [ 0.5953, -0.3029,  0.8256,  0.6461, -0.5687],
        [-0.0755, -0.5802, -0.3434, -0.6548,  0.8353]])

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

dingjiaweiww
dingjiaweiww previously approved these changes Oct 10, 2020
Copy link
Contributor

@dingjiaweiww dingjiaweiww left a comment

Choose a reason for hiding this comment

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

LGTM

luotao1
luotao1 previously approved these changes Oct 12, 2020
Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM for framework.py

lanxianghit
lanxianghit previously approved these changes Oct 12, 2020
@zhiqiu zhiqiu dismissed stale reviews from lanxianghit and luotao1 via a7c621a October 12, 2020 12:33
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhiqiu zhiqiu merged commit 049696b into PaddlePaddle:develop Oct 13, 2020
chen-zhiyu pushed a commit to chen-zhiyu/Paddle that referenced this pull request Oct 15, 2020
* add sumary feature

* refine printting tensor

* add sci_mode

* add sample code

* fix indent error

* fix _format_item

* polish code

* support item indent

* add ut

* set place for ut

* fix py2 issue

* fix ut
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

Successfully merging this pull request may close these issues.

None yet

5 participants