Skip to content

Commit efe06ca

Browse files
authored
change data type of beam_search op (#7374)
1 parent 91f80f7 commit efe06ca

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

paddle/operators/beam_search_op.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void BeamSearch::operator()(const framework::LoDTensor &pre_ids,
3939

4040
std::map<size_t /*offset*/, std::vector<Item>> hash;
4141
framework::LoD new_lod;
42-
auto *ids_data = selected_ids->mutable_data<int>(platform::CPUPlace());
42+
auto *ids_data = selected_ids->mutable_data<int64_t>(platform::CPUPlace());
4343
auto *scores_data =
4444
selected_scores->mutable_data<float>(platform::CPUPlace());
4545

@@ -66,7 +66,7 @@ void BeamSearch::operator()(const framework::LoDTensor &pre_ids,
6666

6767
void BeamSearch::PruneEndidCandidates(const framework::LoDTensor &pre_ids,
6868
std::vector<std::vector<Item>> *items) {
69-
auto *pre_ids_data = pre_ids.data<int>();
69+
auto *pre_ids_data = pre_ids.data<int64_t>();
7070

7171
for (size_t offset = 0; offset < items->size(); offset++) {
7272
auto prefix_id = pre_ids_data[offset];
@@ -127,7 +127,7 @@ bool BeamSearch::NextItemSet(std::vector<BeamSearch::Item> *items) {
127127
auto abs_lod = framework::ToAbsOffset(ids.lod());
128128
PADDLE_ENFORCE_GE(source_abs_two_level_lod.size(), 2UL);
129129

130-
auto *ids_data = ids.data<int>();
130+
auto *ids_data = ids.data<int64_t>();
131131
auto *scores_data = scores.data<float>();
132132

133133
size_t instance_dim = 1;

python/paddle/v2/fluid/tests/test_beam_search_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def test_run(self):
3737
print 'lod', selected_ids.lod()
3838

3939
def _create_pre_ids(self):
40-
np_data = np.array([[1, 2, 3, 4]], dtype='int32')
40+
np_data = np.array([[1, 2, 3, 4]], dtype='int64')
4141
tensor = create_tensor(self.scope, "pre_ids", np_data)
4242

4343
def _create_ids(self):
4444
self.lod = [[0, 1, 4], [0, 1, 2, 3, 4]]
4545
np_data = np.array(
46-
[[4, 2, 5], [2, 1, 3], [3, 5, 2], [8, 2, 1]], dtype='int32')
46+
[[4, 2, 5], [2, 1, 3], [3, 5, 2], [8, 2, 1]], dtype='int64')
4747
tensor = create_tensor(self.scope, "ids", np_data)
4848
tensor.set_lod(self.lod)
4949

0 commit comments

Comments
 (0)