Skip to content

Is there any function or method that clears the cached memory during the process? #96

Answered by sugarme
luxiant asked this question in Q&A
Discussion options

You must be logged in to vote

@luxiant ,

Nice memory profile graph! In general, I would create a simple inference example on CPU device and run for-loop input through it to check for any memory leak inside the model.

Just have a quick look at your inference function and there a potential mem leak there:

func (m *customModel) bertSentimentProcess(dataframe dataframe.DataFrame) sentimentRow {
	var logit []float64
	ts.NoGrad(func() {
		torchResult, _, _ := m.bertModel.ForwardT(
                        // a new tensor is created by calling this function. Then no where you delete it.
			processSentenceIntoInput(m.tokenizer, dataframe.Col("text").Records()[0]), // <-- this is the leak
			ts.None,
			ts.None,
			ts.None,
			ts.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@luxiant
Comment options

Comment options

You must be logged in to vote
2 replies
@luxiant
Comment options

@luxiant
Comment options

Answer selected by luxiant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants