Skip to content

Commit e677833

Browse files
committed
code clean
1 parent 5c65eff commit e677833

File tree

3 files changed

+16
-50
lines changed

3 files changed

+16
-50
lines changed

paddle/fluid/operators/reader/ctr_reader.cc

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ static inline void parse_line(
7373
}
7474
}
7575

76-
static void print_map(
77-
std::unordered_map<std::string, std::vector<int64_t>>* map) {
78-
for (auto it = map->begin(); it != map->end(); ++it) {
79-
std::cout << it->first << " -> ";
80-
std::cout << "[";
81-
for (auto& i : it->second) {
82-
std::cout << i << " ";
83-
}
84-
std::cout << "]\n";
85-
}
86-
}
87-
8876
class Reader {
8977
public:
9078
virtual ~Reader() {}
@@ -162,10 +150,6 @@ void ReadThread(const std::vector<std::string>& file_list,
162150

163151
VLOG(3) << "reader inited";
164152

165-
uint64_t t0 = GetTimeInSec();
166-
167-
int i = 0;
168-
169153
while (reader.HasNext()) {
170154
batch_data.clear();
171155
batch_data.reserve(batch_size);
@@ -186,7 +170,6 @@ void ReadThread(const std::vector<std::string>& file_list,
186170
break;
187171
}
188172
}
189-
// print_map(&batch_data[0]);
190173

191174
std::vector<framework::LoDTensor> lod_datas;
192175

@@ -224,19 +207,10 @@ void ReadThread(const std::vector<std::string>& file_list,
224207

225208
queue->Push(lod_datas);
226209
VLOG(4) << "push one data, queue_size=" << queue->Size();
227-
228-
if (i != 0 && i % 100 == 0) {
229-
uint64_t t1 = GetTimeInSec();
230-
float line_per_s = 100 * batch_size * 1000000 / (t1 - t0);
231-
VLOG(3) << "[" << thread_id << "]"
232-
<< " line_per_second = " << line_per_s;
233-
t0 = t1;
234-
}
235-
i++;
236210
}
237211

238212
(*thread_status)[thread_id] = Stopped;
239-
VLOG(3) << "thread " << thread_id << " exited";
213+
VLOG(3) << "set status to stopped, thread " << thread_id << " exited";
240214
}
241215

242216
} // namespace reader

paddle/fluid/operators/reader/ctr_reader.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ void ReadThread(const std::vector<std::string>& file_list,
3939
int thread_id, std::vector<ReaderThreadStatus>* thread_status,
4040
std::shared_ptr<LoDTensorBlockingQueue> queue);
4141

42-
inline uint64_t GetTimeInSec() {
43-
using clock = std::conditional<std::chrono::high_resolution_clock::is_steady,
44-
std::chrono::high_resolution_clock,
45-
std::chrono::steady_clock>::type;
46-
return std::chrono::duration_cast<std::chrono::microseconds>(
47-
clock::now().time_since_epoch())
48-
.count();
49-
}
50-
5142
class CTRReader : public framework::FileReader {
5243
public:
5344
explicit CTRReader(const std::shared_ptr<LoDTensorBlockingQueue>& queue,

paddle/fluid/operators/reader/ctr_reader_test.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ using paddle::operators::reader::LoDTensorBlockingQueueHolder;
3333
using paddle::operators::reader::CTRReader;
3434
using paddle::framework::LoDTensor;
3535
using paddle::framework::LoD;
36+
using paddle::framework::DDim;
3637
using paddle::platform::CPUPlace;
3738

3839
static void generatedata(const std::vector<std::string>& data,
@@ -73,25 +74,25 @@ TEST(CTR_READER, read_data) {
7374
std::vector<int64_t> label_value = {0, 0, 1, 0, 1, 1, 0, 1, 1, 1};
7475

7576
std::vector<std::tuple<LoD, std::vector<int64_t>>> data_slot_6002{
76-
{{{0, 1, 2}}, {0, 0}},
77-
{{{0, 5, 6}}, {10, 11, 12, 13, 14, 0}},
78-
{{{0, 1, 2}}, {0, 0}},
79-
{{{0, 1, 2}}, {30, 0}},
80-
{{{0, 1, 2}}, {40, 0}}};
77+
{{{0, 1, 2, 7}}, {0, 0, 10, 11, 12, 13, 14}},
78+
{{{0, 1, 2, 3}}, {0, 0, 0}},
79+
{{{0, 1, 2, 3}}, {30, 0, 40}},
80+
{{{0, 1}}, {0}}};
8181
std::vector<std::tuple<LoD, std::vector<int64_t>>> data_slot_6003{
82-
{{{0, 1, 4}}, {1, 5, 6, 7}},
83-
{{{0, 1, 5}}, {0, 15, 16, 17, 18}},
84-
{{{0, 1, 2}}, {0, 0}},
85-
{{{0, 1, 3}}, {31, 35, 36}},
86-
{{{0, 1, 4}}, {41, 47, 48, 49}}};
82+
{{{0, 1, 4, 5}}, {1, 5, 6, 7, 0}},
83+
{{{0, 4, 5, 6}}, {15, 16, 17, 18, 0, 0}},
84+
{{{0, 1, 3, 4}}, {31, 35, 36, 41}},
85+
{{{0, 3}}, {47, 48, 49}}};
86+
87+
std::vector<DDim> label_dims = {{1, 3}, {1, 3}, {1, 3}, {1, 1}};
8788

8889
LoDTensorBlockingQueueHolder queue_holder;
8990
int capacity = 64;
9091
queue_holder.InitOnce(capacity, {}, false);
9192

9293
std::shared_ptr<LoDTensorBlockingQueue> queue = queue_holder.GetQueue();
9394

94-
int batch_size = 2;
95+
int batch_size = 3;
9596
int thread_num = 1;
9697
std::vector<std::string> slots = {"6002", "6003"};
9798
std::vector<std::string> file_list;
@@ -103,15 +104,15 @@ TEST(CTR_READER, read_data) {
103104

104105
reader.Start();
105106

106-
size_t batch_num = std::ceil(ctr_data.size() / batch_size) * thread_num;
107+
size_t batch_num =
108+
std::ceil(static_cast<float>(ctr_data.size()) / batch_size) * thread_num;
107109

108110
for (size_t i = 0; i < batch_num; ++i) {
109111
std::vector<LoDTensor> out;
110112
reader.ReadNext(&out);
111113
ASSERT_EQ(out.size(), slots.size() + 1);
112114
auto& label_tensor = out.back();
113-
ASSERT_EQ(label_tensor.dims(),
114-
paddle::framework::make_ddim({1, batch_size}));
115+
ASSERT_EQ(label_tensor.dims(), label_dims[i]);
115116
for (size_t j = 0; j < batch_size && i * batch_num + j < ctr_data.size();
116117
++j) {
117118
auto& label = label_tensor.data<int64_t>()[j];

0 commit comments

Comments
 (0)