Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7fc25f22
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2297
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7fc25f22
编写于
12月 19, 2022
作者:
姜
姜永久
提交者:
GitHub
12月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Yj/rm imperative dygraph eager tests (#48782)
* rm imperative op eager guard tests * modify varbase patch eager guard doc
上级
afeb394e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
28 addition
and
75 deletion
+28
-75
python/paddle/fluid/contrib/slim/tests/test_imperative_out_scale.py
...dle/fluid/contrib/slim/tests/test_imperative_out_scale.py
+2
-7
python/paddle/fluid/contrib/slim/tests/test_imperative_ptq.py
...on/paddle/fluid/contrib/slim/tests/test_imperative_ptq.py
+2
-13
python/paddle/fluid/contrib/slim/tests/test_imperative_qat.py
...on/paddle/fluid/contrib/slim/tests/test_imperative_qat.py
+1
-7
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_amp.py
...addle/fluid/contrib/slim/tests/test_imperative_qat_amp.py
+1
-7
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_lsq.py
...addle/fluid/contrib/slim/tests/test_imperative_qat_lsq.py
+0
-1
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_user_defined.py
...id/contrib/slim/tests/test_imperative_qat_user_defined.py
+1
-7
python/paddle/fluid/contrib/slim/tests/test_imperative_skip_op.py
...addle/fluid/contrib/slim/tests/test_imperative_skip_op.py
+1
-7
python/paddle/fluid/dygraph/varbase_patch_methods.py
python/paddle/fluid/dygraph/varbase_patch_methods.py
+20
-26
未找到文件。
python/paddle/fluid/contrib/slim/tests/test_imperative_out_scale.py
浏览文件 @
7fc25f22
...
...
@@ -25,7 +25,7 @@ import paddle.fluid as fluid
import
paddle.fluid.layers
as
layers
from
paddle.fluid
import
core
from
paddle.fluid.optimizer
import
AdamOptimizer
from
paddle.fluid.framework
import
IrGraph
,
_test_eager_guard
from
paddle.fluid.framework
import
IrGraph
from
paddle.fluid.contrib.slim.quantization
import
ImperativeQuantAware
from
paddle.nn
import
Sequential
from
paddle.jit.translated_layer
import
INFER_MODEL_SUFFIX
,
INFER_PARAMS_SUFFIX
...
...
@@ -139,7 +139,7 @@ class TestImperativeOutSclae(unittest.TestCase):
def
tearDown
(
self
):
self
.
root_path
.
cleanup
()
def
func
_out_scale_acc
(
self
):
def
test
_out_scale_acc
(
self
):
seed
=
1000
lr
=
0.001
...
...
@@ -208,11 +208,6 @@ class TestImperativeOutSclae(unittest.TestCase):
msg
=
'Failed to do the imperative qat.'
,
)
def
test_out_scale_acc
(
self
):
with
_test_eager_guard
():
self
.
func_out_scale_acc
()
self
.
func_out_scale_acc
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/contrib/slim/tests/test_imperative_ptq.py
浏览文件 @
7fc25f22
...
...
@@ -28,7 +28,6 @@ import paddle.fluid as fluid
from
paddle.fluid.contrib.slim.quantization
import
*
from
paddle.fluid.log_helper
import
get_logger
from
paddle.dataset.common
import
download
from
paddle.fluid.framework
import
_test_eager_guard
from
imperative_test_utils
import
(
fix_model_dict
,
...
...
@@ -208,7 +207,7 @@ class TestImperativePTQ(unittest.TestCase):
break
return
top1_correct_num
/
total_num
def
func
_ptq
(
self
):
def
test
_ptq
(
self
):
start_time
=
time
.
time
()
self
.
set_vars
()
...
...
@@ -266,14 +265,9 @@ class TestImperativePTQ(unittest.TestCase):
end_time
=
time
.
time
()
print
(
"total time: %ss
\n
"
%
(
end_time
-
start_time
))
def
test_ptq
(
self
):
with
_test_eager_guard
():
self
.
func_ptq
()
self
.
func_ptq
()
class
TestImperativePTQfuse
(
TestImperativePTQ
):
def
func
_ptq
(
self
):
def
test
_ptq
(
self
):
start_time
=
time
.
time
()
self
.
set_vars
()
...
...
@@ -342,11 +336,6 @@ class TestImperativePTQfuse(TestImperativePTQ):
end_time
=
time
.
time
()
print
(
"total time: %ss
\n
"
%
(
end_time
-
start_time
))
def
test_ptq
(
self
):
with
_test_eager_guard
():
self
.
func_ptq
()
self
.
func_ptq
()
class
TestImperativePTQHist
(
TestImperativePTQ
):
def
set_vars
(
self
):
...
...
python/paddle/fluid/contrib/slim/tests/test_imperative_qat.py
浏览文件 @
7fc25f22
...
...
@@ -33,7 +33,6 @@ from paddle.nn.quant.quant_layers import (
QuantizedConv2D
,
QuantizedConv2DTranspose
,
)
from
paddle.fluid.framework
import
_test_eager_guard
from
imperative_test_utils
import
fix_model_dict
,
ImperativeLenet
paddle
.
enable_static
()
...
...
@@ -63,7 +62,7 @@ class TestImperativeQat(unittest.TestCase):
self
.
diff_threshold
=
0.03125
self
.
fuse_conv_bn
=
False
def
func
_qat
(
self
):
def
test
_qat
(
self
):
self
.
set_vars
()
imperative_qat
=
ImperativeQuantAware
(
...
...
@@ -244,11 +243,6 @@ class TestImperativeQat(unittest.TestCase):
delta_value
=
fp32_acc
-
quant_acc
self
.
assertLessEqual
(
delta_value
,
self
.
diff_threshold
)
def
test_qat
(
self
):
with
_test_eager_guard
():
self
.
func_qat
()
self
.
func_qat
()
class
TestImperativeQatONNXFormat
(
unittest
.
TestCase
):
def
set_vars
(
self
):
...
...
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_amp.py
浏览文件 @
7fc25f22
...
...
@@ -26,7 +26,6 @@ import paddle.fluid as fluid
from
paddle.fluid.contrib.slim.quantization
import
ImperativeQuantAware
from
paddle.fluid.log_helper
import
get_logger
from
paddle.dataset.common
import
download
from
paddle.fluid.framework
import
_test_eager_guard
from
imperative_test_utils
import
fix_model_dict
,
ImperativeLenet
os
.
environ
[
"CPU_NUM"
]
=
"1"
...
...
@@ -188,7 +187,7 @@ class TestImperativeQatAmp(unittest.TestCase):
acc_top1
=
sum
(
acc_top1_list
)
/
len
(
acc_top1_list
)
return
acc_top1
def
ptq
(
self
):
def
test_
ptq
(
self
):
start_time
=
time
.
time
()
self
.
set_vars
()
...
...
@@ -239,11 +238,6 @@ class TestImperativeQatAmp(unittest.TestCase):
end_time
=
time
.
time
()
print
(
"total time: %ss"
%
(
end_time
-
start_time
))
def
test_ptq
(
self
):
self
.
ptq
()
with
_test_eager_guard
():
self
.
ptq
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_lsq.py
浏览文件 @
7fc25f22
...
...
@@ -38,7 +38,6 @@ from paddle.nn.quant.quant_layers import (
QuantizedConv2D
,
QuantizedConv2DTranspose
,
)
from
paddle.fluid.framework
import
_test_eager_guard
from
imperative_test_utils
import
fix_model_dict
paddle
.
enable_static
()
...
...
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_user_defined.py
浏览文件 @
7fc25f22
...
...
@@ -26,7 +26,6 @@ from paddle.nn import Sequential
from
paddle.nn
import
Linear
from
paddle.nn.quant.quant_layers
import
QuantizedConv2DTranspose
from
paddle.fluid.log_helper
import
get_logger
from
paddle.fluid.framework
import
_test_eager_guard
os
.
environ
[
"CPU_NUM"
]
=
"1"
...
...
@@ -161,7 +160,7 @@ class TestUserDefinedActPreprocess(unittest.TestCase):
_logger
.
info
(
"test act_preprocess"
)
self
.
imperative_qat
=
ImperativeQuantAware
(
act_preprocess_layer
=
PACT
)
def
func
_quant_aware_training
(
self
):
def
test
_quant_aware_training
(
self
):
imperative_qat
=
self
.
imperative_qat
seed
=
1
np
.
random
.
seed
(
seed
)
...
...
@@ -263,11 +262,6 @@ class TestUserDefinedActPreprocess(unittest.TestCase):
train
(
lenet
)
test
(
lenet
)
def
test_quant_aware_training
(
self
):
with
_test_eager_guard
():
self
.
func_quant_aware_training
()
self
.
func_quant_aware_training
()
class
TestUserDefinedWeightPreprocess
(
TestUserDefinedActPreprocess
):
def
setUp
(
self
):
...
...
python/paddle/fluid/contrib/slim/tests/test_imperative_skip_op.py
浏览文件 @
7fc25f22
...
...
@@ -33,7 +33,6 @@ from imperative_test_utils import (
train_lenet
,
ImperativeLenetWithSkipQuant
,
)
from
paddle.fluid.framework
import
_test_eager_guard
os
.
environ
[
"CPU_NUM"
]
=
"1"
if
core
.
is_compiled_with_cuda
():
...
...
@@ -45,7 +44,7 @@ _logger = get_logger(
class
TestImperativeOutSclae
(
unittest
.
TestCase
):
def
func
_out_scale_acc
(
self
):
def
test
_out_scale_acc
(
self
):
paddle
.
disable_static
()
seed
=
1000
lr
=
0.1
...
...
@@ -141,11 +140,6 @@ class TestImperativeOutSclae(unittest.TestCase):
if
find_matmul
:
self
.
assertTrue
(
matmul_skip_count
==
1
)
def
test_out_scale_acc
(
self
):
with
_test_eager_guard
():
self
.
func_out_scale_acc
()
self
.
func_out_scale_acc
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/dygraph/varbase_patch_methods.py
浏览文件 @
7fc25f22
...
...
@@ -965,14 +965,12 @@ def monkey_patch_varbase():
.. code-block:: python
import paddle
from paddle.fluid.framework import _test_eager_guard
with _test_eager_guard():
indices = [[0, 0, 1, 2, 2], [1, 3, 2, 0, 1]]
values = [1, 2, 3, 4, 5]
dense_shape = [3, 4]
sparse_x = paddle.sparse.sparse_coo_tensor(paddle.to_tensor(indices, dtype='int32'), paddle.to_tensor(values, dtype='float32'), shape=dense_shape)
print(sparse_x.values())
#[1, 2, 3, 4, 5]
indices = [[0, 0, 1, 2, 2], [1, 3, 2, 0, 1]]
values = [1, 2, 3, 4, 5]
dense_shape = [3, 4]
sparse_x = paddle.sparse.sparse_coo_tensor(paddle.to_tensor(indices, dtype='int32'), paddle.to_tensor(values, dtype='float32'), shape=dense_shape)
print(sparse_x.values())
#[1, 2, 3, 4, 5]
"""
return
_C_ops
.
sparse_values
(
self
)
...
...
@@ -990,16 +988,14 @@ def monkey_patch_varbase():
.. code-block:: python
import paddle
from paddle.fluid.framework import _test_eager_guard
with _test_eager_guard():
indices = [[0, 0, 1, 2, 2], [1, 3, 2, 0, 1]]
values = [1, 2, 3, 4, 5]
dense_shape = [3, 4]
sparse_x = paddle.sparse.sparse_coo_tensor(paddle.to_tensor(indices, dtype='int64'), paddle.to_tensor(values, dtype='float32'), shape=dense_shape)
dense_x = sparse_x.to_dense()
#[[0., 1., 0., 2.],
# [0., 0., 3., 0.],
# [4., 5., 0., 0.]]
indices = [[0, 0, 1, 2, 2], [1, 3, 2, 0, 1]]
values = [1, 2, 3, 4, 5]
dense_shape = [3, 4]
sparse_x = paddle.sparse.sparse_coo_tensor(paddle.to_tensor(indices, dtype='int64'), paddle.to_tensor(values, dtype='float32'), shape=dense_shape)
dense_x = sparse_x.to_dense()
#[[0., 1., 0., 2.],
# [0., 0., 3., 0.],
# [4., 5., 0., 0.]]
"""
return
_C_ops
.
sparse_to_dense
(
self
)
...
...
@@ -1018,14 +1014,12 @@ def monkey_patch_varbase():
.. code-block:: python
import paddle
from paddle.fluid.framework import _test_eager_guard
with _test_eager_guard():
dense_x = [[0, 1, 0, 2], [0, 0, 3, 4]]
dense_x = paddle.to_tensor(dense_x, dtype='float32')
sparse_x = dense_x.to_sparse_coo(sparse_dim=2)
#indices=[[0, 0, 1, 1],
# [1, 3, 2, 3]],
#values=[1., 2., 3., 4.]
dense_x = [[0, 1, 0, 2], [0, 0, 3, 4]]
dense_x = paddle.to_tensor(dense_x, dtype='float32')
sparse_x = dense_x.to_sparse_coo(sparse_dim=2)
#indices=[[0, 0, 1, 1],
# [1, 3, 2, 3]],
#values=[1., 2., 3., 4.]
"""
return
_C_ops
.
sparse_to_sparse_coo
(
self
,
sparse_dim
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录