vvanirudh:

hidden_states_weights[i] = attention_val


This is an in-place assignment. Most likely the best solution will be to accumulate the contents of hidden_states_weights as a list, then use torch.cat or torch.stack after the for loop to combine it together into a Tensor.