MCPcopy Create free account
hub / github.com/Tencent/embedx / DumpBatch

Method DumpBatch

src/tools/trainer_context.cc:107–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107void TrainerContext::DumpBatch(deepx_core::OutputStream& os) const {
108 // output format
109 // FLAGS_target_type=1
110 // ctr: label prob
111 // classification: node prob0 prob1
112 // FLAGS_target_type=2 or FLAGS_target_type=3
113 // embedding: node val0 val1 val2 val3
114
115 const vec_int_t* nodes = nullptr;
116 const tsr_t* Y = nullptr;
117 const auto* Z = op_context_->ptr().get<tsr_t*>(target_name_);
118 const Instance& inst = op_context_->inst();
119
120 int inst_batch = Z->dim(0);
121 DXCHECK_THROW(Z->is_rank(2));
122
123 if (target_type_ == 1) {
124 auto it = inst.find(deepx_core::Y_NAME);
125 if (it != inst.end()) {
126 Y = &it->second.to_ref<tsr_t>();
127 DXCHECK_THROW(Y->is_rank(2));
128 DXCHECK_THROW(Y->dim(0) == inst_batch);
129 }
130
131 it = inst.find(instance_name::X_PREDICT_NODE_NAME);
132 if (it != inst.end()) {
133 nodes = &it->second.to_ref<vec_int_t>();
134 DXCHECK_THROW((int)nodes->size() == inst_batch);
135 }
136 } else if (target_type_ == 2 or target_type_ == 3) {
137 auto it = inst.find(instance_name::X_PREDICT_NODE_NAME);
138 DXCHECK_THROW(it != inst.end());
139
140 nodes = &it->second.to_ref<vec_int_t>();
141 DXCHECK_THROW((int)nodes->size() == inst_batch);
142 }
143
144 std::ostringstream oss;
145 for (int i = 0; i < inst_batch; ++i) {
146 oss.clear();
147 oss.str("");
148 if (nodes) {
149 oss << (*nodes)[i];
150 }
151 if (Y) {
152 for (int j = 0; j < Y->dim(1); ++j) {
153 oss << ' ' << Y->data(i * Y->dim(1) + j);
154 }
155 }
156 for (int j = 0; j < Z->dim(1); ++j) {
157 oss << ' ' << Z->data(i * Z->dim(1) + j);
158 }
159 oss << "\n";
160 std::string s = oss.str();
161 os.Write(s.data(), s.size());
162 }
163}
164

Callers

nothing calls this directly

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected