Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5675c7d5
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
5675c7d5
编写于
11月 20, 2022
作者:
C
ccrrong
提交者:
GitHub
11月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove range from fluid (#48086)
* remove range
上级
f38e09f0
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
11 addition
and
114 deletion
+11
-114
python/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py
...ddle/fluid/dygraph/dygraph_to_static/convert_operators.py
+4
-5
python/paddle/fluid/layers/rnn.py
python/paddle/fluid/layers/rnn.py
+1
-1
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+0
-103
python/paddle/fluid/tests/unittests/test_dynamic_rnn_stop_gradient.py
...e/fluid/tests/unittests/test_dynamic_rnn_stop_gradient.py
+2
-1
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+4
-4
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py
浏览文件 @
5675c7d5
...
@@ -20,7 +20,6 @@ from paddle.fluid.dygraph.dygraph_to_static.variable_trans_func import (
...
@@ -20,7 +20,6 @@ from paddle.fluid.dygraph.dygraph_to_static.variable_trans_func import (
)
)
from
paddle.fluid.framework
import
core
,
Variable
from
paddle.fluid.framework
import
core
,
Variable
from
paddle.fluid.layers
import
Assert
,
Print
from
paddle.fluid.layers
import
Assert
,
Print
from
paddle.fluid.layers
import
range
as
paddle_range
from
paddle.fluid.layers
import
(
from
paddle.fluid.layers
import
(
array_length
,
array_length
,
array_read
,
array_read
,
...
@@ -570,7 +569,7 @@ class VariableTuple:
...
@@ -570,7 +569,7 @@ class VariableTuple:
self
.
var
=
var
self
.
var
=
var
self
.
len
=
convert_len
(
var
)
self
.
len
=
convert_len
(
var
)
if
isinstance
(
self
.
len
,
Variable
):
if
isinstance
(
self
.
len
,
Variable
):
self
.
rag
=
paddle
_
range
(
start
,
start
+
self
.
len
,
1
,
paddle
.
int64
)
self
.
rag
=
paddle
.
a
range
(
start
,
start
+
self
.
len
,
1
,
paddle
.
int64
)
else
:
else
:
self
.
rag
=
range
(
start
,
start
+
self
.
len
)
self
.
rag
=
range
(
start
,
start
+
self
.
len
)
...
@@ -592,11 +591,11 @@ def convert_range(*args):
...
@@ -592,11 +591,11 @@ def convert_range(*args):
has_variable
=
any
(
map
(
lambda
x
:
isinstance
(
x
,
Variable
),
args
))
has_variable
=
any
(
map
(
lambda
x
:
isinstance
(
x
,
Variable
),
args
))
if
has_variable
:
if
has_variable
:
if
len
(
args
)
==
1
:
if
len
(
args
)
==
1
:
return
paddle
_
range
(
0
,
args
[
0
],
1
,
paddle
.
int64
)
return
paddle
.
a
range
(
0
,
args
[
0
],
1
,
paddle
.
int64
)
if
len
(
args
)
==
2
:
if
len
(
args
)
==
2
:
return
paddle
_
range
(
args
[
0
],
args
[
1
],
1
,
paddle
.
int64
)
return
paddle
.
a
range
(
args
[
0
],
args
[
1
],
1
,
paddle
.
int64
)
if
len
(
args
)
==
3
:
if
len
(
args
)
==
3
:
return
paddle
_
range
(
args
[
0
],
args
[
1
],
args
[
2
],
paddle
.
int64
)
return
paddle
.
a
range
(
args
[
0
],
args
[
1
],
args
[
2
],
paddle
.
int64
)
return
range
(
*
args
)
return
range
(
*
args
)
...
...
python/paddle/fluid/layers/rnn.py
浏览文件 @
5675c7d5
...
@@ -1163,7 +1163,7 @@ class BeamSearchDecoder(Decoder):
...
@@ -1163,7 +1163,7 @@ class BeamSearchDecoder(Decoder):
batch_size
.
stop_gradient
=
True
# TODO: remove this
batch_size
.
stop_gradient
=
True
# TODO: remove this
batch_pos
=
paddle
.
tile
(
batch_pos
=
paddle
.
tile
(
nn
.
unsqueeze
(
nn
.
unsqueeze
(
tensor
.
range
(
0
,
batch_size
,
1
,
dtype
=
indices
.
dtype
),
[
1
]
paddle
.
a
range
(
0
,
batch_size
,
1
,
dtype
=
indices
.
dtype
),
[
1
]
),
),
[
1
,
self
.
beam_size
],
[
1
,
self
.
beam_size
],
)
)
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
5675c7d5
...
@@ -66,7 +66,6 @@ __all__ = [
...
@@ -66,7 +66,6 @@ __all__ = [
'has_inf'
,
'has_inf'
,
'has_nan'
,
'has_nan'
,
'isfinite'
,
'isfinite'
,
'range'
,
'linspace'
,
'linspace'
,
'zeros_like'
,
'zeros_like'
,
'ones_like'
,
'ones_like'
,
...
@@ -1635,108 +1634,6 @@ def isfinite(x):
...
@@ -1635,108 +1634,6 @@ def isfinite(x):
return
out
return
out
def
range
(
start
,
end
,
step
,
dtype
,
name
=
None
):
"""
This OP returns a 1-D Tensor with spaced values within a given interval.
Values are generated into the half-open interval [``start``, ``end``) with
the ``step``. (the interval including ``start`` but excluding ``end``).
If ``dtype`` is float32 or float64, we advise adding a small epsilon to
``end`` to avoid floating point rounding errors when comparing against ``end``.
Parameters:
start(float|int|Tensor): Start of interval. The interval includes this
value. If ``start`` is a Tensor, it is a 1-D Tensor with shape [1],
with data type int32, int64, float32, float64.
end(float|int|Tensor): End of interval. The interval does not include
this value. If ``end`` is a Tensor, it is a 1-D Tensor with shape
[1], with data type int32, int64, float32, float64.
step(float|int|Tensor): Spacing between values. For any out, it is
the istance between two adjacent values, out[i+1] - out[i]. If
``step`` is a Tensor, it is a 1-D Tensor with shape [1], with data
type int32, int64, float32, float64.
dtype(str|np.dtype|core.VarDesc.VarType, optional): The data type of the
output tensor. Supported data types: int32, int64, float32, float64.
name(str, optional): The default value is None. Normally there is no
need for user to set this property. For more information, please
refer to :ref:`api_guide_Name`.
Returns:
Tensor: A 1-D Tensor with values from the interval [``start``, ``end``)
taken with common difference ``step`` beginning from ``start``. Its
data type is set by ``dtype``.
Raises:
TypeError: If ``dtype`` is not int32, int64, float32, float64.
examples:
.. code-block:: python
import paddle.fluid as fluid
out1 = fluid.layers.range(0, 10, 2, 'int32')
# [0, 2, 4, 6, 8]
start_var = fluid.layers.fill_constant([1], 'int64', 3)
out2 = fluid.layers.range(start_var, 7, 1, 'int64')
# [3, 4, 5, 6]
"""
out_shape
=
None
if
(
not
isinstance
(
start
,
Variable
)
and
not
isinstance
(
end
,
Variable
)
and
not
isinstance
(
step
,
Variable
)
):
out_shape
=
[
int
(
math
.
ceil
((
end
-
start
)
/
step
))]
if
not
isinstance
(
dtype
,
core
.
VarDesc
.
VarType
):
dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
if
not
isinstance
(
start
,
Variable
):
with
device_guard
(
"cpu"
):
start
=
fill_constant
([
1
],
dtype
,
start
,
force_cpu
=
True
)
elif
start
.
dtype
!=
dtype
:
start
=
cast
(
start
,
dtype
)
if
not
isinstance
(
end
,
Variable
):
with
device_guard
(
"cpu"
):
end
=
fill_constant
([
1
],
dtype
,
end
,
force_cpu
=
True
)
elif
end
.
dtype
!=
dtype
:
end
=
cast
(
end
,
dtype
)
if
not
isinstance
(
step
,
Variable
):
with
device_guard
(
"cpu"
):
step
=
fill_constant
([
1
],
dtype
,
step
,
force_cpu
=
True
)
elif
step
.
dtype
!=
dtype
:
step
=
cast
(
step
,
dtype
)
if
in_dygraph_mode
():
return
_C_ops
.
arange
(
start
,
end
,
step
,
dtype
,
_current_expected_place
())
if
_in_legacy_dygraph
():
out
=
_legacy_C_ops
.
range
(
start
,
end
,
step
)
out
.
stop_gradient
=
True
return
out
check_dtype
(
dtype
,
'dtype'
,
[
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'range/arange'
)
helper
=
LayerHelper
(
'range'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
,
shape
=
out_shape
)
helper
.
append_op
(
type
=
'range'
,
inputs
=
{
'Start'
:
start
,
'End'
:
end
,
'Step'
:
step
},
outputs
=
{
'Out'
:
out
},
)
out
.
stop_gradient
=
True
if
out_shape
is
not
None
:
out
.
desc
.
set_shape
(
out_shape
)
return
out
def
linspace
(
start
,
stop
,
num
,
dtype
=
None
,
name
=
None
):
def
linspace
(
start
,
stop
,
num
,
dtype
=
None
,
name
=
None
):
r
"""
r
"""
This OP return fixed number of evenly spaced values within a given interval.
This OP return fixed number of evenly spaced values within a given interval.
...
...
python/paddle/fluid/tests/unittests/test_dynamic_rnn_stop_gradient.py
浏览文件 @
5675c7d5
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
# limitations under the License.
# limitations under the License.
import
numpy
as
np
import
numpy
as
np
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
import
paddle.fluid.layers
as
layers
import
unittest
import
unittest
...
@@ -43,7 +44,7 @@ def build_and_run_program(place, batch_size, beam_size, stop_gradient=False):
...
@@ -43,7 +44,7 @@ def build_and_run_program(place, batch_size, beam_size, stop_gradient=False):
bs
=
layers
.
cast
(
bs
,
'int64'
)
bs
=
layers
.
cast
(
bs
,
'int64'
)
bs
.
stop_gradient
=
stop_gradient
bs
.
stop_gradient
=
stop_gradient
batch_pos
=
layers
.
expand
(
batch_pos
=
layers
.
expand
(
layers
.
unsqueeze
(
layers
.
range
(
0
,
bs
,
1
,
dtype
=
bs
.
dtype
),
[
1
]),
layers
.
unsqueeze
(
paddle
.
a
range
(
0
,
bs
,
1
,
dtype
=
bs
.
dtype
),
[
1
]),
[
1
,
beam_size
],
[
1
,
beam_size
],
)
)
topk_coordinates
=
paddle
.
stack
([
batch_pos
,
indices
],
axis
=
2
)
topk_coordinates
=
paddle
.
stack
([
batch_pos
,
indices
],
axis
=
2
)
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
5675c7d5
...
@@ -4023,13 +4023,13 @@ class TestBook(LayerTest):
...
@@ -4023,13 +4023,13 @@ class TestBook(LayerTest):
with
program_guard
(
with
program_guard
(
fluid
.
default_main_program
(),
fluid
.
default_startup_program
()
fluid
.
default_main_program
(),
fluid
.
default_startup_program
()
):
):
layers
.
range
(
0
,
10
,
2
,
'int32'
)
paddle
.
a
range
(
0
,
10
,
2
,
'int32'
)
layers
.
range
(
0.1
,
10.0
,
0.2
,
'float32'
)
paddle
.
a
range
(
0.1
,
10.0
,
0.2
,
'float32'
)
layers
.
range
(
0.1
,
10.0
,
0.2
,
'float64'
)
paddle
.
a
range
(
0.1
,
10.0
,
0.2
,
'float64'
)
start
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.1
,
dtype
=
"float32"
)
start
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.1
,
dtype
=
"float32"
)
end
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
10.0
,
dtype
=
"float32"
)
end
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
10.0
,
dtype
=
"float32"
)
step
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.2
,
dtype
=
"float32"
)
step
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.2
,
dtype
=
"float32"
)
y
=
layers
.
range
(
start
,
end
,
step
,
'float64'
)
y
=
paddle
.
a
range
(
start
,
end
,
step
,
'float64'
)
return
y
return
y
def
make_spectral_norm
(
self
):
def
make_spectral_norm
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录