-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[xdoctest] reformat example code with google style in No.21-30 #55849
Conversation
This reverts commit 76bcdb2.
你的PR提交成功,感谢你对开源项目的贡献! |
>>> z = cus_tanh.apply(data) | ||
>>> z.mean().backward() | ||
|
||
>>> print(data.grad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果有输出的话后面加上~
>>> print(data.grad)
Tensor(shape=[2, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
[[0.16604150, 0.05858341, 0.14051214],
[0.15677770, 0.01564609, 0.02991660]])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果有输出的话后面加上~
>>> print(data.grad) Tensor(shape=[2, 3], dtype=float64, place=Place(cpu), stop_gradient=True, [[0.16604150, 0.05858341, 0.14051214], [0.15677770, 0.01564609, 0.02991660]])
函数里有print,调用函数时会打印,这种需要写输出吗,python/paddle/autograd/saved_tensors_hooks.py中
` >>> # Example1
>>> import paddle
>>> def pack_hook(x):
... print("Packing", x)
... return x.numpy()
>>> def unpack_hook(x):
... print("UnPacking", x)
... return paddle.to_tensor(x)
>>> a = paddle.ones([3,3])
>>> b = paddle.ones([3,3]) * 2
>>> a.stop_gradient = False
>>> b.stop_gradient = False
>>> with paddle.autograd.saved_tensors_hooks(pack_hook, unpack_hook):
... y = paddle.multiply(a, b)
>>> y.sum().backward()`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得优先以原示例为准吧~ 如果原来有,就把新的输出改上去,如果没有就算了~
python/paddle/framework/io.py
Outdated
>>> path = "example/main_program.pdmodel" | ||
>>> paddle.save(main_program, path) | ||
>>> load_main = paddle.load(path) | ||
>>> print(load_main) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里感觉没有 print 的必要~ 去掉?
regularizer=L2Decay(0.), | ||
initializer=nn.initializer.Bilinear()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两行加上 ...
这个前缀吧~
不加前缀 xdoctest 也能兼容,但指不定哪天不用 xdoctest 了,这就出问题了~
另外,这个文件不是用 convert-doctest 转换的?按理说应该可以自动加上前缀的,bug ? ... ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没有使用convert-doctest,纯属打漏了
>>> print(linear.weight) | ||
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False, | ||
[[2., 2., 2., 2.], | ||
[2., 2., 2., 2.]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
少了一行
Parameter containing:
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
[[2., 2., 2., 2.],
[2., 2., 2., 2.]])
python/paddle/framework/random.py
Outdated
import paddle | ||
sts = paddle.get_rng_state() | ||
>>> import paddle | ||
>>> paddle.seed(2023) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也是有必要 seed 的么?是要固定什么的随机性呢?
python/paddle/framework/random.py
Outdated
import paddle | ||
sts = paddle.get_cuda_rng_state() | ||
>>> import paddle | ||
>>> paddle.seed(2023) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/framework/random.py
Outdated
sts = paddle.get_rng_state() | ||
paddle.set_rng_state(sts) | ||
>>> import paddle | ||
>>> paddle.seed(2023) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/framework/random.py
Outdated
sts = paddle.get_cuda_rng_state() | ||
paddle.set_cuda_rng_state(sts) | ||
>>> import paddle | ||
>>> paddle.seed(2023) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
>>> w_attr = paddle.ParamAttr(learning_rate=0., | ||
... regularizer=L2Decay(0.), | ||
... initializer=nn.initializer.Bilinear()) | ||
>>> paddle.seed(2023) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没输出也不需要固定 seed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMeow~
hi, @ooooo-create
|
PR types
Others
PR changes
Others
Description
修改如下文件的示例代码,使其通过
xdoctest
检查:预览:
关联 PR:
#55629
#55295
@sunzhongkai588 @SigureMo @megemini