MCPcopy Create free account
hub / github.com/dmlc/parameter_server / BCDServer

Class BCDServer

src/learner/bcd.h:194–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193template <typename V>
194class BCDServer : public App, public BCDCommon {
195 public:
196 BCDServer(const string& name, const BCDConfig& conf)
197 : App(name), BCDCommon(conf), model_(name+"_model", name) { }
198 virtual ~BCDServer() { }
199
200 void process(const MessagePtr& msg) {
201 CHECK(msg->task.has_bcd());
202 auto bcd = msg->task.bcd();
203 int time = msg->task.time() * time_ratio_;
204 switch (bcd.cmd()) {
205 case BCDCall::PREPROCESS_DATA:
206 preprocessData(time, bcd);
207 break;
208 case BCDCall::UPDATE_MODEL:
209 updateModel(time, bcd);
210 break;
211 case BCDCall::SAVE_MODEL:
212 CHECK(bcd.has_data());
213 saveModel(bcd.data());
214 case BCDCall::EVALUATE_PROGRESS: {
215 BCDProgress prog; evaluate(&prog);
216 sys_.replyProtocalMessage(msg, prog);
217 break;
218 }
219 default: break;
220 }
221 }
222 protected:
223 virtual void updateModel(int time, const BCDCall& call) = 0;
224 virtual void evaluate(BCDProgress* prog) = 0;
225
226 virtual void preprocessData(int time, const BCDCall& call) {
227 int grp_size = call.fea_grp_size();
228 fea_grp_.clear();
229 for (int i = 0; i < grp_size; ++i) {
230 fea_grp_.push_back(call.fea_grp(i));
231 }
232 bool hit_cache = call.hit_cache();
233 // filter tail keys
234 for (int i = 0; i < grp_size; ++i, time += time_ratio_) {
235 if (hit_cache) continue;
236 model_.waitInMsg(kWorkerGroup, time);
237 model_.finish(kWorkerGroup, time+1);
238 }
239 for (int i = 0; i < grp_size; ++i, time += time_ratio_) {
240 // wait untill received all keys from workers
241 model_.waitInMsg(kWorkerGroup, time);
242 // initialize the weight
243 int chl = fea_grp_[i];
244 model_.clearTailFilter(chl);
245 model_.value(chl).resize(model_.key(chl).size());
246 model_.value(chl).setValue(bcd_conf_.init_w());
247 model_.finish(kWorkerGroup, time+1);
248 }
249 }
250
251 void saveModel(const DataConfig& output) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected