Abstract base-class for neural-net components. More...
#include <nnet-component-itf.h>
Public Member Functions | |
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 | ZeroStats () |
Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero. 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 void | InitFromConfig (ConfigLine *cfl)=0 |
Initialize, from a ConfigLine object. More... | |
virtual int32 | InputDim () const =0 |
Returns input-dimension of this component. More... | |
virtual int32 | OutputDim () const =0 |
Returns output-dimension of this component. 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 | Read (std::istream &is, bool binary)=0 |
Read function (used after we know the type of the Component); accepts input that is missing the token that describes the component type, in case it has already been consumed. More... | |
virtual void | Write (std::ostream &os, bool binary) const =0 |
Write component to stream. More... | |
virtual std::string | Info () const |
Returns some text-form information about this component, for diagnostics. 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 | 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... | |
virtual void | ConsolidateMemory () |
This virtual function relates to memory management, and avoiding fragmentation. More... | |
Component () | |
virtual | ~Component () |
Static Public Member Functions | |
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... | |
Private Member Functions | |
KALDI_DISALLOW_COPY_AND_ASSIGN (Component) | |
Abstract base-class for neural-net components.
Definition at line 114 of file nnet-component-itf.h.
|
inline |
Definition at line 396 of file nnet-component-itf.h.
|
inlinevirtual |
Definition at line 398 of file nnet-component-itf.h.
References KALDI_DISALLOW_COPY_AND_ASSIGN.
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 in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, LinearComponent, NaturalGradientAffineComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, TdnnComponent, TdnnComponent, BackpropTruncationComponent, AffineComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, BatchNormComponent, ConvolutionComponent, and RestrictedAttentionComponent.
Definition at line 370 of file nnet-component-itf.h.
Referenced by kaldi::nnet3::AddNnet(), kaldi::nnet3::AddNnetComponents(), kaldi::nnet3::ApplyL2Regularization(), BatchNormComponent::Copy(), ClipGradientComponent::Copy(), ScaleAndOffsetComponent::Copy(), ConstantComponent::IsComputable(), LinearComponent::LinearComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), AffineComponent::Properties(), BackpropTruncationComponent::Properties(), BlockAffineComponent::Properties(), RepeatedAffineComponent::Properties(), PerElementScaleComponent::Properties(), PerElementOffsetComponent::Properties(), ConstantFunctionComponent::Properties(), kaldi::nnet3::TestNnetComponentAddScale(), and CompositeComponent::Type().
|
pure virtual |
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.
[in] | debug_info | The component name, to be printed out in any warning messages. |
[in] | indexes | A pointer to some information output by this class's PrecomputeIndexes function (will be NULL for simple components, i.e. those that don't do things like splicing). |
[in] | in_value | The matrix that was given as input to the Propagate function. Will be ignored (and may be empty) if Properties()&kBackpropNeedsInput == 0. |
[in] | out_value | The matrix that was output from the Propagate function. Will be ignored (and may be empty) if Properties()&kBackpropNeedsOutput == 0 |
[in] | out_deriv | The derivative at the output of this component. |
[in] | memo | This will normally be NULL, but for component types that set the flag kUsesMemo, this will be the return value of the Propagate() function that corresponds to this Backprop() function. Ownership of any pointers is not transferred to the Backprop function; DeleteMemo() will be called to delete it. |
[out] | to_update | If model update is desired, the Component to be updated, else NULL. Does not have to be identical to this. If supplied, you can assume that to_update->Properties() & kUpdatableComponent is nonzero. |
[out] | in_deriv | The derivative at the input of this component, if needed (else NULL). If Properties()&kBackpropInPlace, may be the same matrix as out_deriv. If Properties()&kBackpropAdds, this is added to by the Backprop routine, else it is set. The component code chooses which mode to work in, based on convenience. |
Implemented in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, LstmNonlinearityComponent, TanhComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by NnetComputer::ExecuteCommand(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().
|
inlinevirtual |
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 in ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, LinearComponent, NaturalGradientAffineComponent, ConstantComponent, NaturalGradientRepeatedAffineComponent, NonlinearComponent, TdnnComponent, TdnnComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, and TimeHeightConvolutionComponent.
Definition at line 394 of file nnet-component-itf.h.
Referenced by kaldi::nnet3::ConsolidateMemory(), ConstantComponent::IsComputable(), LinearComponent::LinearComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), ScaleAndOffsetComponent::NumParameters(), LstmNonlinearityComponent::Properties(), ConstantFunctionComponent::Properties(), NaturalGradientRepeatedAffineComponent::Type(), and NaturalGradientPerElementScaleComponent::Type().
|
pure virtual |
Copies component (deep copy).
Implemented in CompositeComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, NaturalGradientRepeatedAffineComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, LstmNonlinearityComponent, RectifiedLinearComponent, TanhComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, SigmoidComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, DistributeComponent, NormalizeComponent, and PnormComponent.
Referenced by ModelCollapser::GetDiagonallyPreModifiedComponentIndex(), ModelCollapser::GetScaledComponentIndex(), kaldi::nnet3::TestNnetComponentAddScale(), kaldi::nnet3::TestNnetComponentCopy(), kaldi::nnet3::TestNnetComponentUpdatable(), kaldi::nnet3::TestNnetComponentVectorizeUnVectorize(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().
|
inlinevirtual |
This virtual function only needs to be overwritten by Components that return a non-NULL memo from their Propagate() function.
It's called by NnetComputer in cases where Propagate returns a memo but there will be no backprop to consume it.
Reimplemented in SpecAugmentTimeMaskComponent, GeneralDropoutComponent, BatchNormComponent, and RestrictedAttentionComponent.
Definition at line 376 of file nnet-component-itf.h.
References KALDI_ASSERT.
Referenced by NnetComputer::ExecuteCommand(), NnetComputer::SaveMemo(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().
|
virtual |
This function only does something interesting for non-simple Components.
For a given index at the output of the component, tells us what indexes are required at its input (note: "required" encompasses also optionally-required things; it will enumerate all things that we'd like to have). See also IsComputable().
[in] | misc_info | This argument is supplied to handle things that the framework can't very easily supply: information like which time indexes are needed for AggregateComponent, which time-indexes are available at the input of a recurrent network, and so on. We will add members to misc_info as needed. |
[in] | output_index | The Index at the output of the component, for which we are requesting the list of indexes at the component's input. |
[out] | desired_indexes | A list of indexes that are desired at the input. are to be written to here. By "desired" we mean required or optionally-required. |
The default implementation of this function is suitable for any SimpleComponent; it just copies the output_index to a single identical element in input_indexes.
Reimplemented in DropoutMaskComponent, ConstantComponent, TdnnComponent, TdnnComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.
Definition at line 206 of file nnet-component-itf.cc.
Referenced by ComputationGraphBuilder::AddDependencies(), and kaldi::nnet3::ComputeComputationGraph().
|
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 in CompositeComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, UpdatableComponent, BackpropTruncationComponent, BlockAffineComponent, MaxpoolingComponent, TdnnComponent, TdnnComponent, AffineComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, BatchNormComponent, DropoutComponent, ConvolutionComponent, RestrictedAttentionComponent, and NormalizeComponent.
Definition at line 199 of file nnet-component-itf.cc.
References ComponentPrecomputedIndexes::Type().
Referenced by PermuteComponent::Add(), NoOpComponent::Copy(), ClipGradientComponent::Copy(), FixedAffineComponent::Info(), FixedScaleComponent::Info(), FixedBiasComponent::Info(), LinearComponent::LinearComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), AffineComponent::OrthonormalConstraint(), DropoutComponent::OutputDim(), BlockAffineComponent::OutputDim(), RepeatedAffineComponent::OutputDim(), ConstantComponent::OutputDim(), DropoutMaskComponent::OutputDim(), GeneralDropoutComponent::OutputDim(), SpecAugmentTimeMaskComponent::OutputDim(), SumBlockComponent::OutputDim(), PerElementScaleComponent::OutputDim(), PerElementOffsetComponent::OutputDim(), ConstantFunctionComponent::OutputDim(), ScaleAndOffsetComponent::OutputDim(), BackpropTruncationComponent::Properties(), kaldi::nnet3::TestNnetComponentAddScale(), kaldi::nnet3::TestNnetComponentCopy(), FixedAffineComponent::Type(), FixedScaleComponent::Type(), FixedBiasComponent::Type(), and kaldi::nnet3::UnitTestNnetComponent().
|
pure 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" |
Implemented in CompositeComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by kaldi::nnet3::GenerateRandomSimpleComponent(), CompositeComponent::InitFromConfig(), and Nnet::ProcessComponentConfigLine().
|
pure virtual |
Returns input-dimension of this component.
Implemented in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by Nnet::Check(), ComputationChecker::CheckComputationIndexes(), UpdatableComponent::Info(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().
|
virtual |
This function only does something interesting for non-simple Components, and it exists to make it possible to manage optionally-required inputs.
It tells the user whether a given output index is computable from a given set of input indexes, and if so, says which input indexes will be used in the computation.
Implementations of this function are required to have the property that adding an element to "input_index_set" can only ever change IsComputable from false to true, never vice versa.
[in] | misc_info | Some information specific to the computation, such as minimum and maximum times for certain components to do adaptation on; it's a place to put things that don't easily fit in the framework. |
[in] | output_index | The index that is to be computed at the output of this Component. |
[in] | input_index_set | The set of indexes that is available at the input of this Component. |
[out] | used_inputs | If this is non-NULL and the output is computable this will be set to the list of input indexes that will actually be used in the computation. |
The default implementation of this function is suitable for any SimpleComponent: it just returns true if output_index is in input_index_set, and if so sets used_inputs to vector containing that one Index.
Reimplemented in DropoutMaskComponent, ConstantComponent, TdnnComponent, TdnnComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.
Definition at line 213 of file nnet-component-itf.cc.
Referenced by ComputationGraphBuilder::ComputeComputableInfo(), and ComputationGraphBuilder::PruneDependencies().
|
private |
Referenced by SumGroupComponent::Properties().
|
static |
Returns a new Component of the given type e.g.
"SoftmaxComponent", or NULL if no such component type exists.
Definition at line 98 of file nnet-component-itf.cc.
References KALDI_ASSERT, and Component::Type().
Referenced by kaldi::nnet3::GenerateRandomSimpleComponent(), CompositeComponent::InitFromConfig(), and Nnet::ProcessComponentConfigLine().
|
pure virtual |
Returns output-dimension of this component.
Implemented in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by ComputationChecker::CheckComputationIndexes(), NetworkNode::Dim(), UpdatableComponent::Info(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().
|
inlinevirtual |
This function must return NULL for simple Components.
Returns a pointer to a class that may contain some precomputed component-specific and computation-specific indexes to be in used in the Propagate and Backprop functions.
[in] | misc_info | This argument is supplied to handle things that the framework can't very easily supply: information like which time indexes are needed for AggregateComponent, which time-indexes are available at the input of a recurrent network, and so on. misc_info may not even ever be used here. We will add members to misc_info as needed. |
[in] | input_indexes | A vector of indexes that explains what time-indexes (and other indexes) each row of the in/in_value/in_deriv matrices given to Propagate and Backprop will mean. |
[in] | output_indexes | A vector of indexes that explains what time-indexes (and other indexes) each row of the out/out_value/out_deriv matrices given to Propagate and Backprop will mean. |
[in] | need_backprop | True if we might need to do backprop with this component, so that if any different indexes are needed for backprop then those should be computed too. |
Reimplemented in SpecAugmentTimeMaskComponent, GeneralDropoutComponent, TdnnComponent, TdnnComponent, BackpropTruncationComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.
Definition at line 302 of file nnet-component-itf.h.
References ComponentPrecomputedIndexes::Copy(), ComponentPrecomputedIndexes::Read(), ComponentPrecomputedIndexes::ReadNew(), ComponentPrecomputedIndexes::Type(), and ComponentPrecomputedIndexes::Write().
Referenced by ComputationExpander::ComputePrecomputedIndexes(), kaldi::nnet3::GetPrecomputedIndexes(), and Compiler::SetUpPrecomputedIndexes().
|
pure virtual |
Propagate function.
[in] | indexes | A pointer to some information output by this class's PrecomputeIndexes function (will be NULL for simple components, i.e. those that don't do things like splicing). |
[in] | in | The input to this component. Num-columns == InputDim(). |
[out] | out | The output of this component. Num-columns == OutputDim(). Note: output of this component will be added to the initial value of "out" if Properties()&kPropagateAdds != 0; otherwise the output will be set and the initial value ignored. Each Component chooses whether it is more convenient implementation-wise to add or set, and the calling code has to deal with it. |
Implemented in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, LstmNonlinearityComponent, TanhComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by NnetComputer::ExecuteCommand(), FixedBiasComponent::OutputDim(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().
|
pure virtual |
Return bitmask of the component's properties.
These properties depend only on the component's type. See enum ComponentProperties.
Implemented in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, LstmNonlinearityComponent, TanhComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by Compiler::AddBackwardStepComponent(), Compiler::AddForwardStepComponent(), kaldi::nnet3::AddNnetComponents(), kaldi::nnet3::ApplyL2Regularization(), ComputationChecker::CheckComputationIndexes(), kaldi::nnet3::ComponentDotProducts(), kaldi::nnet3::ComputeCommandAttributes(), Compiler::ComputeDerivNeeded(), ModelUpdateConsolidator::ConsolidateModelUpdate(), ModelUpdateConsolidator::ConsolidateUpdateForComponent(), NnetComputer::DebugAfterExecute(), NnetComputer::DebugBeforeExecute(), kaldi::nnet3::DotProduct(), NnetComputer::ExecuteCommand(), kaldi::nnet3::FreezeNaturalGradient(), kaldi::nnet3::GetPrecomputedIndexes(), Compiler::GetStrideType(), CompositeComponent::InitFromConfig(), VariableMergingOptimizer::MergeVariables(), DerivativeTimeLimiter::ModifyCommand(), kaldi::nnet3::NnetParametersAreIdentical(), kaldi::nnet3::NumParameters(), kaldi::nnet3::NumUpdatableComponents(), kaldi::nnet3::PerturbParams(), MaxChangeStats::Print(), kaldi::nnet3::PrintVectorPerUpdatableComponent(), ComputationStepsComputer::ProcessComponentStep(), kaldi::nnet3::SetLearningRate(), kaldi::nnet3::SetNnetAsGradient(), kaldi::nnet3::TestNnetComponentUpdatable(), kaldi::nnet3::TestNnetComponentVectorizeUnVectorize(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), kaldi::nnet3::TestSimpleComponentPropagateProperties(), kaldi::nnet3::UnVectorizeNnet(), kaldi::nnet3::UpdateNnetWithMaxChange(), and kaldi::nnet3::VectorizeNnet().
|
pure virtual |
Read function (used after we know the type of the Component); accepts input that is missing the token that describes the component type, in case it has already been consumed.
Implemented in CompositeComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by Component::ReadNew().
Read component from stream (works out its type). Dies on error.
Definition at line 84 of file nnet-component-itf.cc.
References KALDI_ERR, Component::Read(), and kaldi::ReadToken().
Referenced by Nnet::Read(), CompositeComponent::Read(), and kaldi::nnet3::TestNnetComponentIo().
|
inlinevirtual |
This function only does something interesting for non-simple Components.
It provides an opportunity for a Component to reorder the or pad the indexes at its input and output. This might be useful, for instance, if a component requires a particular ordering of the indexes that doesn't correspond to their natural ordering. Components that might modify the indexes are required to return the kReordersIndexes flag in their Properties(). The ReorderIndexes() function is now allowed to insert blanks into the indexes. The 'blanks' must be of the form (n,kNoTime,x), where the marker kNoTime (a very negative number) is there where the 't' indexes normally live. The reason we don't just have, say, (-1,-1,-1), relates to the need to preserve a regular pattern over the 'n' indexes so that 'shortcut compilation' (c.f. ExpandComputation()) can work correctly
[in,out] | Indexes | at the input of the Component. |
[in,out] | Indexes | at the output of the Component |
Reimplemented in TdnnComponent, TdnnComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, and RestrictedAttentionComponent.
Definition at line 272 of file nnet-component-itf.h.
Referenced by StatisticsExtractionComponent::Copy(), StatisticsPoolingComponent::Copy(), kaldi::nnet3::GetPrecomputedIndexes(), and ComputationStepsComputer::ProcessComponentStep().
|
inlinevirtual |
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 in CompositeComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, LinearComponent, NaturalGradientAffineComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, TdnnComponent, TdnnComponent, BackpropTruncationComponent, AffineComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, BatchNormComponent, ConvolutionComponent, and RestrictedAttentionComponent.
Definition at line 360 of file nnet-component-itf.h.
Referenced by BatchNormComponent::Copy(), ClipGradientComponent::Copy(), ScaleAndOffsetComponent::Copy(), ConstantComponent::IsComputable(), LinearComponent::LinearComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), AffineComponent::Properties(), BackpropTruncationComponent::Properties(), BlockAffineComponent::Properties(), RepeatedAffineComponent::Properties(), PerElementScaleComponent::Properties(), PerElementOffsetComponent::Properties(), ConstantFunctionComponent::Properties(), kaldi::nnet3::ScaleNnet(), kaldi::nnet3::TestNnetComponentAddScale(), kaldi::nnet3::TestNnetComponentUpdatable(), kaldi::nnet3::TestNnetComponentVectorizeUnVectorize(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and CompositeComponent::Type().
|
inlinevirtual |
This function may store stats on average activation values, and for some component types, the average value of the derivative of the nonlinearity.
It only does something for those components that have nonzero Properties()&kStoresStats.
[in] | in_value | The input to the Propagate() function. Note: if the component sets the flag kPropagateInPlace, this should not be used; the empty matrix will be provided here if in-place propagation was used. |
[in] | out_value | The output of the Propagate() function. |
[in] | memo | The 'memo' returned by the Propagate() function; this will usually be NULL. |
Reimplemented in SoftmaxComponent, RectifiedLinearComponent, TanhComponent, SigmoidComponent, BatchNormComponent, and RestrictedAttentionComponent.
Definition at line 186 of file nnet-component-itf.h.
Referenced by CompositeComponent::Backprop(), SigmoidComponent::Copy(), BatchNormComponent::DeleteMemo(), NnetComputer::ExecuteCommand(), TanhComponent::Properties(), RectifiedLinearComponent::Properties(), and SoftmaxComponent::Properties().
|
pure virtual |
Returns a string such as "SigmoidComponent", describing the type of the object.
Implemented in CompositeComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, NaturalGradientRepeatedAffineComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, LstmNonlinearityComponent, TanhComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by ComputationChecker::CheckComputationCompression(), kaldi::nnet3::ConvertRepeatedToBlockAffine(), UpdatableComponent::Info(), NonlinearComponent::Info(), NonlinearComponent::InitFromConfig(), CompositeComponent::InitFromConfig(), Component::NewComponentOfType(), kaldi::nnet3::NnetParametersAreIdentical(), MemoryCompressionOptimizer::ProcessMatrix(), NonlinearComponent::Read(), UpdatableComponent::ReadUpdatableCommon(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), kaldi::nnet3::TestSimpleComponentPropagateProperties(), kaldi::nnet3::UnitTestConvertRepeatedToBlockAffine(), kaldi::nnet3::UnitTestConvertRepeatedToBlockAffineComposite(), NonlinearComponent::Write(), and UpdatableComponent::WriteUpdatableCommon().
|
pure virtual |
Write component to stream.
Implemented in CompositeComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, SpecAugmentTimeMaskComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, MaxpoolingComponent, BackpropTruncationComponent, TdnnComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, LstmNonlinearityComponent, TimeHeightConvolutionComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, ConvolutionComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.
Referenced by kaldi::nnet3::TestNnetComponentIo().
|
inlinevirtual |
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 in CompositeComponent, PermuteComponent, ClipGradientComponent, NonlinearComponent, BackpropTruncationComponent, LstmNonlinearityComponent, BatchNormComponent, and RestrictedAttentionComponent.
Definition at line 195 of file nnet-component-itf.h.
Referenced by BatchNormComponent::Copy(), LstmNonlinearityComponent::Properties(), BackpropTruncationComponent::Properties(), ClipGradientComponent::Properties(), CompositeComponent::Type(), kaldi::nnet3::ZeroComponentStats(), and CompositeComponent::ZeroStats().