#include <nnet-component-itf.h>
Public Member Functions | |
NonlinearComponent () | |
NonlinearComponent (const NonlinearComponent &other) | |
virtual int32 | InputDim () const |
Returns input-dimension of this component. More... | |
virtual int32 | OutputDim () const |
Returns output-dimension of this component. More... | |
virtual void | InitFromConfig (ConfigLine *cfl) |
Initialize, from a ConfigLine object. More... | |
virtual void | Read (std::istream &is, bool binary) |
We implement Read at this level as it just needs the Type(). More... | |
virtual void | ZeroStats () |
Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero. More... | |
virtual std::string | Info () const |
Returns some text-form information about this component, for diagnostics. More... | |
virtual void | Write (std::ostream &os, bool binary) const |
Write component to stream. More... | |
virtual void | Scale (BaseFloat scale) |
This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when called by an UpdatableComponent. More... | |
virtual void | Add (BaseFloat alpha, const Component &other) |
This virtual function when called by – an UpdatableComponent adds the parameters of another updatable component, times some constant, to the current parameters. More... | |
virtual void | ConsolidateMemory () |
This virtual function relates to memory management, and avoiding fragmentation. More... | |
const CuVector< double > & | ValueSum () const |
const CuVector< double > & | DerivSum () const |
double | Count () const |
Public Member Functions inherited from Component | |
virtual void * | Propagate (const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const =0 |
Propagate function. More... | |
virtual void | Backprop (const std::string &debug_info, const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, const CuMatrixBase< BaseFloat > &out_deriv, void *memo, Component *to_update, CuMatrixBase< BaseFloat > *in_deriv) const =0 |
Backprop function; depending on which of the arguments 'to_update' and 'in_deriv' are non-NULL, this can compute input-data derivatives and/or perform model update. More... | |
virtual void | StoreStats (const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, void *memo) |
This function may store stats on average activation values, and for some component types, the average value of the derivative of the nonlinearity. More... | |
virtual void | GetInputIndexes (const MiscComputationInfo &misc_info, const Index &output_index, std::vector< Index > *desired_indexes) const |
This function only does something interesting for non-simple Components. More... | |
virtual bool | IsComputable (const MiscComputationInfo &misc_info, const Index &output_index, const IndexSet &input_index_set, std::vector< Index > *used_inputs) const |
This function only does something interesting for non-simple Components, and it exists to make it possible to manage optionally-required inputs. More... | |
virtual void | ReorderIndexes (std::vector< Index > *input_indexes, std::vector< Index > *output_indexes) const |
This function only does something interesting for non-simple Components. More... | |
virtual ComponentPrecomputedIndexes * | PrecomputeIndexes (const MiscComputationInfo &misc_info, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, bool need_backprop) const |
This function must return NULL for simple Components. More... | |
virtual std::string | Type () const =0 |
Returns a string such as "SigmoidComponent", describing the type of the object. More... | |
virtual int32 | Properties () const =0 |
Return bitmask of the component's properties. More... | |
virtual Component * | Copy () const =0 |
Copies component (deep copy). More... | |
virtual void | DeleteMemo (void *memo) const |
This virtual function only needs to be overwritten by Components that return a non-NULL memo from their Propagate() function. More... | |
Component () | |
virtual | ~Component () |
Protected Types | |
enum | { kUnsetThreshold = -1000 } |
Protected Member Functions | |
void | StoreStatsInternal (const CuMatrixBase< BaseFloat > &out_value, const CuMatrixBase< BaseFloat > *deriv=NULL) |
void | StoreBackpropStats (const CuMatrixBase< BaseFloat > &out_deriv) |
const NonlinearComponent & | operator= (const NonlinearComponent &other) |
Protected Attributes | |
int32 | dim_ |
int32 | block_dim_ |
CuVector< double > | value_sum_ |
CuVector< double > | deriv_sum_ |
double | count_ |
CuVector< double > | oderiv_sumsq_ |
double | oderiv_count_ |
double | num_dims_self_repaired_ |
double | num_dims_processed_ |
BaseFloat | self_repair_lower_threshold_ |
BaseFloat | self_repair_upper_threshold_ |
BaseFloat | self_repair_scale_ |
Friends | |
class | SigmoidComponent |
class | TanhComponent |
class | SoftmaxComponent |
class | LogSoftmaxComponent |
class | RectifiedLinearComponent |
Additional Inherited Members | |
Static Public Member Functions inherited from Component | |
static Component * | ReadNew (std::istream &is, bool binary) |
Read component from stream (works out its type). Dies on error. More... | |
static Component * | NewComponentOfType (const std::string &type) |
Returns a new Component of the given type e.g. More... | |
Definition at line 613 of file nnet-component-itf.h.
|
protected |
Definition at line 605 of file nnet-component-itf.cc.
|
explicit |
Definition at line 612 of file nnet-component-itf.cc.
This virtual function when called by – an UpdatableComponent adds the parameters of another updatable component, times some constant, to the current parameters.
– a NonlinearComponent (or another component that stores stats, like BatchNormComponent)– it relates to adding stats. Otherwise it will normally do nothing.
Reimplemented from Component.
Definition at line 459 of file nnet-component-itf.cc.
References NonlinearComponent::count_, NonlinearComponent::deriv_sum_, CuVectorBase< Real >::Dim(), KALDI_ASSERT, NonlinearComponent::num_dims_processed_, NonlinearComponent::num_dims_self_repaired_, NonlinearComponent::oderiv_count_, NonlinearComponent::oderiv_sumsq_, and NonlinearComponent::value_sum_.
|
virtual |
This virtual function relates to memory management, and avoiding fragmentation.
It is called only once per model, after we do the first minibatch of training. The default implementation does nothing, but it can be overridden by child classes, where it may re-initialize certain quantities that may possibly have been allocated during the forward pass (e.g. certain statistics; OnlineNaturalGradient objects). We use our own CPU-based allocator (see cu-allocator.h) and since it can't do paging since we're not in control of the GPU page table, fragmentation can be a problem. The allocator always tries to put things in 'low-address memory' (i.e. at smaller memory addresses) near the beginning of the block it allocated, to avoid fragmentation; but if permanent things (belonging to the model) are allocated in the forward pass, they can permanently stay in high memory. This function helps to prevent that, by re-allocating those things into low-address memory (It's important that it's called after all the temporary buffers for the forward-backward have been freed, so that there is low-address memory available)).
Reimplemented from Component.
Definition at line 636 of file nnet-component-itf.cc.
References NonlinearComponent::deriv_sum_, NonlinearComponent::oderiv_sumsq_, CuVector< Real >::Swap(), and NonlinearComponent::value_sum_.
|
inline |
Definition at line 647 of file nnet-component-itf.h.
|
inline |
Definition at line 645 of file nnet-component-itf.h.
|
virtual |
Returns some text-form information about this component, for diagnostics.
Starts with the type of the component. E.g. "SigmoidComponent dim=900", although most components will have much more info.
Reimplemented from Component.
Definition at line 409 of file nnet-component-itf.cc.
References VectorBase< Real >::ApplyFloor(), VectorBase< Real >::ApplyPow(), VectorBase< Real >::Scale(), kaldi::nnet3::SummarizeVector(), and Component::Type().
|
virtual |
Initialize, from a ConfigLine object.
[in] | cfl | A ConfigLine containing any parameters that are needed for initialization. For example: "dim=100 param-stddev=0.1" |
Implements Component.
Definition at line 623 of file nnet-component-itf.cc.
References NonlinearComponent::block_dim_, NonlinearComponent::dim_, ConfigLine::GetValue(), ConfigLine::HasUnusedValues(), KALDI_ERR, NonlinearComponent::self_repair_lower_threshold_, NonlinearComponent::self_repair_scale_, NonlinearComponent::self_repair_upper_threshold_, Component::Type(), and ConfigLine::WholeLine().
|
inlinevirtual |
Returns input-dimension of this component.
Implements Component.
Definition at line 619 of file nnet-component-itf.h.
|
protected |
|
inlinevirtual |
Returns output-dimension of this component.
Implements Component.
Definition at line 620 of file nnet-component-itf.h.
References kaldi::nnet3::ConsolidateMemory(), ComponentPrecomputedIndexes::Read(), and ComponentPrecomputedIndexes::Write().
|
virtual |
We implement Read at this level as it just needs the Type().
Implements Component.
Definition at line 481 of file nnet-component-itf.cc.
References kaldi::ExpectOneOrTwoTokens(), kaldi::nnet3::ExpectToken(), KALDI_ERR, kaldi::PeekToken(), kaldi::ReadBasicType(), kaldi::ReadToken(), and Component::Type().
|
virtual |
This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when called by an UpdatableComponent.
– a Nonlinear component (or another component that stores stats, like BatchNormComponent)– it relates to scaling activation stats, not parameters. Otherwise it will normally do nothing.
Reimplemented from Component.
Definition at line 449 of file nnet-component-itf.cc.
|
protected |
Definition at line 377 of file nnet-component-itf.cc.
References CuVectorBase< Real >::AddDiagMat2(), KALDI_ASSERT, kaldi::kTrans, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and kaldi::RandInt().
Referenced by SigmoidComponent::Backprop(), TanhComponent::Backprop(), RectifiedLinearComponent::Backprop(), SoftmaxComponent::Backprop(), and LogSoftmaxComponent::Backprop().
|
protected |
Definition at line 349 of file nnet-component-itf.cc.
References CuVectorBase< Real >::AddRowSumMat(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuMatrixBase< Real >::NumCols(), and CuMatrixBase< Real >::NumRows().
|
inline |
Definition at line 644 of file nnet-component-itf.h.
|
virtual |
Write component to stream.
Implements Component.
Definition at line 546 of file nnet-component-itf.cc.
References VectorBase< Real >::ApplyFloor(), VectorBase< Real >::ApplyPow(), VectorBase< Real >::CopyFromVec(), Vector< Real >::Resize(), VectorBase< Real >::Scale(), Component::Type(), VectorBase< Real >::Write(), kaldi::WriteBasicType(), and kaldi::WriteToken().
|
virtual |
Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero.
Other components that store other types of statistics (e.g. regarding gradient clipping) should implement ZeroStats() also.
Reimplemented from Component.
Definition at line 399 of file nnet-component-itf.cc.
|
friend |
Definition at line 655 of file nnet-component-itf.h.
|
friend |
Definition at line 656 of file nnet-component-itf.h.
|
friend |
Definition at line 652 of file nnet-component-itf.h.
|
friend |
Definition at line 654 of file nnet-component-itf.h.
|
friend |
Definition at line 653 of file nnet-component-itf.h.
|
protected |
Definition at line 678 of file nnet-component-itf.h.
Referenced by NonlinearComponent::InitFromConfig().
|
protected |
Definition at line 684 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add().
|
protected |
Definition at line 680 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add(), and NonlinearComponent::ConsolidateMemory().
|
protected |
Definition at line 673 of file nnet-component-itf.h.
Referenced by NonlinearComponent::InitFromConfig().
|
protected |
Definition at line 695 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add(), SigmoidComponent::RepairGradients(), TanhComponent::RepairGradients(), and RectifiedLinearComponent::RepairGradients().
|
protected |
Definition at line 694 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add(), SigmoidComponent::RepairGradients(), TanhComponent::RepairGradients(), and RectifiedLinearComponent::RepairGradients().
|
protected |
Definition at line 691 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add().
|
protected |
Definition at line 686 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add(), and NonlinearComponent::ConsolidateMemory().
|
protected |
Definition at line 698 of file nnet-component-itf.h.
Referenced by NonlinearComponent::InitFromConfig().
|
protected |
Definition at line 700 of file nnet-component-itf.h.
Referenced by NonlinearComponent::InitFromConfig().
|
protected |
Definition at line 699 of file nnet-component-itf.h.
Referenced by NonlinearComponent::InitFromConfig().
|
protected |
Definition at line 679 of file nnet-component-itf.h.
Referenced by NonlinearComponent::Add(), and NonlinearComponent::ConsolidateMemory().