Caffe2 - C++ API
A deep learning, cross platform ML framework
observer_config.h
1 #pragma once
2 
3 #include "observers/net_observer_reporter.h"
4 
5 namespace caffe2 {
6 
7 /*
8  netInitSampleRate_ == 1 && operatorNetSampleRatio_ == 1 :
9  Log operator metrics in every iteration
10  netInitSampleRate_ == 1 && operatorNetSampleRatio_ == 0 :
11  Log net metrics in every iterationn
12  netInitSampleRate_ == n && netFollowupSampleRate_ == m &&
13  netFollowupSampleCount == c && operatorNetSampleRatio_ == 1 :
14  Log operator metrics first at odds of 1 / n. Once first logged,
15  the following c logs are at odds of 1 / min(n, m). Then repeat
16  netInitSampleRate_ == n && netFollowupSampleRate_ == m &&
17  netFollowupSampleCount == c && operatorNetSampleRatio_ == 0 :
18  Log net metrics first at odds of 1 / n. Once first logged,
19  the following c logs are at odds of 1 / min(n, m). Then repeat
20  netInitSampleRate_ == n && netFollowupSampleRate_ == m &&
21  netFollowupSampleCount == c && operatorNetSampleRatio_ == o :
22  Log net metrics first at odds of 1 / n. Once first logged,
23  the following c logs are at odds of 1 / min(n, m), if the random number
24  is multiples of o, log operator metrics instead. Then repeat
25  skipIters_ == n: skip the first n iterations of the net.
26 */
28  public:
29  static void initSampleRate(
30  int netInitSampleRate,
31  int netFollowupSampleRate,
32  int netFollowupSampleCount,
33  int operatorNetSampleRatio,
34  int skipIters) {
35  CAFFE_ENFORCE(netFollowupSampleRate <= netInitSampleRate);
36  CAFFE_ENFORCE(netFollowupSampleRate >= 1 || netInitSampleRate == 0);
37  netInitSampleRate_ = netInitSampleRate;
38  netFollowupSampleRate_ = netFollowupSampleRate;
39  netFollowupSampleCount_ = netFollowupSampleCount;
40  operatorNetSampleRatio_ = operatorNetSampleRatio;
41  skipIters_ = skipIters;
42  }
43  static int getNetInitSampleRate() {
44  return netInitSampleRate_;
45  }
46  static int getNetFollowupSampleRate() {
47  return netFollowupSampleRate_;
48  }
49  static int getNetFollowupSampleCount() {
50  return netFollowupSampleCount_;
51  }
52  static int getOpoeratorNetSampleRatio() {
53  return operatorNetSampleRatio_;
54  }
55  static int getSkipIters() {
56  return skipIters_;
57  }
58  static void setReporter(unique_ptr<NetObserverReporter> reporter) {
59  // Can only set the reporter once
60  CAFFE_ENFORCE(reporter_ == nullptr);
61  reporter_ = std::move(reporter);
62  }
63  static NetObserverReporter* getReporter() {
64  CAFFE_ENFORCE(reporter_);
65  return reporter_.get();
66  }
67  static void setMarker(int marker) {
68  marker_ = marker;
69  }
70  static int getMarker() {
71  return marker_;
72  }
73 
74  private:
75  /* The odds of log net metric initially or immediately after reset */
76  static int netInitSampleRate_;
77 
78  /* The odds of log net metric after log once after start of reset */
79  static int netFollowupSampleRate_;
80 
81  /* The number of follow up logs to be collected for odds of
82  netFollowupSampleRate_ */
83  static int netFollowupSampleCount_;
84 
85  /* The odds to log the operator metric instead of the net metric.
86  When the operator is logged the net is not logged. */
87  static int operatorNetSampleRatio_;
88 
89  /* skip the first few iterations */
90  static int skipIters_;
91 
92  static unique_ptr<NetObserverReporter> reporter_;
93 
94  /* marker used in identifying the metrics in certain reporters */
95  static int marker_;
96 };
97 
98 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...