Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NeoML] total clean-up in BaseLayer #1050

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[NeoML] total clean-up for BaseLayer
Signed-off-by: Kirill Golikov <kirill.golikov@abbyy.com>
  • Loading branch information
favorart committed Apr 23, 2024
commit b1e5b2b5948e978e0474500955720a9a2a1ad09b
4 changes: 2 additions & 2 deletions NeoML/include/NeoML/Dnn/Dnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class NEOML_API CBaseLayer : public virtual IObject {
virtual size_t GetOutputBlobsSize() const;

// Releases all temporary resources allocated for the layer
virtual void CleanUp();
virtual void CleanUp( bool totalCleanUp = false );

// Returns the total size of trainable parameters in this layer
// Returns the total size of trainable parameters of its internal layers, if layer is composite or recurrent
Expand Down Expand Up @@ -529,7 +529,7 @@ class NEOML_API CDnn : public CDnnLayerGraph {
void RunAndLearnOnce();

// Releases all temporary resources allocated for RunAndBackwardOnce()
void CleanUp();
void CleanUp( bool totalCleanUp = false );

// Gets the maximum sequence length
int GetMaxSequenceLength() const { return maxSequenceLength; }
Expand Down
2 changes: 1 addition & 1 deletion NeoML/include/NeoML/Dnn/Layers/CompositeLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NEOML_API CCompositeLayer : public CBaseLayer, public CDnnLayerGraph {
size_t GetOutputBlobsSize() const override;

// Releases all temporary resources allocated for the layer
void CleanUp() override;
void CleanUp( bool totalCleanUp = false ) override;

// Returns the total size of trainable parameters
size_t GetTrainableParametersSize() const override;
Expand Down
2 changes: 2 additions & 0 deletions NeoML/include/NeoML/Dnn/Layers/SinkLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NEOML_API CSinkLayer : public CBaseLayer {
// After each call to RunOnce this blob contains the results
const CPtr<CDnnBlob>& GetBlob() const;

void CleanUp( bool totalCleanUp = false ) override { CBaseLayer::CleanUp( totalCleanUp ); blob = nullptr; }

protected:
CPtr<CDnnBlob> blob;

Expand Down
17 changes: 16 additions & 1 deletion NeoML/src/Dnn/BaseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,27 @@ size_t CBaseLayer::GetOutputBlobsSize() const
return result;
}

void CBaseLayer::CleanUp()
void CBaseLayer::CleanUp( bool totalCleanUp )
{
inputBlobs.DeleteAll();
inputBlobs.SetSize(inputDescs.Size());
outputBlobs.DeleteAll();
outputBlobs.SetSize(outputDescs.Size());
allocatedBlobs = 0;

if ( totalCleanUp ) {
for( int cacheType = 0; cacheType < BCT_Count; ++cacheType ) {
blobCache[cacheType].DeleteAll();
}

inputDiffBlobs.DeleteAll();
outputDiffBlobs.DeleteAll();
paramDiffBlobs.DeleteAll();
readyOutputDiffs.DeleteAll();
clearAllRuntimeBlobs();

ForceReshape();
}
}

size_t CBaseLayer::GetTrainableParametersSize() const
Expand Down
4 changes: 2 additions & 2 deletions NeoML/src/Dnn/Dnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ void CDnn::RunAndLearnOnce()
solver->Train();
}

void CDnn::CleanUp()
void CDnn::CleanUp( bool totalCleanUp )
{
for( int i = 0; i < layers.Size(); i++ ) {
layers[i]->CleanUp();
layers[i]->CleanUp( totalCleanUp );
}
}

Expand Down
5 changes: 3 additions & 2 deletions NeoML/src/Dnn/Layers/CompositeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,11 @@ size_t CCompositeLayer::GetOutputBlobsSize() const
return result;
}

void CCompositeLayer::CleanUp()
void CCompositeLayer::CleanUp( bool totalCleanUp )
{
CBaseLayer::CleanUp( totalCleanUp );
for( int i = 0; i < internalDnn->layers.Size(); i++ ) {
internalDnn->layers[i]->CleanUp();
internalDnn->layers[i]->CleanUp( totalCleanUp );
}
}

Expand Down