Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
c6a2b0fd
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c6a2b0fd
编写于
12月 07, 2022
作者:
2
201716010711
提交者:
GitHub
12月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete sampling_id api (#48543)
上级
ddd5656a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
0 addition
and
263 deletion
+0
-263
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-40
python/paddle/fluid/layers/rnn.py
python/paddle/fluid/layers/rnn.py
+0
-34
python/paddle/fluid/tests/unittests/npu/test_sampling_id_op_npu.py
...ddle/fluid/tests/unittests/npu/test_sampling_id_op_npu.py
+0
-52
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+0
-15
python/paddle/fluid/tests/unittests/test_random_seed.py
python/paddle/fluid/tests/unittests/test_random_seed.py
+0
-77
python/paddle/fluid/tests/unittests/test_sampling_id_op.py
python/paddle/fluid/tests/unittests/test_sampling_id_op.py
+0
-45
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
c6a2b0fd
...
...
@@ -86,7 +86,6 @@ __all__ = [
'elementwise_sub'
,
'elementwise_mul'
,
'gaussian_random'
,
'sampling_id'
,
'clip'
,
'clip_by_norm'
,
'mean'
,
...
...
@@ -3190,45 +3189,6 @@ def gaussian_random(
return
out
@
templatedoc
()
def
sampling_id
(
x
,
min
=
0.0
,
max
=
1.0
,
seed
=
0
,
dtype
=
'float32'
):
"""
This op is used for sampling id from multinomial distribution from the input, sampling one id for one sample.
Parameters:
x (Variable): 2-D tensor, [batch_size, input_feature_dimensions]
min (Float): minimum , default 0.0.
max (Float): maximum, default 1.0.
seed (Float): Random seed, default 0. if seed is not 0, will generate same number every time.
dtype(np.dtype|core.VarDesc.VarType|str): The type of output data : float32, float_16, int etc
Returns:
Variable: sampling tensor.
Examples:
.. code-block:: python
import paddle.fluid as fluid
x = fluid.data(
name="X",
shape=[13, 11],
dtype='float32')
out = fluid.layers.sampling_id(x)
"""
helper
=
LayerHelper
(
'sampling_id'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
helper
.
append_op
(
type
=
'sampling_id'
,
inputs
=
{
'X'
:
x
},
outputs
=
{
'Out'
:
out
},
attrs
=
{
'min'
:
min
,
'max'
:
max
,
'seed'
:
seed
},
)
return
out
def
_elementwise_op
(
helper
):
op_type
=
helper
.
layer_type
x
=
helper
.
kwargs
.
get
(
'x'
,
None
)
...
...
python/paddle/fluid/layers/rnn.py
浏览文件 @
c6a2b0fd
...
...
@@ -2306,40 +2306,6 @@ class SampleEmbeddingHelper(GreedyEmbeddingHelper):
)
self
.
seed
=
seed
def
sample
(
self
,
time
,
outputs
,
states
):
r
"""
Perform sampling from a categorical distribution, and the distribution
is computed by `softmax(outputs/softmax_temperature)`.
Parameters:
time(Variable): An `int64` tensor with shape `[1]` provided by the
caller, representing the current time step number of decoding.
outputs(Variable): A tensor variable. Usually it's data type is float32
or float64, and it's shape is `[batch_size, vocabulary_size]`,
representing the predicted logits of current step. It is same as
`outputs` returned by `BasicDecoder.output_fn(BasicDecoder.cell.call())`.
states(Variable): A (possibly nested structure of) tensor variable[s].
It is same as `new_states` returned by `BasicDecoder.cell.call()`.
Returns:
Variable: An `int64` tensor with shape `[batch_size]`, representing \
the sampled ids.
"""
logits
=
(
(
outputs
/
self
.
softmax_temperature
)
if
self
.
softmax_temperature
is
not
None
else
outputs
)
probs
=
paddle
.
nn
.
functional
.
softmax
(
logits
)
# TODO: remove this stop_gradient. The stop_gradient of sample_ids can
# not pass to probs, since sampling_id op does not have corresponding
# grad op and thus can not pass.
probs
.
stop_gradient
=
True
sample_ids
=
nn
.
sampling_id
(
probs
,
seed
=
self
.
seed
,
dtype
=
self
.
start_tokens
.
dtype
)
return
sample_ids
class
BasicDecoder
(
Decoder
):
"""
...
...
python/paddle/fluid/tests/unittests/npu/test_sampling_id_op_npu.py
已删除
100644 → 0
浏览文件 @
ddd5656a
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
numpy
as
np
import
sys
sys
.
path
.
append
(
".."
)
from
op_test
import
OpTest
,
_set_use_system_allocator
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
from
paddle.fluid.op
import
Operator
import
paddle
_set_use_system_allocator
(
False
)
class
TestSamplingIdShape
(
unittest
.
TestCase
):
def
test_shape
(
self
):
paddle
.
enable_static
()
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
3
],
dtype
=
'float32'
)
output
=
fluid
.
layers
.
sampling_id
(
x
)
place
=
fluid
.
NPUPlace
(
0
)
exe
=
fluid
.
Executor
(
place
=
place
)
exe
.
run
(
fluid
.
default_startup_program
())
feed
=
{
'x'
:
np
.
array
([[
0.2
,
0.3
,
0.5
],
[
0.2
,
0.3
,
0.4
]],
dtype
=
'float32'
)
}
output_np
=
exe
.
run
(
feed
=
feed
,
fetch_list
=
[
output
])[
0
]
self
.
assertEqual
(
output
.
shape
[
0
],
-
1
)
self
.
assertEqual
(
len
(
output
.
shape
),
1
)
self
.
assertEqual
(
output_np
.
shape
[
0
],
2
)
self
.
assertEqual
(
len
(
output_np
.
shape
),
1
)
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
c6a2b0fd
...
...
@@ -2308,7 +2308,6 @@ class TestBook(LayerTest):
{
"make_gaussian_random"
,
"make_kldiv_loss"
,
"make_sampling_id"
,
"make_uniform_random_batch_size_like"
,
}
)
...
...
@@ -2794,20 +2793,6 @@ class TestBook(LayerTest):
out
=
layers
.
gaussian_random
(
shape
=
[
20
,
30
])
return
out
def
make_sampling_id
(
self
):
with
program_guard
(
fluid
.
default_main_program
(),
fluid
.
default_startup_program
()
):
x
=
self
.
_get_data
(
name
=
"X"
,
shape
=
[
13
,
11
],
dtype
=
'float32'
,
append_batch_size
=
False
,
)
out
=
layers
.
sampling_id
(
x
)
return
out
def
make_sum
(
self
):
with
program_guard
(
fluid
.
default_main_program
(),
fluid
.
default_startup_program
()
...
...
python/paddle/fluid/tests/unittests/test_random_seed.py
浏览文件 @
c6a2b0fd
...
...
@@ -372,83 +372,6 @@ class TestGeneratorSeed(unittest.TestCase):
np
.
testing
.
assert_allclose
(
out1_res2
,
out2_res2
,
rtol
=
1e-05
)
self
.
assertTrue
(
not
np
.
allclose
(
out1_res2
,
out1_res1
))
def
test_generator_sampling_id_dygraph
(
self
):
"""Test Generator seed."""
gen
=
paddle
.
seed
(
12312321111
)
fluid
.
enable_dygraph
()
gen
.
manual_seed
(
12312321111
)
x
=
fluid
.
layers
.
uniform_random
(
[
10
,
10
],
dtype
=
"float32"
,
min
=
0.0
,
max
=
1.0
)
y
=
fluid
.
layers
.
sampling_id
(
x
)
st1
=
gen
.
get_state
()
x1
=
fluid
.
layers
.
uniform_random
(
[
10
,
10
],
dtype
=
"float32"
,
min
=
0.0
,
max
=
1.0
)
y1
=
fluid
.
layers
.
sampling_id
(
x
)
gen
.
set_state
(
st1
)
x2
=
fluid
.
layers
.
uniform_random
(
[
10
,
10
],
dtype
=
"float32"
,
min
=
0.0
,
max
=
1.0
)
y2
=
fluid
.
layers
.
sampling_id
(
x
)
gen
.
manual_seed
(
12312321111
)
x3
=
fluid
.
layers
.
uniform_random
(
[
10
,
10
],
dtype
=
"float32"
,
min
=
0.0
,
max
=
1.0
)
y3
=
fluid
.
layers
.
sampling_id
(
x
)
x_np
=
y
.
numpy
()
x1_np
=
y1
.
numpy
()
x2_np
=
y2
.
numpy
()
x3_np
=
y3
.
numpy
()
if
not
core
.
is_compiled_with_cuda
():
print
(
">>>>>>> sampling id dygraph >>>>>>>"
)
np
.
testing
.
assert_allclose
(
x1_np
,
x2_np
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
x_np
,
x3_np
,
rtol
=
1e-05
)
def
test_generator_randperm_static_1
(
self
):
fluid
.
disable_dygraph
()
paddle
.
seed
(
123123143
)
startup_program
=
fluid
.
Program
()
train_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
train_program
,
startup_program
):
# example 1:
# attr shape is a list which doesn't contain tensor Variable.
x
=
fluid
.
layers
.
uniform_random
(
shape
=
[
10
,
10
])
result_1
=
fluid
.
layers
.
sampling_id
(
x
)
result_2
=
fluid
.
layers
.
sampling_id
(
x
)
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
exe
.
run
(
startup_program
)
out1
=
exe
.
run
(
train_program
,
feed
=
{},
fetch_list
=
[
result_1
,
result_2
]
)
paddle
.
seed
(
123123143
)
out2
=
exe
.
run
(
train_program
,
feed
=
{},
fetch_list
=
[
result_1
,
result_2
]
)
out1_res1
=
np
.
array
(
out1
[
0
])
out1_res2
=
np
.
array
(
out1
[
1
])
out2_res1
=
np
.
array
(
out2
[
0
])
out2_res2
=
np
.
array
(
out2
[
1
])
if
not
core
.
is_compiled_with_cuda
():
print
(
">>>>>>> sampling id static >>>>>>>"
)
np
.
testing
.
assert_allclose
(
out1_res1
,
out2_res1
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
out1_res2
,
out2_res2
,
rtol
=
1e-05
)
self
.
assertTrue
(
not
np
.
allclose
(
out1_res2
,
out1_res1
))
def
test_gen_TruncatedNormal_initializer
(
self
):
fluid
.
disable_dygraph
()
...
...
python/paddle/fluid/tests/unittests/test_sampling_id_op.py
已删除
100644 → 0
浏览文件 @
ddd5656a
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
numpy
as
np
import
paddle
import
paddle.fluid
as
fluid
class
TestSamplingIdShape
(
unittest
.
TestCase
):
def
test_shape
(
self
):
paddle
.
enable_static
()
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
3
],
dtype
=
'float32'
)
output
=
fluid
.
layers
.
sampling_id
(
x
)
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
=
place
)
exe
.
run
(
fluid
.
default_startup_program
())
feed
=
{
'x'
:
np
.
array
([[
0.2
,
0.3
,
0.5
],
[
0.2
,
0.3
,
0.4
]],
dtype
=
'float32'
)
}
output_np
=
exe
.
run
(
feed
=
feed
,
fetch_list
=
[
output
])[
0
]
self
.
assertEqual
(
output
.
shape
[
0
],
-
1
)
self
.
assertEqual
(
len
(
output
.
shape
),
1
)
self
.
assertEqual
(
output_np
.
shape
[
0
],
2
)
self
.
assertEqual
(
len
(
output_np
.
shape
),
1
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录