Skip to content

Commit

Permalink
[NeoML] fix CTransformerEncoderLayer reconstruction in change preNorm (
Browse files Browse the repository at this point in the history
…#1055)

Signed-off-by: Kirill Golikov <kirill.golikov@abbyy.com>
  • Loading branch information
favorart committed Apr 26, 2024
1 parent fafb496 commit 6ccc1da
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions NeoML/src/Dnn/Layers/TransformerLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,30 @@ void CTransformerEncoderLayer::Serialize( CArchive& archive )

void CTransformerEncoderLayer::SetPreNorm( bool _preNorm )
{
preNorm = _preNorm;
DeleteAllLayers();
if( preNorm != _preNorm ) {
preNorm = _preNorm;

const auto headCount = GetHeadCount();
const auto hiddenSize = GetHiddenSize();
const auto dropoutRate = GetDropoutRate();
const auto attentionDropoutRate = GetSelfAttentionDropoutRate();
const auto feedForwardSize = GetFeedForwardSize();
const auto maskType = GetMaskType();

const auto& activationLayer = dynamic_cast<const IActivationLayer&>( *GetLayer( activationName ) );
const auto activation = activationLayer.GetDesc();

DeleteAllLayers();
buildLayer();

SetHeadCount( headCount );
SetHiddenSize( hiddenSize );
SetDropoutRate( dropoutRate );
SetSelfAttentionDropoutRate( attentionDropoutRate );
SetFeedForwardSize( feedForwardSize );
SetMaskType( maskType );
SetActivation( activation );
}
}

void CTransformerEncoderLayer::SetHeadCount( int headCount )
Expand Down

0 comments on commit 6ccc1da

Please sign in to comment.