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