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

Class BCDWorker

src/learner/bcd.h:277–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275
276template <typename V>
277class BCDWorker : public App, public BCDCommon {
278 public:
279 BCDWorker(const string& name, const BCDConfig& conf)
280 : App(name), BCDCommon(conf), model_(name+"_model", name) { }
281 virtual ~BCDWorker() { }
282
283 void process(const MessagePtr& msg) {
284 CHECK(msg->task.has_bcd());
285 auto bcd = msg->task.bcd();
286 int time = msg->task.time() * time_ratio_;
287 switch (bcd.cmd()) {
288 case BCDCall::LOAD_DATA: {
289 LoadDataReturn ret;
290 int hit_cache = 0;
291 CHECK(bcd.has_data());
292 loadData(bcd.data(), ret.mutable_example_info(), &hit_cache);
293 ret.set_hit_cache(hit_cache);
294 sys_.replyProtocalMessage(msg, ret);
295 break;
296 }
297 case BCDCall::PREPROCESS_DATA:
298 preprocessData(time, bcd);
299 break;
300 case BCDCall::UPDATE_MODEL:
301 computeGradient(time, bcd, msg);
302 msg->finished = false; //
303 break;
304 case BCDCall::EVALUATE_PROGRESS: {
305 BCDProgress prog; evaluate(&prog);
306 sys_.replyProtocalMessage(msg, prog);
307 break;
308 }
309 default: break;
310 }
311 }
312 protected:
313 virtual void computeGradient(int time, const BCDCall& bcd, MessagePtr msg) = 0;
314 virtual void evaluate(BCDProgress* prog) = 0;
315
316 void loadData(const DataConfig& data, ExampleInfo* info, int *hit_cache) {
317 *hit_cache = dataCache("train", true);
318 if (!(*hit_cache)) {
319 slot_reader_.init(data, bcd_conf_.local_cache());
320 slot_reader_.read(info);
321 }
322 }
323
324 virtual void preprocessData(int time, const BCDCall& call) {
325 int grp_size = call.fea_grp_size();
326 fea_grp_.clear();
327 for (int i = 0; i < grp_size; ++i) {
328 fea_grp_.push_back(call.fea_grp(i));
329 }
330 bool hit_cache = call.hit_cache();
331 int max_parallel = std::max(
332 1, bcd_conf_.max_num_parallel_groups_in_preprocessing());
333 // filter keys whose occurance <= bcd_conf_.tail_feature_freq()
334 std::vector<int> pull_time(grp_size);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected