# LongFormer inplace modification error

**URL:** <https://discuss.huggingface.co/t/longformer-inplace-modification-error/8708>\
**Category:** Models\
**Created:** [July 26, 2021, 8:38pm UTC](https://discuss.huggingface.co/t/longformer-inplace-modification-error/8708 "2021-07-26T20:38:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sb1](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sb1](https://discuss.huggingface.co/u/sb1)\
**Post date:** [July 26, 2021, 8:38pm UTC](https://discuss.huggingface.co/t/longformer-inplace-modification-error/8708/1 "2021-07-26T20:38:54Z")

</div>

I keep getting this error “one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [12, 4096, 159]], which is output 0 of ViewBackward, is at version 1; expected version 0 instead”  
Here is the code where I specify the global attention mask I feed into longformer:  
attention\_mask = mask\_src  
cls\_ids = clss.detach().cpu().data.numpy()  
global\_attention\_mask = torch.zeros(src.shape,dtype=torch.long,device=src.device)  
global\_attention\_mask\_curr = global\_attention\_mask.clone()  
global\_attention\_mask\_curr[:,cls\_ids] = 1  
I realize that global\_attention\_mask\_curr[:,cls\_ids] = 1 is an inplace operation as I’m setting specific indices to 1s. However in the example, you do pretty much exactly the same thing. How do I get around this error. (Btw if I comment out global\_attention\_mask\_curr[:,cls\_ids] = 1, it trains just fine.)
