NnetOptimizeOptions Struct Reference

#include <nnet-optimize.h>

Collaboration diagram for NnetOptimizeOptions:

Public Member Functions

 NnetOptimizeOptions ()
 
void Register (OptionsItf *opts)
 
void Read (std::istream &is, bool binary)
 
void Write (std::ostream &os, bool binary) const
 
bool operator== (const NnetOptimizeOptions &other) const
 

Public Attributes

bool optimize
 
bool consolidate_model_update
 
bool propagate_in_place
 
bool backprop_in_place
 
bool optimize_row_ops
 
bool split_row_ops
 
bool extend_matrices
 
bool convert_addition
 
bool remove_assignments
 
bool allow_left_merge
 
bool allow_right_merge
 
bool initialize_undefined
 
bool move_sizing_commands
 
bool allocate_from_other
 
int32 min_deriv_time
 
int32 max_deriv_time
 
int32 max_deriv_time_relative
 
bool snip_row_ops
 
int32 memory_compression_level
 
bool optimize_looped_computation
 

Detailed Description

Definition at line 35 of file nnet-optimize.h.

Constructor & Destructor Documentation

◆ NnetOptimizeOptions()

NnetOptimizeOptions ( )
inline

Definition at line 62 of file nnet-optimize.h.

62  :
63  optimize(true),
65  propagate_in_place(true),
66  backprop_in_place(true),
67  optimize_row_ops(true),
68  split_row_ops(true),
69  extend_matrices(true),
70  convert_addition(true),
71  remove_assignments(true),
72  allow_left_merge(true),
73  allow_right_merge(true),
76  allocate_from_other(true),
77  min_deriv_time(std::numeric_limits<int32>::min()),
78  max_deriv_time(std::numeric_limits<int32>::max()),
79  max_deriv_time_relative(std::numeric_limits<int32>::max()),
80  snip_row_ops(true),

Member Function Documentation

◆ operator==()

bool operator== ( const NnetOptimizeOptions other) const

Definition at line 128 of file nnet-optimize.cc.

References NnetOptimizeOptions::allocate_from_other, NnetOptimizeOptions::allow_left_merge, NnetOptimizeOptions::allow_right_merge, NnetOptimizeOptions::backprop_in_place, NnetOptimizeOptions::consolidate_model_update, NnetOptimizeOptions::convert_addition, NnetOptimizeOptions::initialize_undefined, NnetOptimizeOptions::max_deriv_time, NnetOptimizeOptions::max_deriv_time_relative, NnetOptimizeOptions::memory_compression_level, NnetOptimizeOptions::min_deriv_time, NnetOptimizeOptions::move_sizing_commands, NnetOptimizeOptions::optimize, NnetOptimizeOptions::optimize_row_ops, NnetOptimizeOptions::propagate_in_place, NnetOptimizeOptions::remove_assignments, NnetOptimizeOptions::snip_row_ops, and NnetOptimizeOptions::split_row_ops.

Referenced by NnetOptimizeOptions::Register().

128  {
129  return (other.optimize == optimize &&
130  other.consolidate_model_update == consolidate_model_update &&
131  other.propagate_in_place == propagate_in_place &&
132  other.backprop_in_place == backprop_in_place &&
133  other.optimize_row_ops == optimize_row_ops &&
134  other.split_row_ops == split_row_ops &&
135  other.convert_addition == convert_addition &&
136  other.remove_assignments == remove_assignments &&
137  other.allow_left_merge == allow_left_merge &&
138  other.allow_right_merge == allow_right_merge &&
139  other.initialize_undefined == initialize_undefined &&
140  other.move_sizing_commands == move_sizing_commands &&
141  other.allocate_from_other == allocate_from_other &&
142  other.min_deriv_time == min_deriv_time &&
143  other.max_deriv_time == max_deriv_time &&
144  other.max_deriv_time_relative == max_deriv_time_relative &&
145  other.snip_row_ops == snip_row_ops &&
146  other.memory_compression_level == memory_compression_level);
147 }

◆ Read()

void Read ( std::istream &  is,
bool  binary 
)

Definition at line 30 of file nnet-optimize.cc.

