RuntimeError: index 2512 is out of bounds for dimension 0 with size 2512

username: monee_h.a
cooked: <p>Hi</p>
<p>I am getting the following error:<br>
RuntimeError: index 2512 is out of bounds for dimension 0 with size 2512</p>
<p>Here is the full troubleshooting:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/5/153fa213fafdd439b9f889e04ecc642ef66a09fa.png" data-download-href="https://discuss.pytorch.org/uploads/default/153fa213fafdd439b9f889e04ecc642ef66a09fa" title="Screen Shot 2021-05-27 at 10.45.28 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/153fa213fafdd439b9f889e04ecc642ef66a09fa_2_690x397.png" alt="Screen Shot 2021-05-27 at 10.45.28 PM" data-base62-sha1="31YmkCQUzl2YxXlAJBNGt01rqWe" width="690" height="397" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/153fa213fafdd439b9f889e04ecc642ef66a09fa_2_690x397.png, https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/153fa213fafdd439b9f889e04ecc642ef66a09fa_2_1035x595.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/153fa213fafdd439b9f889e04ecc642ef66a09fa_2_1380x794.png 2x" data-dominant-color="F0EFF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-05-27 at 10.45.28 PM</span><span class="informations">2012×1160 383 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Here is what I have in data:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/9/b958980c2dc120a74dd0f9baca1b39aa1054f3a0.png" data-download-href="https://discuss.pytorch.org/uploads/default/b958980c2dc120a74dd0f9baca1b39aa1054f3a0" title="Screen Shot 2021-05-27 at 10.59.38 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/9/b958980c2dc120a74dd0f9baca1b39aa1054f3a0_2_690x144.png" alt="Screen Shot 2021-05-27 at 10.59.38 PM" data-base62-sha1="qrE8UfrbnbUvwuucR702B0f3TDW" width="690" height="144" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/9/b958980c2dc120a74dd0f9baca1b39aa1054f3a0_2_690x144.png, https://discuss.pytorch.org/uploads/default/original/3X/b/9/b958980c2dc120a74dd0f9baca1b39aa1054f3a0.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/9/b958980c2dc120a74dd0f9baca1b39aa1054f3a0.png 2x" data-dominant-color="EDEDED"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-05-27 at 10.59.38 PM</span><span class="informations">1010×212 24.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I would appreciate your help. Thank you!</p>

username: ptrblck
cooked: <p>The index error is raised, since an index of <code>2512</code> is invalid for a shape of <code>2512</code>, which would accept indices in <code>[0, 2511]</code>, so you would have to check how this index is created and if you could clip it to the valid range.</p>

username: monee_h.a
cooked: <p>Thank you for your reply. I am still getting this error and not sure how to fix it, here is my code:</p>
<p>if <strong>name</strong> == “<strong>main</strong>”:<br>
<span class="hashtag-raw">#process</span> &amp; create the dataset files<br>
parser = argparse.ArgumentParser()</p>
<pre><code># system
parser.add_argument("--feature", type=str, default="glove", help="glove | all")
#no use of user_type for now
parser.add_argument("--user_type", type=str, default="hate", help="hate | suspend")
parser.add_argument("--model_type", type=str, default="sage", help="sage | gat")
parser.add_argument("--epoch", type=int, default=201)
args = parser.parse_args()
assert(args.feature in ['glove', 'all'])
assert(args.user_type in ['hate', 'suspend'])
assert(args.model_type in ['sage', 'gat'])
print("====information of experiment====")
print("FEATURE: ", args.feature, "classification_type:", args.user_type, "MODEL:", args.model_type)
print("====end information of experiment====")
dataset = construct_dataset(args.feature)
model_type = args.model_type
index0, index1, index2,index3,index4,index5,index6,index7,index8,index9,index10,index11,index12,index13,index14,index15,index16,index17,index18,index19,index20,index21,index22,index23,index24,index25,index26,index27,index28 = get_labeled_index(feature_type=args.feature)
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=123)
#y_all = [2] * len(hate_index)
y_all = [0] * len(index0)

#y_normal = [0] * len(normal_index)
y_1 = [1] * len(index1)
y_2 = [2] * len(index2)
y_3 = [3] * len(index3)
y_4 = [4] * len(index4)
y_5 = [5] * len(index5)
y_6 = [6] * len(index6)
y_7 = [7] * len(index7)
y_8 = [8] * len(index8)
y_9 = [9] * len(index9)
y_10 = [10] * len(index10)
y_11 = [11] * len(index11)
y_12 = [12] * len(index12)
y_13 = [13] * len(index13)
y_14 = [14] * len(index14)
y_15 = [15] * len(index15)
y_16 = [16] * len(index16)
y_17 = [17] * len(index17)
y_18 = [18] * len(index18)
y_19 = [19] * len(index19)
y_20 = [20] * len(index20)
y_21 = [21] * len(index21)
y_22 = [22] * len(index22)
y_23 = [23] * len(index23)
y_24 = [24] * len(index24)
y_25 = [25] * len(index25)
y_26 = [26] * len(index26)
y_27 = [27] * len(index27)
y_28 = [28] * len(index28)


