nlpodyssey / cybertron

Cybertron: the home planet of the Transformers in Go
BSD 2-Clause "Simplified" License
280 stars 26 forks source link

Failure when target/passage text length > 2.5K chars #6

Closed Dabnis closed 9 months ago

Dabnis commented 1 year ago

System Info: Processor: Ryzen 7, 8 core RAM: 32Gb OS: Ubuntu 20.4 GO: 1.19.3

I am using the question&answer example, when I increase the size of the text to analyse (passage) I get failures as below:

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x751d32]

goroutine 1340 [running]: github.com/nlpodyssey/spago/ag.Node.Value({0x0, 0x0})

:1 +0x32 github.com/nlpodyssey/spago/ag/fn.(*Add[...]).Forward(0xc004d8fc00) /home/jonathan/go/pkg/mod/github.com/nlpodyssey/spago@v1.0.1/ag/fn/add.go:32 +0xcc github.com/nlpodyssey/spago/ag.(*Operator).forward(0xc0087f99a0) /home/jonathan/go/pkg/mod/github.com/nlpodyssey/spago@v1.0.1/ag/operator.go:191 +0x2f created by github.com/nlpodyssey/spago/ag.NewOperator /home/jonathan/go/pkg/mod/github.com/nlpodyssey/spago@v1.0.1/ag/operator.go:58 +0x199 Debugging shows that r.x2 has a nil value on 2nd line of func below ``` `// Forward computes the output of the function. func (r *Add[O]) Forward() mat.Matrix { x1v := r.x1.Value() x2v := r.x2.Value() // r.x2 == nil here if x1v == nil { x1v = x2v.ZerosLike() defer mat.ReleaseMatrix(x1v) } return x1v.Add(x2v) }` ``` I have tried adjusting GOMAXPROCS with no affect to the issue. My first question is: Is there a limit on the size of the text being analysed? The error above happens when passage size gets to ~ 2,550 characters.
jonny-d commented 1 year ago

Hello,

Curious if you ever found a solution to this? I am getting the same error with a text encoding model on mac.

jonathan-wondereur commented 1 year ago

I am also having this issue, I see a spike to ~20GB of RAM then this crash, I tried it on a VM with much more RAM and it still crashed with ~20GB of RAM so it is not an out of memory issue as I initially thought it might be. I am working on trying to find a simplified example of the crash.

I have the same issue on both Mac M1 and Linux AMD 64

jonathan-wondereur commented 1 year ago

It does seem to be related to the input string length. I seem to be getting this issue around ~1,100 characters of input.

jonny-d commented 1 year ago

In my case the problem was caused by exceeding the sequence length of the underlying BERT model which was 512 for the particular model I was using. I got around this issue by tokenizing the string directly using the model's Tokenize function (not forgetting to add special tokens), truncating the token slice and then passing the token slice to the model's Encode function.

Truncating the string directly will sometimes solve the issue because sometimes a string of a certain length, say 1000, will tokenize to a slice under the max sequence length and sometimes not, depending on the string.

matteo-grella commented 1 year ago

It should be solved in HEAD