References NnetOptimizeOptions::allocate_from_other, NnetOptimizeOptions::allow_left_merge, NnetOptimizeOptions::allow_right_merge, NnetOptimizeOptions::backprop_in_place, NnetOptimizeOptions::consolidate_model_update, NnetOptimizeOptions::convert_addition, kaldi::nnet3::ExpectToken(), NnetOptimizeOptions::extend_matrices, NnetOptimizeOptions::initialize_undefined, NnetOptimizeOptions::max_deriv_time, NnetOptimizeOptions::max_deriv_time_relative, NnetOptimizeOptions::memory_compression_level, NnetOptimizeOptions::min_deriv_time, NnetOptimizeOptions::move_sizing_commands, NnetOptimizeOptions::optimize, NnetOptimizeOptions::optimize_row_ops, kaldi::PeekToken(), NnetOptimizeOptions::propagate_in_place, kaldi::ReadBasicType(), NnetOptimizeOptions::remove_assignments, NnetOptimizeOptions::snip_row_ops, and NnetOptimizeOptions::split_row_ops.

Referenced by CachingOptimizingCompiler::ReadCache(), and NnetOptimizeOptions::Register().

30  {
31  ExpectToken(is, binary, "<NnetOptimizeOptions>");
32  ExpectToken(is, binary, "<Optimize>");
33  ReadBasicType(is, binary, &optimize);
34  ExpectToken(is, binary, "<ConsolidateModelUpdate>");
36  ExpectToken(is, binary, "<PropagateInPlace>");
37  ReadBasicType(is, binary, &propagate_in_place);
38  ExpectToken(is, binary, "<BackpropInPlace>");
39  ReadBasicType(is, binary, &backprop_in_place);
40  if (PeekToken(is, binary) == 'O') {
41  ExpectToken(is, binary, "<OptimizeRowOps>");
42  ReadBasicType(is, binary, &optimize_row_ops);
43  }
44  if (PeekToken(is, binary) == 'S') {
45  ExpectToken(is, binary, "<SplitRowOps>");
46  ReadBasicType(is, binary, &split_row_ops);
47  }
48  if (PeekToken(is, binary) == 'E') {
49  ExpectToken(is, binary, "<ExtendMatrices>");
50  ReadBasicType(is, binary, &extend_matrices);
51  }
52  ExpectToken(is, binary, "<ConvertAddition>");
53  ReadBasicType(is, binary, &convert_addition);
54  ExpectToken(is, binary, "<RemoveAssignments>");
55  ReadBasicType(is, binary, &remove_assignments);
56  ExpectToken(is, binary, "<AllowLeftMerge>");
57  ReadBasicType(is, binary, &allow_left_merge);
58  ExpectToken(is, binary, "<AllowRightMerge>");
59  ReadBasicType(is, binary, &allow_right_merge);
60  ExpectToken(is, binary, "<InitializeUndefined>");
61  ReadBasicType(is, binary, &initialize_undefined);
62  ExpectToken(is, binary, "<MoveSizingCommands>");
63  ReadBasicType(is, binary, &move_sizing_commands);
64  ExpectToken(is, binary, "<AllocateFromOther>");
65  ReadBasicType(is, binary, &allocate_from_other);
66  ExpectToken(is, binary, "<MinDerivTime>");
67  ReadBasicType(is, binary, &min_deriv_time);
68  ExpectToken(is, binary, "<MaxDerivTime>");
69  ReadBasicType(is, binary, &max_deriv_time);
70  if (PeekToken(is, binary) == 'M') {
71  ExpectToken(is, binary, "<MaxDerivTimeRelative>");
73  }
74  if (PeekToken(is, binary) == 'S') {
75  ExpectToken(is, binary, "<SnipRowOps>");
76  ReadBasicType(is, binary, &snip_row_ops);
77  }
78  if (PeekToken(is, binary) == 'M') {
79  ExpectToken(is, binary, "<MemoryCompressionLevel>");
81  }
82  ExpectToken(is, binary, "</NnetOptimizeOptions>");
83 }
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
int PeekToken(std::istream &is, bool binary)
PeekToken will return the first character of the next token, or -1 if end of file.
Definition: io-funcs.cc:170

◆ Register()

void Register ( OptionsItf opts)
inline

Definition at line 84 of file nnet-optimize.h.

