Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
162b4d6c
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
162b4d6c
编写于
9月 27, 2020
作者:
Z
Zhou Wei
提交者:
GitHub
9月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove to_variable from 2.0 (#27528)
上级
9b124014
变更
38
显示空白变更内容
内联
并排
Showing
38 changed file
with
102 addition
and
114 deletion
+102
-114
python/paddle/__init__.py
python/paddle/__init__.py
+0
-1
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+2
-5
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+4
-4
python/paddle/fluid/tests/unittests/test_adamax_api.py
python/paddle/fluid/tests/unittests/test_adamax_api.py
+1
-1
python/paddle/fluid/tests/unittests/test_adamw_op.py
python/paddle/fluid/tests/unittests/test_adamw_op.py
+2
-2
python/paddle/fluid/tests/unittests/test_adaptive_avg_pool2d.py
.../paddle/fluid/tests/unittests/test_adaptive_avg_pool2d.py
+2
-2
python/paddle/fluid/tests/unittests/test_adaptive_avg_pool3d.py
.../paddle/fluid/tests/unittests/test_adaptive_avg_pool3d.py
+2
-2
python/paddle/fluid/tests/unittests/test_adaptive_max_pool2d.py
.../paddle/fluid/tests/unittests/test_adaptive_max_pool2d.py
+2
-2
python/paddle/fluid/tests/unittests/test_adaptive_max_pool3d.py
.../paddle/fluid/tests/unittests/test_adaptive_max_pool3d.py
+2
-2
python/paddle/fluid/tests/unittests/test_addmm_op.py
python/paddle/fluid/tests/unittests/test_addmm_op.py
+3
-3
python/paddle/fluid/tests/unittests/test_arange.py
python/paddle/fluid/tests/unittests/test_arange.py
+3
-3
python/paddle/fluid/tests/unittests/test_cholesky_op.py
python/paddle/fluid/tests/unittests/test_cholesky_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_clip_op.py
python/paddle/fluid/tests/unittests/test_clip_op.py
+3
-3
python/paddle/fluid/tests/unittests/test_concat_op.py
python/paddle/fluid/tests/unittests/test_concat_op.py
+3
-3
python/paddle/fluid/tests/unittests/test_cosine_similarity_api.py
...addle/fluid/tests/unittests/test_cosine_similarity_api.py
+8
-8
python/paddle/fluid/tests/unittests/test_cumsum_op.py
python/paddle/fluid/tests/unittests/test_cumsum_op.py
+1
-2
python/paddle/fluid/tests/unittests/test_default_dtype.py
python/paddle/fluid/tests/unittests/test_default_dtype.py
+0
-1
python/paddle/fluid/tests/unittests/test_directory_migration.py
.../paddle/fluid/tests/unittests/test_directory_migration.py
+1
-1
python/paddle/fluid/tests/unittests/test_flatten_contiguous_range_op.py
...fluid/tests/unittests/test_flatten_contiguous_range_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_imperative_basic.py
python/paddle/fluid/tests/unittests/test_imperative_basic.py
+2
-2
python/paddle/fluid/tests/unittests/test_imperative_selected_rows.py
...le/fluid/tests/unittests/test_imperative_selected_rows.py
+1
-1
python/paddle/fluid/tests/unittests/test_isfinite_v2_op.py
python/paddle/fluid/tests/unittests/test_isfinite_v2_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_jit_save_load.py
python/paddle/fluid/tests/unittests/test_jit_save_load.py
+7
-7
python/paddle/fluid/tests/unittests/test_kldiv_loss_op.py
python/paddle/fluid/tests/unittests/test_kldiv_loss_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_l1_loss.py
python/paddle/fluid/tests/unittests/test_l1_loss.py
+4
-4
python/paddle/fluid/tests/unittests/test_log_softmax.py
python/paddle/fluid/tests/unittests/test_log_softmax.py
+2
-2
python/paddle/fluid/tests/unittests/test_logsumexp.py
python/paddle/fluid/tests/unittests/test_logsumexp.py
+2
-2
python/paddle/fluid/tests/unittests/test_max_op.py
python/paddle/fluid/tests/unittests/test_max_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_maximum_op.py
python/paddle/fluid/tests/unittests/test_maximum_op.py
+4
-4
python/paddle/fluid/tests/unittests/test_mean_op.py
python/paddle/fluid/tests/unittests/test_mean_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_min_op.py
python/paddle/fluid/tests/unittests/test_min_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_randn_op.py
python/paddle/fluid/tests/unittests/test_randn_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_retain_graph.py
python/paddle/fluid/tests/unittests/test_retain_graph.py
+2
-2
python/paddle/fluid/tests/unittests/test_transformer_api.py
python/paddle/fluid/tests/unittests/test_transformer_api.py
+20
-20
python/paddle/fluid/tests/unittests/test_zeros_like_op.py
python/paddle/fluid/tests/unittests/test_zeros_like_op.py
+1
-1
python/paddle/tensor/linalg.py
python/paddle/tensor/linalg.py
+6
-12
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+1
-2
tools/wlist.json
tools/wlist.json
+3
-2
未找到文件。
python/paddle/__init__.py
浏览文件 @
162b4d6c
...
...
@@ -230,7 +230,6 @@ from .framework import CPUPlace #DEFINE_ALIAS
from
.framework
import
CUDAPlace
#DEFINE_ALIAS
from
.framework
import
CUDAPinnedPlace
#DEFINE_ALIAS
from
.framework
import
to_variable
#DEFINE_ALIAS
from
.framework
import
grad
#DEFINE_ALIAS
from
.framework
import
no_grad
#DEFINE_ALIAS
from
.framework
import
save
#DEFINE_ALIAS
...
...
python/paddle/fluid/dygraph/nn.py
浏览文件 @
162b4d6c
...
...
@@ -3230,14 +3230,11 @@ class Flatten(layers.Layer):
.. code-block:: python
import paddle
from paddle import to_variable
import numpy as np
inp_np = np.ones([5, 2, 3, 4]).astype('float32')
paddle.disable_static()
inp_np = to_variable(inp_np)
inp_np = np.ones([5, 2, 3, 4]).astype('float32')
inp_np = paddle.to_tensor(inp_np)
flatten = paddle.nn.Flatten(start_axis=1, stop_axis=2)
flatten_res = flatten(inp_np)
...
...
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
162b4d6c
...
...
@@ -228,7 +228,7 @@ class TestTanhAPI(unittest.TestCase):
def
test_dygraph_api
(
self
):
paddle
.
disable_static
(
self
.
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out1
=
F
.
tanh
(
x
)
out2
=
paddle
.
tanh
(
x
)
th
=
paddle
.
nn
.
Tanh
()
...
...
@@ -573,7 +573,7 @@ class TestHardShrinkAPI(unittest.TestCase):
def
test_dygraph_api
(
self
):
paddle
.
disable_static
(
self
.
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out1
=
F
.
hardshrink
(
x
)
hd
=
paddle
.
nn
.
Hardshrink
()
out2
=
hd
(
x
)
...
...
@@ -639,7 +639,7 @@ class TestHardtanhAPI(unittest.TestCase):
def
test_dygraph_api
(
self
):
paddle
.
disable_static
(
self
.
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out1
=
F
.
hardtanh
(
x
)
m
=
paddle
.
nn
.
Hardtanh
()
out2
=
m
(
x
)
...
...
@@ -1063,7 +1063,7 @@ class TestLeakyReluAPI(unittest.TestCase):
def
test_dygraph_api
(
self
):
paddle
.
disable_static
(
self
.
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out1
=
F
.
leaky_relu
(
x
)
m
=
paddle
.
nn
.
LeakyReLU
()
out2
=
m
(
x
)
...
...
python/paddle/fluid/tests/unittests/test_adamax_api.py
浏览文件 @
162b4d6c
...
...
@@ -25,7 +25,7 @@ class TestAdamaxAPI(unittest.TestCase):
def
test_adamax_api_dygraph
(
self
):
paddle
.
disable_static
()
value
=
np
.
arange
(
26
).
reshape
(
2
,
13
).
astype
(
"float32"
)
a
=
paddle
.
to_
variable
(
value
)
a
=
paddle
.
to_
tensor
(
value
)
linear
=
paddle
.
nn
.
Linear
(
13
,
5
)
adam
=
paddle
.
optimizer
.
Adamax
(
learning_rate
=
0.01
,
...
...
python/paddle/fluid/tests/unittests/test_adamw_op.py
浏览文件 @
162b4d6c
...
...
@@ -22,7 +22,7 @@ class TestAdamWOp(unittest.TestCase):
def
test_adamw_op_dygraph
(
self
):
paddle
.
disable_static
()
value
=
np
.
arange
(
26
).
reshape
(
2
,
13
).
astype
(
"float32"
)
a
=
paddle
.
to_
variable
(
value
)
a
=
paddle
.
to_
tensor
(
value
)
linear
=
paddle
.
nn
.
Linear
(
13
,
5
)
adam
=
paddle
.
optimizer
.
AdamW
(
learning_rate
=
0.01
,
...
...
@@ -37,7 +37,7 @@ class TestAdamWOp(unittest.TestCase):
def
test_adamw_op_coverage
(
self
):
paddle
.
disable_static
()
value
=
np
.
arange
(
26
).
reshape
(
2
,
13
).
astype
(
"float32"
)
a
=
paddle
.
to_
variable
(
value
)
a
=
paddle
.
to_
tensor
(
value
)
linear
=
paddle
.
nn
.
Linear
(
13
,
5
)
adam
=
paddle
.
optimizer
.
AdamW
(
learning_rate
=
0.0
,
...
...
python/paddle/fluid/tests/unittests/test_adaptive_avg_pool2d.py
浏览文件 @
162b4d6c
...
...
@@ -147,7 +147,7 @@ class TestAdaptiveAvgPool2dAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out_1
=
paddle
.
nn
.
functional
.
adaptive_avg_pool2d
(
x
=
x
,
output_size
=
[
3
,
3
])
...
...
@@ -245,7 +245,7 @@ class TestAdaptiveAvgPool2dClassAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
adaptive_avg_pool
=
paddle
.
nn
.
AdaptiveAvgPool2d
(
output_size
=
[
3
,
3
])
out_1
=
adaptive_avg_pool
(
x
=
x
)
...
...
python/paddle/fluid/tests/unittests/test_adaptive_avg_pool3d.py
浏览文件 @
162b4d6c
...
...
@@ -162,7 +162,7 @@ class TestAdaptiveAvgPool3dAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out_1
=
paddle
.
nn
.
functional
.
adaptive_avg_pool3d
(
x
=
x
,
output_size
=
[
3
,
3
,
3
])
...
...
@@ -262,7 +262,7 @@ class TestAdaptiveAvgPool3dClassAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
adaptive_avg_pool
=
paddle
.
nn
.
AdaptiveAvgPool3d
(
output_size
=
[
3
,
3
,
3
])
...
...
python/paddle/fluid/tests/unittests/test_adaptive_max_pool2d.py
浏览文件 @
162b4d6c
...
...
@@ -147,7 +147,7 @@ class TestAdaptiveMaxPool2dAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out_1
=
paddle
.
nn
.
functional
.
adaptive_max_pool2d
(
x
=
x
,
return_indices
=
False
,
output_size
=
[
3
,
3
])
...
...
@@ -240,7 +240,7 @@ class TestAdaptiveMaxPool2dClassAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
adaptive_max_pool
=
paddle
.
nn
.
AdaptiveMaxPool2d
(
output_size
=
[
3
,
3
])
out_1
=
adaptive_max_pool
(
x
=
x
)
...
...
python/paddle/fluid/tests/unittests/test_adaptive_max_pool3d.py
浏览文件 @
162b4d6c
...
...
@@ -162,7 +162,7 @@ class TestAdaptiveMaxPool3dAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
out_1
=
paddle
.
nn
.
functional
.
adaptive_max_pool3d
(
x
=
x
,
output_size
=
[
3
,
3
,
3
])
...
...
@@ -257,7 +257,7 @@ class TestAdaptiveMaxPool3dClassAPI(unittest.TestCase):
if
core
.
is_compiled_with_cuda
()
else
[
False
]):
place
=
paddle
.
CUDAPlace
(
0
)
if
use_cuda
else
paddle
.
CPUPlace
()
paddle
.
disable_static
(
place
=
place
)
x
=
paddle
.
to_
variable
(
self
.
x_np
)
x
=
paddle
.
to_
tensor
(
self
.
x_np
)
adaptive_max_pool
=
paddle
.
nn
.
AdaptiveMaxPool3d
(
output_size
=
[
3
,
3
,
3
])
...
...
python/paddle/fluid/tests/unittests/test_addmm_op.py
浏览文件 @
162b4d6c
...
...
@@ -244,9 +244,9 @@ class TestAddMMAPI(unittest.TestCase):
def test_error1():
data_x_wrong = np.ones((2, 3)).astype(np.float32)
x = paddle.to_
variable
(data_x_wrong)
y = paddle.to_
variable
(data_y)
input = paddle.to_
variable
(data_input)
x = paddle.to_
tensor
(data_x_wrong)
y = paddle.to_
tensor
(data_y)
input = paddle.to_
tensor
(data_input)
out = paddle.tensor.addmm( input=input, x=x, y=y, beta=0.5, alpha=5.0 )
self.assertRaises(ValueError, test_error1)
'''
...
...
python/paddle/fluid/tests/unittests/test_arange.py
浏览文件 @
162b4d6c
...
...
@@ -98,9 +98,9 @@ class TestArangeImperative(unittest.TestCase):
x2
=
paddle
.
tensor
.
arange
(
5
)
x3
=
paddle
.
tensor
.
creation
.
arange
(
5
)
start
=
paddle
.
to_
variable
(
np
.
array
([
0
],
'float32'
))
end
=
paddle
.
to_
variable
(
np
.
array
([
5
],
'float32'
))
step
=
paddle
.
to_
variable
(
np
.
array
([
1
],
'float32'
))
start
=
paddle
.
to_
tensor
(
np
.
array
([
0
],
'float32'
))
end
=
paddle
.
to_
tensor
(
np
.
array
([
5
],
'float32'
))
step
=
paddle
.
to_
tensor
(
np
.
array
([
1
],
'float32'
))
x4
=
paddle
.
arange
(
start
,
end
,
step
,
'int64'
)
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_cholesky_op.py
浏览文件 @
162b4d6c
...
...
@@ -96,7 +96,7 @@ class TestDygraph(unittest.TestCase):
a
=
np
.
random
.
rand
(
3
,
3
)
a_t
=
np
.
transpose
(
a
,
[
1
,
0
])
x_data
=
np
.
matmul
(
a
,
a_t
)
+
1e-03
x
=
paddle
.
to_
variable
(
x_data
)
x
=
paddle
.
to_
tensor
(
x_data
)
out
=
paddle
.
cholesky
(
x
,
upper
=
False
)
...
...
python/paddle/fluid/tests/unittests/test_clip_op.py
浏览文件 @
162b4d6c
...
...
@@ -168,9 +168,9 @@ class TestClipAPI(unittest.TestCase):
paddle
.
disable_static
(
place
)
data_shape
=
[
1
,
9
,
9
,
4
]
data
=
np
.
random
.
random
(
data_shape
).
astype
(
'float32'
)
images
=
paddle
.
to_
variable
(
data
,
dtype
=
'float32'
)
v_min
=
paddle
.
to_
variable
(
np
.
array
([
0.2
],
dtype
=
np
.
float32
))
v_max
=
paddle
.
to_
variable
(
np
.
array
([
0.8
],
dtype
=
np
.
float32
))
images
=
paddle
.
to_
tensor
(
data
,
dtype
=
'float32'
)
v_min
=
paddle
.
to_
tensor
(
np
.
array
([
0.2
],
dtype
=
np
.
float32
))
v_max
=
paddle
.
to_
tensor
(
np
.
array
([
0.8
],
dtype
=
np
.
float32
))
out_1
=
paddle
.
clip
(
images
,
min
=
0.2
,
max
=
0.8
)
out_2
=
paddle
.
clip
(
images
,
min
=
0.2
,
max
=
0.9
)
...
...
python/paddle/fluid/tests/unittests/test_concat_op.py
浏览文件 @
162b4d6c
...
...
@@ -285,9 +285,9 @@ class TestConcatAPI(unittest.TestCase):
in2
=
np
.
array
([[
11
,
12
,
13
],
[
14
,
15
,
16
]])
in3
=
np
.
array
([[
21
,
22
],
[
23
,
24
]])
paddle
.
disable_static
()
x1
=
paddle
.
to_
variable
(
in1
)
x2
=
paddle
.
to_
variable
(
in2
)
x3
=
paddle
.
to_
variable
(
in3
)
x1
=
paddle
.
to_
tensor
(
in1
)
x2
=
paddle
.
to_
tensor
(
in2
)
x3
=
paddle
.
to_
tensor
(
in3
)
out1
=
fluid
.
layers
.
concat
(
input
=
[
x1
,
x2
,
x3
],
axis
=-
1
)
out2
=
paddle
.
concat
(
x
=
[
x1
,
x2
],
axis
=
0
)
np_out1
=
np
.
concatenate
([
in1
,
in2
,
in3
],
axis
=-
1
)
...
...
python/paddle/fluid/tests/unittests/test_cosine_similarity_api.py
浏览文件 @
162b4d6c
...
...
@@ -75,8 +75,8 @@ class TestCosineSimilarityAPI(unittest.TestCase):
np_x2
=
np
.
random
.
rand
(
*
shape
).
astype
(
np
.
float32
)
np_out
=
self
.
_get_numpy_out
(
np_x1
,
np_x2
,
axis
=
axis
,
eps
=
eps
)
tesnor_x1
=
paddle
.
to_
variable
(
np_x1
)
tesnor_x2
=
paddle
.
to_
variable
(
np_x2
)
tesnor_x1
=
paddle
.
to_
tensor
(
np_x1
)
tesnor_x2
=
paddle
.
to_
tensor
(
np_x2
)
y
=
F
.
cosine_similarity
(
tesnor_x1
,
tesnor_x2
,
axis
=
axis
,
eps
=
eps
)
self
.
assertTrue
(
np
.
allclose
(
y
.
numpy
(),
np_out
))
...
...
@@ -92,8 +92,8 @@ class TestCosineSimilarityAPI(unittest.TestCase):
np_x2
=
np
.
random
.
rand
(
*
shape
).
astype
(
np
.
float32
)
np_out
=
self
.
_get_numpy_out
(
np_x1
,
np_x2
,
axis
=
axis
,
eps
=
eps
)
tesnor_x1
=
paddle
.
to_
variable
(
np_x1
)
tesnor_x2
=
paddle
.
to_
variable
(
np_x2
)
tesnor_x1
=
paddle
.
to_
tensor
(
np_x1
)
tesnor_x2
=
paddle
.
to_
tensor
(
np_x2
)
y
=
F
.
cosine_similarity
(
tesnor_x1
,
tesnor_x2
,
axis
=
axis
,
eps
=
eps
)
self
.
assertTrue
(
np
.
allclose
(
y
.
numpy
(),
np_out
))
...
...
@@ -110,8 +110,8 @@ class TestCosineSimilarityAPI(unittest.TestCase):
np_x2
=
np
.
random
.
rand
(
*
shape2
).
astype
(
np
.
float32
)
np_out
=
self
.
_get_numpy_out
(
np_x1
,
np_x2
,
axis
=
axis
,
eps
=
eps
)
tesnor_x1
=
paddle
.
to_
variable
(
np_x1
)
tesnor_x2
=
paddle
.
to_
variable
(
np_x2
)
tesnor_x1
=
paddle
.
to_
tensor
(
np_x1
)
tesnor_x2
=
paddle
.
to_
tensor
(
np_x2
)
y
=
F
.
cosine_similarity
(
tesnor_x1
,
tesnor_x2
,
axis
=
axis
,
eps
=
eps
)
self
.
assertTrue
(
np
.
allclose
(
y
.
numpy
(),
np_out
))
...
...
@@ -129,8 +129,8 @@ class TestCosineSimilarityAPI(unittest.TestCase):
np_out
=
self
.
_get_numpy_out
(
np_x1
,
np_x2
,
axis
=
axis
,
eps
=
eps
)
cos_sim_func
=
nn
.
CosineSimilarity
(
axis
=
axis
,
eps
=
eps
)
tesnor_x1
=
paddle
.
to_
variable
(
np_x1
)
tesnor_x2
=
paddle
.
to_
variable
(
np_x2
)
tesnor_x1
=
paddle
.
to_
tensor
(
np_x1
)
tesnor_x2
=
paddle
.
to_
tensor
(
np_x2
)
y
=
cos_sim_func
(
tesnor_x1
,
tesnor_x2
)
self
.
assertTrue
(
np
.
allclose
(
y
.
numpy
(),
np_out
))
...
...
python/paddle/fluid/tests/unittests/test_cumsum_op.py
浏览文件 @
162b4d6c
...
...
@@ -21,13 +21,12 @@ import paddle
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
from
paddle
import
to_variable
class
TestCumsumOp
(
unittest
.
TestCase
):
def
run_cases
(
self
):
data_np
=
np
.
arange
(
12
).
reshape
(
3
,
4
)
data
=
to_variable
(
data_np
)
data
=
paddle
.
to_tensor
(
data_np
)
y
=
paddle
.
cumsum
(
data
)
z
=
np
.
cumsum
(
data_np
)
...
...
python/paddle/fluid/tests/unittests/test_default_dtype.py
浏览文件 @
162b4d6c
...
...
@@ -20,7 +20,6 @@ import paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph
import
Linear
import
paddle.fluid.core
as
core
from
paddle
import
to_variable
class
TestDefaultType
(
unittest
.
TestCase
):
...
...
python/paddle/fluid/tests/unittests/test_directory_migration.py
浏览文件 @
162b4d6c
...
...
@@ -36,7 +36,7 @@ class TestDirectory(unittest.TestCase):
def
test_new_directory
(
self
):
new_directory
=
[
'paddle.enable_static'
,
'paddle.disable_static'
,
'paddle.in_dynamic_mode'
,
'paddle.to_
variable
'
,
'paddle.grad'
,
'paddle.in_dynamic_mode'
,
'paddle.to_
tensor
'
,
'paddle.grad'
,
'paddle.no_grad'
,
'paddle.save'
,
'paddle.load'
,
'paddle.static.save'
,
'paddle.static.load'
,
'paddle.distributed.ParallelEnv'
,
...
...
python/paddle/fluid/tests/unittests/test_flatten_contiguous_range_op.py
浏览文件 @
162b4d6c
...
...
@@ -195,7 +195,7 @@ class TestFlattenPython(unittest.TestCase):
def
test_Negative
():
paddle
.
disable_static
()
img
=
paddle
.
to_
variable
(
x
)
img
=
paddle
.
to_
tensor
(
x
)
out
=
paddle
.
flatten
(
img
,
start_axis
=-
2
,
stop_axis
=-
1
)
return
out
.
numpy
().
shape
...
...
python/paddle/fluid/tests/unittests/test_imperative_basic.py
浏览文件 @
162b4d6c
...
...
@@ -211,7 +211,7 @@ class TestImperative(unittest.TestCase):
paddle
.
disable_static
()
self
.
assertTrue
(
paddle
.
in_dynamic_mode
())
np_inp
=
np
.
array
([[
1.0
,
2.0
],
[
3.0
,
4.0
]],
dtype
=
np
.
float32
)
var_inp
=
paddle
.
to_
variable
(
np_inp
)
var_inp
=
paddle
.
to_
tensor
(
np_inp
)
mlp
=
MLP
(
input_size
=
2
)
out
=
mlp
(
var_inp
)
dy_out1
=
out
.
numpy
()
...
...
@@ -221,7 +221,7 @@ class TestImperative(unittest.TestCase):
self
.
assertFalse
(
paddle
.
in_dynamic_mode
())
paddle
.
disable_static
()
self
.
assertTrue
(
paddle
.
in_dynamic_mode
())
var_inp
=
paddle
.
to_
variable
(
np_inp
)
var_inp
=
paddle
.
to_
tensor
(
np_inp
)
mlp
=
MLP
(
input_size
=
2
)
out
=
mlp
(
var_inp
)
dy_out2
=
out
.
numpy
()
...
...
python/paddle/fluid/tests/unittests/test_imperative_selected_rows.py
浏览文件 @
162b4d6c
...
...
@@ -54,7 +54,7 @@ class TestSimpleNet(unittest.TestCase):
# grad_clip = fluid.clip.GradientClipByGlobalNorm(5.0)
input_word
=
np
.
array
([[
1
,
2
],
[
2
,
1
]]).
astype
(
'int64'
)
input
=
paddle
.
to_
variable
(
input_word
)
input
=
paddle
.
to_
tensor
(
input_word
)
simplenet
=
SimpleNet
(
20
,
32
,
dtype
)
adam
=
SGDOptimizer
(
...
...
python/paddle/fluid/tests/unittests/test_isfinite_v2_op.py
浏览文件 @
162b4d6c
...
...
@@ -41,7 +41,7 @@ def run_dygraph(x_np, op_str, use_gpu=True):
if
use_gpu
and
fluid
.
core
.
is_compiled_with_cuda
():
place
=
paddle
.
CUDAPlace
(
0
)
paddle
.
disable_static
(
place
)
x
=
paddle
.
to_
variable
(
x_np
)
x
=
paddle
.
to_
tensor
(
x_np
)
dygraph_result
=
getattr
(
paddle
.
tensor
,
op_str
)(
x
)
return
dygraph_result
...
...
python/paddle/fluid/tests/unittests/test_jit_save_load.py
浏览文件 @
162b4d6c
...
...
@@ -543,9 +543,9 @@ class TestJitSaveMultiCases(unittest.TestCase):
loaded_layer
=
paddle
.
jit
.
load
(
model_path
)
loaded_layer
.
eval
()
# inference & compare
x
=
paddle
.
to_
variable
(
np
.
random
.
random
((
1
,
784
)).
astype
(
'float32'
))
x
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
1
,
784
)).
astype
(
'float32'
))
if
with_label
:
y
=
paddle
.
to_
variable
(
np
.
random
.
random
((
1
,
1
)).
astype
(
'int64'
))
y
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
1
,
1
)).
astype
(
'int64'
))
pred
,
_
=
layer
(
x
,
y
)
pred
=
pred
.
numpy
()
else
:
...
...
@@ -677,7 +677,7 @@ class TestJitSaveMultiCases(unittest.TestCase):
model_path
=
"test_not_prune_output_spec_name_warning"
configs
=
paddle
.
SaveLoadConfig
()
out
=
paddle
.
to_
variable
(
np
.
random
.
random
((
1
,
1
)).
astype
(
'float'
))
out
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
1
,
1
)).
astype
(
'float'
))
configs
.
output_spec
=
[
out
]
paddle
.
jit
.
save
(
layer
,
model_path
,
configs
=
configs
)
...
...
@@ -709,7 +709,7 @@ class TestJitSaveMultiCases(unittest.TestCase):
model_path
=
"test_prune_to_static_after_train"
configs
=
paddle
.
SaveLoadConfig
()
out
=
paddle
.
to_
variable
(
np
.
random
.
random
((
1
,
1
)).
astype
(
'float'
))
out
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
1
,
1
)).
astype
(
'float'
))
configs
.
output_spec
=
[
out
]
with
self
.
assertRaises
(
ValueError
):
paddle
.
jit
.
save
(
...
...
@@ -730,7 +730,7 @@ class TestJitSaveLoadEmptyLayer(unittest.TestCase):
def
test_save_load_empty_layer
(
self
):
layer
=
EmptyLayer
()
x
=
paddle
.
to_
variable
(
np
.
random
.
random
((
10
)).
astype
(
'float32'
))
x
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
10
)).
astype
(
'float32'
))
out
=
layer
(
x
)
paddle
.
jit
.
save
(
layer
,
self
.
model_path
)
load_layer
=
paddle
.
jit
.
load
(
self
.
model_path
)
...
...
@@ -746,8 +746,8 @@ class TestJitSaveLoadNoParamLayer(unittest.TestCase):
def
test_save_load_no_param_layer
(
self
):
layer
=
NoParamLayer
()
x
=
paddle
.
to_
variable
(
np
.
random
.
random
((
5
)).
astype
(
'float32'
))
y
=
paddle
.
to_
variable
(
np
.
random
.
random
((
5
)).
astype
(
'float32'
))
x
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
5
)).
astype
(
'float32'
))
y
=
paddle
.
to_
tensor
(
np
.
random
.
random
((
5
)).
astype
(
'float32'
))
out
=
layer
(
x
,
y
)
paddle
.
jit
.
save
(
layer
,
self
.
model_path
)
load_layer
=
paddle
.
jit
.
load
(
self
.
model_path
)
...
...
python/paddle/fluid/tests/unittests/test_kldiv_loss_op.py
浏览文件 @
162b4d6c
...
...
@@ -90,7 +90,7 @@ class TestKLDivLossDygraph(unittest.TestCase):
with
paddle
.
fluid
.
dygraph
.
guard
():
kldiv_criterion
=
paddle
.
nn
.
KLDivLoss
(
reduction
)
pred_loss
=
kldiv_criterion
(
paddle
.
to_
variable
(
x
),
paddle
.
to_variable
(
target
))
paddle
.
to_
tensor
(
x
),
paddle
.
to_tensor
(
target
))
self
.
assertTrue
(
np
.
allclose
(
pred_loss
.
numpy
(),
gt_loss
))
def
test_kl_loss_batchmean
(
self
):
...
...
python/paddle/fluid/tests/unittests/test_l1_loss.py
浏览文件 @
162b4d6c
...
...
@@ -26,8 +26,8 @@ class TestFunctionalL1Loss(unittest.TestCase):
self
.
label_np
=
np
.
random
.
random
(
size
=
(
10
,
10
,
5
)).
astype
(
np
.
float32
)
def
run_imperative
(
self
):
input
=
paddle
.
to_
variable
(
self
.
input_np
)
label
=
paddle
.
to_
variable
(
self
.
label_np
)
input
=
paddle
.
to_
tensor
(
self
.
input_np
)
label
=
paddle
.
to_
tensor
(
self
.
label_np
)
dy_result
=
paddle
.
nn
.
functional
.
l1_loss
(
input
,
label
)
expected
=
np
.
mean
(
np
.
abs
(
self
.
input_np
-
self
.
label_np
))
self
.
assertTrue
(
np
.
allclose
(
dy_result
.
numpy
(),
expected
))
...
...
@@ -106,8 +106,8 @@ class TestClassL1Loss(unittest.TestCase):
self
.
label_np
=
np
.
random
.
random
(
size
=
(
10
,
10
,
5
)).
astype
(
np
.
float32
)
def
run_imperative
(
self
):
input
=
paddle
.
to_
variable
(
self
.
input_np
)
label
=
paddle
.
to_
variable
(
self
.
label_np
)
input
=
paddle
.
to_
tensor
(
self
.
input_np
)
label
=
paddle
.
to_
tensor
(
self
.
label_np
)
l1_loss
=
paddle
.
nn
.
loss
.
L1Loss
()
dy_result
=
l1_loss
(
input
,
label
)
expected
=
np
.
mean
(
np
.
abs
(
self
.
input_np
-
self
.
label_np
))
...
...
python/paddle/fluid/tests/unittests/test_log_softmax.py
浏览文件 @
162b4d6c
...
...
@@ -96,7 +96,7 @@ class TestNNLogSoftmaxAPI(unittest.TestCase):
# test dygrapg api
paddle
.
disable_static
()
x
=
paddle
.
to_
variable
(
self
.
x
)
x
=
paddle
.
to_
tensor
(
self
.
x
)
y
=
logsoftmax
(
x
)
self
.
assertTrue
(
np
.
allclose
(
y
.
numpy
(),
ref_out
))
paddle
.
enable_static
()
...
...
@@ -127,7 +127,7 @@ class TestNNFunctionalLogSoftmaxAPI(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
out
[
0
],
ref_out
))
paddle
.
disable_static
()
x
=
paddle
.
to_
variable
(
self
.
x
)
x
=
paddle
.
to_
tensor
(
self
.
x
)
y
=
F
.
log_softmax
(
x
,
axis
,
dtype
)
self
.
assertTrue
(
np
.
allclose
(
y
.
numpy
(),
ref_out
),
True
)
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_logsumexp.py
浏览文件 @
162b4d6c
...
...
@@ -111,7 +111,7 @@ class TestLogsumexpAPI(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
res
[
0
],
out_ref
))
paddle
.
disable_static
(
self
.
place
)
x
=
paddle
.
to_
variable
(
self
.
x
)
x
=
paddle
.
to_
tensor
(
self
.
x
)
out
=
paddle
.
logsumexp
(
x
,
axis
,
keepdim
)
self
.
assertTrue
(
np
.
allclose
(
out
.
numpy
(),
out_ref
))
paddle
.
enable_static
()
...
...
@@ -126,7 +126,7 @@ class TestLogsumexpAPI(unittest.TestCase):
def
test_alias
(
self
):
paddle
.
disable_static
(
self
.
place
)
x
=
paddle
.
to_
variable
(
self
.
x
)
x
=
paddle
.
to_
tensor
(
self
.
x
)
out1
=
paddle
.
logsumexp
(
x
)
out2
=
paddle
.
tensor
.
logsumexp
(
x
)
out3
=
paddle
.
tensor
.
math
.
logsumexp
(
x
)
...
...
python/paddle/fluid/tests/unittests/test_max_op.py
浏览文件 @
162b4d6c
...
...
@@ -80,7 +80,7 @@ class ApiMaxTest(unittest.TestCase):
def
test_imperative_api
(
self
):
paddle
.
disable_static
()
np_x
=
np
.
array
([
10
,
10
]).
astype
(
'float64'
)
x
=
paddle
.
to_
variable
(
np_x
)
x
=
paddle
.
to_
tensor
(
np_x
)
z
=
paddle
.
max
(
x
,
axis
=
0
)
np_z
=
z
.
numpy
()
z_expected
=
np
.
array
(
np
.
max
(
np_x
,
axis
=
0
))
...
...
python/paddle/fluid/tests/unittests/test_maximum_op.py
浏览文件 @
162b4d6c
...
...
@@ -61,8 +61,8 @@ class ApiMaximumTest(unittest.TestCase):
def
test_dynamic_api
(
self
):
paddle
.
disable_static
()
np_x
=
np
.
array
([
10
,
10
]).
astype
(
'float64'
)
x
=
paddle
.
to_
variable
(
self
.
input_x
)
y
=
paddle
.
to_
variable
(
self
.
input_y
)
x
=
paddle
.
to_
tensor
(
self
.
input_x
)
y
=
paddle
.
to_
tensor
(
self
.
input_y
)
z
=
paddle
.
maximum
(
x
,
y
)
np_z
=
z
.
numpy
()
z_expected
=
np
.
array
(
np
.
maximum
(
self
.
input_x
,
self
.
input_y
))
...
...
@@ -73,8 +73,8 @@ class ApiMaximumTest(unittest.TestCase):
np_x
=
np
.
random
.
rand
(
5
,
4
,
3
,
2
).
astype
(
"float64"
)
np_y
=
np
.
random
.
rand
(
4
,
3
).
astype
(
"float64"
)
x
=
paddle
.
to_
variable
(
self
.
input_x
)
y
=
paddle
.
to_
variable
(
self
.
input_y
)
x
=
paddle
.
to_
tensor
(
self
.
input_x
)
y
=
paddle
.
to_
tensor
(
self
.
input_y
)
result_1
=
paddle
.
maximum
(
x
,
y
,
axis
=
1
)
result_2
=
paddle
.
maximum
(
x
,
y
,
axis
=-
2
)
self
.
assertEqual
((
result_1
.
numpy
()
==
result_2
.
numpy
()).
all
(),
True
)
python/paddle/fluid/tests/unittests/test_mean_op.py
浏览文件 @
162b4d6c
...
...
@@ -204,7 +204,7 @@ class TestMeanAPI(unittest.TestCase):
paddle
.
disable_static
(
self
.
place
)
def
test_case
(
x
,
axis
=
None
,
keepdim
=
False
):
x_tensor
=
paddle
.
to_
variable
(
x
)
x_tensor
=
paddle
.
to_
tensor
(
x
)
out
=
paddle
.
mean
(
x_tensor
,
axis
,
keepdim
)
if
isinstance
(
axis
,
list
):
axis
=
tuple
(
axis
)
...
...
python/paddle/fluid/tests/unittests/test_min_op.py
浏览文件 @
162b4d6c
...
...
@@ -80,7 +80,7 @@ class ApiMinTest(unittest.TestCase):
def
test_imperative_api
(
self
):
paddle
.
disable_static
()
np_x
=
np
.
array
([
10
,
10
]).
astype
(
'float64'
)
x
=
paddle
.
to_
variable
(
np_x
)
x
=
paddle
.
to_
tensor
(
np_x
)
z
=
paddle
.
min
(
x
,
axis
=
0
)
np_z
=
z
.
numpy
()
z_expected
=
np
.
array
(
np
.
min
(
np_x
,
axis
=
0
))
...
...
python/paddle/fluid/tests/unittests/test_randn_op.py
浏览文件 @
162b4d6c
...
...
@@ -63,7 +63,7 @@ class TestRandnOpForDygraph(unittest.TestCase):
dim_2
=
paddle
.
fill_constant
([
1
],
"int32"
,
50
)
x3
=
paddle
.
randn
(
shape
=
[
dim_1
,
dim_2
,
784
])
var_shape
=
paddle
.
to_
variable
(
np
.
array
(
shape
))
var_shape
=
paddle
.
to_
tensor
(
np
.
array
(
shape
))
x4
=
paddle
.
randn
(
var_shape
)
for
out
in
[
x1
,
x2
,
x3
,
x4
]:
...
...
python/paddle/fluid/tests/unittests/test_retain_graph.py
浏览文件 @
162b4d6c
...
...
@@ -105,8 +105,8 @@ class TestRetainGraph(unittest.TestCase):
A
=
np
.
random
.
rand
(
2
,
3
,
32
,
32
).
astype
(
'float32'
)
B
=
np
.
random
.
rand
(
2
,
3
,
32
,
32
).
astype
(
'float32'
)
realA
=
paddle
.
to_
variable
(
A
)
realB
=
paddle
.
to_
variable
(
B
)
realA
=
paddle
.
to_
tensor
(
A
)
realB
=
paddle
.
to_
tensor
(
B
)
fakeB
=
g
(
realA
)
optim_d
.
clear_gradients
()
...
...
python/paddle/fluid/tests/unittests/test_transformer_api.py
浏览文件 @
162b4d6c
...
...
@@ -487,24 +487,24 @@ class TestTransformer(unittest.TestCase):
dropout
=
dropout
,
weight_attr
=
[
None
],
bias_attr
=
[
False
])
src
=
paddle
.
to_
variable
(
src
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
source_length
,
d_model
).
astype
(
"float32"
))
tgt
=
paddle
.
to_
variable
(
tgt
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
target_length
,
d_model
).
astype
(
"float32"
))
src_mask
=
np
.
zeros
((
batch_size
,
n_head
,
source_length
,
source_length
)).
astype
(
"float32"
)
src_mask
[
0
][
0
][
0
][
0
]
=
-
np
.
inf
src_mask
=
paddle
.
to_
variable
(
src_mask
)
src_mask
=
paddle
.
to_
tensor
(
src_mask
)
tgt_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
target_length
)).
astype
(
"float32"
)
tgt_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
memory_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
source_length
)).
astype
(
"float32"
)
memory_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
tgt_mask
,
memory_mask
=
paddle
.
to_
variable
(
tgt_mask
),
paddle
.
to_
variable
(
memory_mask
)
tgt_mask
,
memory_mask
=
paddle
.
to_
tensor
(
tgt_mask
),
paddle
.
to_
tensor
(
memory_mask
)
trans_output
=
transformer
(
src
,
tgt
,
src_mask
,
tgt_mask
,
memory_mask
)
...
...
@@ -521,24 +521,24 @@ class TestTransformer(unittest.TestCase):
dropout
=
dropout
,
weight_attr
=
[
None
,
None
],
bias_attr
=
[
False
,
False
])
src
=
paddle
.
to_
variable
(
src
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
source_length
,
d_model
).
astype
(
"float32"
))
tgt
=
paddle
.
to_
variable
(
tgt
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
target_length
,
d_model
).
astype
(
"float32"
))
src_mask
=
np
.
zeros
((
batch_size
,
n_head
,
source_length
,
source_length
)).
astype
(
"float32"
)
src_mask
[
0
][
0
][
0
][
0
]
=
-
np
.
inf
src_mask
=
paddle
.
to_
variable
(
src_mask
)
src_mask
=
paddle
.
to_
tensor
(
src_mask
)
tgt_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
target_length
)).
astype
(
"float32"
)
tgt_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
memory_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
source_length
)).
astype
(
"float32"
)
memory_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
tgt_mask
,
memory_mask
=
paddle
.
to_
variable
(
tgt_mask
),
paddle
.
to_
variable
(
memory_mask
)
tgt_mask
,
memory_mask
=
paddle
.
to_
tensor
(
tgt_mask
),
paddle
.
to_
tensor
(
memory_mask
)
trans_output
=
transformer
(
src
,
tgt
,
src_mask
,
tgt_mask
,
memory_mask
)
...
...
@@ -555,24 +555,24 @@ class TestTransformer(unittest.TestCase):
dropout
=
dropout
,
weight_attr
=
[
None
,
None
,
None
],
bias_attr
=
[
False
,
False
,
True
])
src
=
paddle
.
to_
variable
(
src
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
source_length
,
d_model
).
astype
(
"float32"
))
tgt
=
paddle
.
to_
variable
(
tgt
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
target_length
,
d_model
).
astype
(
"float32"
))
src_mask
=
np
.
zeros
((
batch_size
,
n_head
,
source_length
,
source_length
)).
astype
(
"float32"
)
src_mask
[
0
][
0
][
0
][
0
]
=
-
np
.
inf
src_mask
=
paddle
.
to_
variable
(
src_mask
)
src_mask
=
paddle
.
to_
tensor
(
src_mask
)
tgt_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
target_length
)).
astype
(
"float32"
)
tgt_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
memory_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
source_length
)).
astype
(
"float32"
)
memory_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
tgt_mask
,
memory_mask
=
paddle
.
to_
variable
(
tgt_mask
),
paddle
.
to_
variable
(
memory_mask
)
tgt_mask
,
memory_mask
=
paddle
.
to_
tensor
(
tgt_mask
),
paddle
.
to_
tensor
(
memory_mask
)
trans_output
=
transformer
(
src
,
tgt
,
src_mask
,
tgt_mask
,
memory_mask
)
...
...
@@ -588,24 +588,24 @@ class TestTransformer(unittest.TestCase):
dim_feedforward
=
dim_feedforward
,
dropout
=
dropout
,
bias_attr
=
False
)
src
=
paddle
.
to_
variable
(
src
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
source_length
,
d_model
).
astype
(
"float32"
))
tgt
=
paddle
.
to_
variable
(
tgt
=
paddle
.
to_
tensor
(
np
.
random
.
rand
(
batch_size
,
target_length
,
d_model
).
astype
(
"float32"
))
src_mask
=
np
.
zeros
((
batch_size
,
n_head
,
source_length
,
source_length
)).
astype
(
"float32"
)
src_mask
[
0
][
0
][
0
][
0
]
=
-
np
.
inf
src_mask
=
paddle
.
to_
variable
(
src_mask
)
src_mask
=
paddle
.
to_
tensor
(
src_mask
)
tgt_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
target_length
)).
astype
(
"float32"
)
tgt_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
memory_mask
=
np
.
zeros
((
batch_size
,
n_head
,
target_length
,
source_length
)).
astype
(
"float32"
)
memory_mask
[
0
][
0
][
0
][
0
]
=
-
1e9
tgt_mask
,
memory_mask
=
paddle
.
to_
variable
(
tgt_mask
),
paddle
.
to_
variable
(
memory_mask
)
tgt_mask
,
memory_mask
=
paddle
.
to_
tensor
(
tgt_mask
),
paddle
.
to_
tensor
(
memory_mask
)
trans_output
=
transformer
(
src
,
tgt
,
src_mask
,
tgt_mask
,
memory_mask
)
...
...
python/paddle/fluid/tests/unittests/test_zeros_like_op.py
浏览文件 @
162b4d6c
...
...
@@ -63,7 +63,7 @@ class TestZerosLikeImpeartive(unittest.TestCase):
place
=
fluid
.
CUDAPlace
(
0
)
if
core
.
is_compiled_with_cuda
(
)
else
fluid
.
CPUPlace
()
paddle
.
disable_static
(
place
)
x
=
paddle
.
to_
variable
(
np
.
ones
(
shape
))
x
=
paddle
.
to_
tensor
(
np
.
ones
(
shape
))
for
dtype
in
[
np
.
bool
,
np
.
float32
,
np
.
float64
,
np
.
int32
,
np
.
int64
]:
out
=
zeros_like
(
x
,
dtype
)
self
.
assertEqual
((
out
.
numpy
()
==
np
.
zeros
(
shape
,
dtype
)).
all
(),
...
...
python/paddle/tensor/linalg.py
浏览文件 @
162b4d6c
...
...
@@ -707,20 +707,14 @@ def cross(x, y, axis=None, name=None):
Examples:
.. code-block:: python
import paddle
from paddle import to_variable
import numpy as np
paddle.disable_static()
data_x = np.array
([[1.0, 1.0, 1.0],
x = paddle.to_tensor
([[1.0, 1.0, 1.0],
[2.0, 2.0, 2.0],
[3.0, 3.0, 3.0]])
data_y = np.array
([[1.0, 1.0, 1.0],
y = paddle.to_tensor
([[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0]])
x = to_variable(data_x)
y = to_variable(data_y)
z1 = paddle.cross(x, y)
print(z1.numpy())
# [[-1. -1. -1.]
...
...
python/paddle/tensor/math.py
浏览文件 @
162b4d6c
...
...
@@ -1650,12 +1650,11 @@ def cumsum(x, axis=None, dtype=None, name=None):
.. code-block:: python
import paddle
from paddle import to_variable
import numpy as np
paddle.disable_static()
data_np = np.arange(12).reshape(3, 4)
data =
to_variable
(data_np)
data =
paddle.to_tensor
(data_np)
y = paddle.cumsum(data)
print(y.numpy())
...
...
tools/wlist.json
浏览文件 @
162b4d6c
...
...
@@ -251,9 +251,10 @@
"BilinearTensorProduct"
,
"GroupNorm"
,
"SpectralNorm"
,
"TreeConv"
,
"TreeConv"
],
"wlist_temp"
:[
"prroi_pool"
,
"to_tensor"
,
"ChunkEvaluator"
,
"EditDistance"
,
"ErrorClipByValue"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录