Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change data type of beam_search op #7374

Merged
merged 1 commit into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions paddle/operators/beam_search_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void BeamSearch::operator()(const framework::LoDTensor &pre_ids,

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

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

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

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

auto *ids_data = ids.data<int>();
auto *ids_data = ids.data<int64_t>();
auto *scores_data = scores.data<float>();

size_t instance_dim = 1;
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/v2/fluid/tests/test_beam_search_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def test_run(self):
print 'lod', selected_ids.lod()

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

def _create_ids(self):
self.lod = [[0, 1, 4], [0, 1, 2, 3, 4]]
np_data = np.array(
[[4, 2, 5], [2, 1, 3], [3, 5, 2], [8, 2, 1]], dtype='int32')
[[4, 2, 5], [2, 1, 3], [3, 5, 2], [8, 2, 1]], dtype='int64')
tensor = create_tensor(self.scope, "ids", np_data)
tensor.set_lod(self.lod)

Expand Down