References kaldi::nnet3::MaxOutputTimeInRequest(), NnetOptimizeOptions::operator==(), kaldi::nnet3::Optimize(), NnetOptimizeOptions::Read(), OptionsItf::Register(), and NnetOptimizeOptions::Write().

Referenced by BatchedXvectorComputerOptions::Register(), NnetTrainerOptions::Register(), NnetSimpleLoopedComputationOptions::Register(), NnetSimpleComputationOptions::Register(), and NnetComputeProbOptions::Register().

84  {
85  opts->Register("optimize", &optimize, "Set this to false to turn off all "
86  "optimizations");
87  opts->Register("consolidate-model-update", &consolidate_model_update,
88  "Set to false to disable optimization that consolidates "
89  "the model-update phase of backprop (e.g. for recurrent "
90  "architectures");
91  opts->Register("propagate-in-place", &propagate_in_place, "Set to false to "
92  "disable optimization that allows in-place propagation");
93  opts->Register("backprop-in-place", &backprop_in_place, "Set to false to "
94  "disable optimization that allows in-place backprop");
95  opts->Register("extend-matrices", &extend_matrices, "This optimization "
96  "can reduce memory requirements for TDNNs when applied "
97  "together with --convert-addition=true");
98  opts->Register("optimize-row-ops", &optimize_row_ops, "Set to false to "
99  "disable certain optimizations that act on operations of "
100  "type *Row*.");
101  opts->Register("split-row-ops", &split_row_ops, "Set to false to disable "
102  "an optimization that may replace some operations of type "
103  "kCopyRowsMulti or kAddRowsMulti with up to two simpler "
104  "operations.");
105  opts->Register("convert-addition", &convert_addition, "Set to false to "
106  "disable the optimization that converts Add commands into "
107  "Copy commands wherever possible.");
108  opts->Register("remove-assignments", &remove_assignments, "Set to false to "
109  "disable optimization that removes redundant assignments");
110  opts->Register("allow-left-merge", &allow_left_merge, "Set to false to "
111  "disable left-merging of variables in remove-assignments "
112  "(obscure option)");
113  opts->Register("allow-right-merge", &allow_right_merge, "Set to false to "
114  "disable right-merging of variables in remove-assignments "
115  "(obscure option)");
116  opts->Register("initialize-undefined", &initialize_undefined, "Set to false "
117  "to disable optimization that avoids redundant zeroing");
118  opts->Register("move-sizing-commands", &move_sizing_commands, "Set to false "
119  "to disable optimization that moves matrix allocation and "
120  "deallocation commands to conserve memory.");
121  opts->Register("allocate-from-other", &allocate_from_other, "Instead of "
122  "deleting a matrix of a given size and then allocating "
123  "a matrix of the same size, allow re-use of that memory");
124  opts->Register("min-deriv-time", &min_deriv_time, "You can set this to "
125  "the minimum t value that you want derivatives to be computed "
126  "at when updating the model. This is an optimization that "
127  "saves time in the backprop phase for recurrent frameworks");
128  opts->Register("max-deriv-time", &max_deriv_time, "You can set this to "
129  "the maximum t value that you want derivatives to be computed "
130  "at when updating the model. This is an optimization that "
131  "saves time in the backprop phase for recurrent frameworks");
132  opts->Register("max-deriv-time-relative", &max_deriv_time_relative,
133  "An alternative mechanism for setting the --max-deriv-time, "
134  "suitable for situations where the length of the egs is "
135  "variable. If set, it is equivalent to setting the "
136  "--max-deriv-time to this value plus the largest 't' value "
137  "in any 'output' node of the computation request.");
138  opts->Register("snip-row-ops", &snip_row_ops, "Set this to false to "
139  "disable an optimization that reduces the size of certain "
140  "per-row operations");
141  opts->Register("memory-compression-level", &memory_compression_level,
142  "This is only relevant to training, not decoding. Set this "
143  "to 0,1,2; higher levels are more aggressive at reducing "
144  "memory by compressing quantities needed for backprop, "
145  "potentially at the expense of speed and the accuracy "
146  "of derivatives. 0 means no compression at all; 1 means "
147  "compression that shouldn't affect results at all.");
148 
149  }

◆ Write()

void Write ( std::ostream &  os,
bool  binary 
) const