#y_all.extend(y_normal)
y_all.extend(y_1)
y_all.extend(y_2)
y_all.extend(y_3)
y_all.extend(y_4)
y_all.extend(y_5)
y_all.extend(y_6)
y_all.extend(y_7)
y_all.extend(y_8)
y_all.extend(y_9)
y_all.extend(y_10)
y_all.extend(y_11)
y_all.extend(y_12)
y_all.extend(y_13)
y_all.extend(y_14)
y_all.extend(y_15)
y_all.extend(y_16)
y_all.extend(y_17)
y_all.extend(y_18)
y_all.extend(y_19)
y_all.extend(y_20)
y_all.extend(y_21)
y_all.extend(y_22)
y_all.extend(y_23)
y_all.extend(y_24)
y_all.extend(y_25)
y_all.extend(y_26)
y_all.extend(y_27)
y_all.extend(y_28)


all_index = []

#all_index.extend(hate_index)
all_index.extend(index0)
all_index.extend(index1)
all_index.extend(index2)
all_index.extend(index3)
all_index.extend(index4)
all_index.extend(index5)
all_index.extend(index6)
all_index.extend(index7)
all_index.extend(index8)
all_index.extend(index9)
all_index.extend(index10)
all_index.extend(index11)
all_index.extend(index12)
all_index.extend(index13)
all_index.extend(index14)
all_index.extend(index15)
all_index.extend(index16)
all_index.extend(index17)
all_index.extend(index18)
all_index.extend(index19)
all_index.extend(index20)
all_index.extend(index21)
all_index.extend(index22)
all_index.extend(index23)
all_index.extend(index24)
all_index.extend(index25)
all_index.extend(index26)
all_index.extend(index27)
all_index.extend(index28)



recall_test = []
accuracy_test = []
fscore_test = []
precision_test = []
all_index = np.array(all_index)
trail = 0
for train_i, test_i in skf.split(all_index, y_all):
    print("========begin trail {:01d}===========".format(trail))
    all_train_index = all_index[train_i]
    test_index = all_index[test_i]
    data = dataset[0]
    data.train_mask = torch.zeros(data.num_nodes, dtype=torch.long)
    data.train_mask[all_train_index] = 1
    data.test_mask = torch.zeros(data.num_nodes, dtype=torch.long)
    data.test_mask[test_index] = 1
    loader = NeighborSampler(data, size=[25], num_hops=1, batch_size=128, shuffle=True, add_self_loops=True)
</code></pre>
<p>Here is what is in the data exactly:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/7/872f1234152e0f9129ea137bcd51b39a8d71a01e.png" data-download-href="https://discuss.pytorch.org/uploads/default/872f1234152e0f9129ea137bcd51b39a8d71a01e" title="Screen Shot 2021-05-29 at 12.23.49 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/7/872f1234152e0f9129ea137bcd51b39a8d71a01e_2_690x345.png" alt="Screen Shot 2021-05-29 at 12.23.49 AM" data-base62-sha1="jhTj5xsom5fMaG124s13Ub4ZiP4" width="690" height="345" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/7/872f1234152e0f9129ea137bcd51b39a8d71a01e_2_690x345.png, https://discuss.pytorch.org/uploads/default/optimized/3X/8/7/872f1234152e0f9129ea137bcd51b39a8d71a01e_2_1035x517.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/8/7/872f1234152e0f9129ea137bcd51b39a8d71a01e.png 2x" data-dominant-color="F6F6F6"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-05-29 at 12.23.49 AM</span><span class="informations">1091×546 53.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I would appreciate your help. Thank you.</p>

username: ptrblck
cooked: <p>I’m unsure how these indices are created, but based on the previous stack trace it seems that your are trying to index some “neighboring samples”? In case you cannot isolate and fix the issue properly (by making sure that these invalid indices are not used or by increasing the size of the tensor, which should be indexed), you could <code>torch.clamp</code> the indices to a max. value of 2511.</p>

username: monee_h.a
cooked: <p>Thank you so much for your reply. I figured this out and keep data in the proper range.</p>