Definition at line 85 of file nnet-optimize.cc.

References NnetOptimizeOptions::allocate_from_other, NnetOptimizeOptions::allow_left_merge, NnetOptimizeOptions::allow_right_merge, NnetOptimizeOptions::backprop_in_place, NnetOptimizeOptions::consolidate_model_update, NnetOptimizeOptions::convert_addition, NnetOptimizeOptions::extend_matrices, NnetOptimizeOptions::initialize_undefined, NnetOptimizeOptions::max_deriv_time, NnetOptimizeOptions::max_deriv_time_relative, NnetOptimizeOptions::memory_compression_level, NnetOptimizeOptions::min_deriv_time, NnetOptimizeOptions::move_sizing_commands, NnetOptimizeOptions::optimize, NnetOptimizeOptions::optimize_row_ops, NnetOptimizeOptions::propagate_in_place, NnetOptimizeOptions::remove_assignments, NnetOptimizeOptions::snip_row_ops, NnetOptimizeOptions::split_row_ops, kaldi::WriteBasicType(), and kaldi::WriteToken().

Referenced by NnetOptimizeOptions::Register(), and CachingOptimizingCompiler::WriteCache().

85  {
86  WriteToken(os, binary, "<NnetOptimizeOptions>");
87  WriteToken(os, binary, "<Optimize>");
88  WriteBasicType(os, binary, optimize);
89  WriteToken(os, binary, "<ConsolidateModelUpdate>");
91  WriteToken(os, binary, "<PropagateInPlace>");
93  WriteToken(os, binary, "<BackpropInPlace>");
94  WriteBasicType(os, binary, backprop_in_place);
95  WriteToken(os, binary, "<OptimizeRowOps>");
96  WriteBasicType(os, binary, optimize_row_ops);
97  WriteToken(os, binary, "<SplitRowOps>");
98  WriteBasicType(os, binary, split_row_ops);
99  WriteToken(os, binary, "<ExtendMatrices>");
100  WriteBasicType(os, binary, extend_matrices);
101  WriteToken(os, binary, "<ConvertAddition>");
102  WriteBasicType(os, binary, convert_addition);
103  WriteToken(os, binary, "<RemoveAssignments>");
104  WriteBasicType(os, binary, remove_assignments);
105  WriteToken(os, binary, "<AllowLeftMerge>");
106  WriteBasicType(os, binary, allow_left_merge);
107  WriteToken(os, binary, "<AllowRightMerge>");
108  WriteBasicType(os, binary, allow_right_merge);
109  WriteToken(os, binary, "<InitializeUndefined>");
111  WriteToken(os, binary, "<MoveSizingCommands>");
113  WriteToken(os, binary, "<AllocateFromOther>");
114  WriteBasicType(os, binary, allocate_from_other);
115  WriteToken(os, binary, "<MinDerivTime>");
116  WriteBasicType(os, binary, min_deriv_time);
117  WriteToken(os, binary, "<MaxDerivTime>");
118  WriteBasicType(os, binary, max_deriv_time);
119  WriteToken(os, binary, "<MaxDerivTimeRelative>");
121  WriteToken(os, binary, "<SnipRowOps>");
122  WriteBasicType(os, binary, snip_row_ops);
123  WriteToken(os, binary, "<MemoryCompressionLevel>");
125  WriteToken(os, binary, "</NnetOptimizeOptions>");
126 }
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34

Member Data Documentation

◆ allocate_from_other

◆ allow_left_merge

◆ allow_right_merge

◆ backprop_in_place

◆ consolidate_model_update

◆ convert_addition

◆ extend_matrices

bool extend_matrices

◆ initialize_undefined

◆ max_deriv_time

◆ max_deriv_time_relative

◆ memory_compression_level

◆ min_deriv_time

◆ move_sizing_commands

◆ optimize

◆ optimize_looped_computation

bool optimize_looped_computation

Definition at line 60 of file nnet-optimize.h.

Referenced by kaldi::nnet3::CompileLoopedInternal(), and kaldi::nnet3::Optimize().

◆ optimize_row_ops

◆ propagate_in_place

◆ remove_assignments

◆ snip_row_ops

◆ split_row_ops


The documentation for this struct was generated from the following files: