Anurag1734/cuda-error-resolution-analysis
07
1[2 {3 "post_stream": {4 "posts": [5 {6 "id": 210037,7 "name": "Amin Sabet",8 "username": "amin_sabet",9 "avatar_template": "/user_avatar/discuss.pytorch.org/amin_sabet/{size}/12866_2.png",10 "created_at": "2020-07-07T11:33:00.271Z",11 "cooked": "<p>In my code, I need to store the latest input data into a layer (Here is _AdaptiveAvgPoolNd ) and do the average pooling operation on the subtraction of new input data and latest input data, then updating the latest value. I was wondering what is the best way to define the latest_inpu? With the variable, I get following error during the training</p>\n<pre><code class=\"lang-auto\">class _AdaptiveAvgPoolNd(nn.Module):\n __constants__ = ['output_size']\n\n def __init__(self, batch,channel,width,height,output_size):\n super(_AdaptiveAvgPoolNd, self).__init__()\n self.output_size = output_size\n self.latest_input = Variable(torch.zeros(batch,channel,width,height), requires_grad=True)\n\n def extra_repr(self):\n return 'output_size={}'.format(self.output_size)\n\n\nclass AdaptiveAvgPool2d_modified(_AdaptiveAvgPoolNd):\n \n def forward(self, input):\n\n output = F.adaptive_avg_pool2d((input - self.latest_input), self.output_size)\n self.latest_input = input\n \n return output\n</code></pre>\n<pre><code class=\"lang-auto\">Variable._execution_engine.run_backward(\nRuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed. Specify retain_graph=True when calling backward the first time.\n</code></pre>",12 "post_number": 1,13 "post_type": 1,14 "posts_count": 2,15 "updated_at": "2020-07-07T11:33:00.271Z",16 "reply_count": 0,17 "reply_to_post_number": null,18 "quote_count": 0,19 "incoming_link_count": 18,20 "reads": 4,21 "readers_count": 3,22 "score": 90.8,23 "yours": false,24 "topic_id": 88221,25 "topic_slug": "store-the-latest-input-data-into-a-layer",26 "display_username": "Amin Sabet",27 "primary_group_name": null,28 "flair_name": null,29 "flair_url": null,30 "flair_bg_color": null,31 "flair_color": null,32 "flair_group_id": null,33 "badges_granted": [],34 "version": 1,35 "can_edit": false,36 "can_delete": false,37 "can_recover": false,38 "can_see_hidden_post": false,39 "can_wiki": false,40 "read": true,41 "user_title": null,42 "bookmarked": false,43 "actions_summary": [],44 "moderator": false,45 "admin": false,46 "staff": false,47 "user_id": 19388,48 "hidden": false,49 "trust_level": 1,50 "deleted_at": null,51 "user_deleted": false,52 "edit_reason": null,53 "can_view_edit_history": true,54 "wiki": false,55 "post_url": "/t/store-the-latest-input-data-into-a-layer/88221/1",56 "can_accept_answer": false,57 "can_unaccept_answer": false,58 "accepted_answer": false,59 "topic_accepted_answer": true,60 "can_vote": false61 },62 {63 "id": 210039,64 "name": "A curious guy here!",65 "username": "Shisho_Sama",66 "avatar_template": "/user_avatar/discuss.pytorch.org/shisho_sama/{size}/6926_2.png",67 "created_at": "2020-07-07T11:42:04.043Z",68 "cooked": "<p>I guess your issue is your latest_input interfers with the current graph as the error suggest so, just do <code>self.latest_input.clone().detach()</code> so your only providing the data needed.</p>",69 "post_number": 2,70 "post_type": 1,71 "posts_count": 2,72 "updated_at": "2020-07-07T11:47:54.493Z",73 "reply_count": 0,74 "reply_to_post_number": null,75 "quote_count": 0,76 "incoming_link_count": 1,77 "reads": 4,78 "readers_count": 3,79 "score": 20.8,80 "yours": false,81 "topic_id": 88221,82 "topic_slug": "store-the-latest-input-data-into-a-layer",83 "display_username": "A curious guy here!",84 "primary_group_name": null,85 "flair_name": null,86 "flair_url": null,87 "flair_bg_color": null,88 "flair_color": null,89 "flair_group_id": null,90 "badges_granted": [],91 "version": 1,92 "can_edit": false,93 "can_delete": false,94 "can_recover": false,95 "can_see_hidden_post": false,96 "can_wiki": false,97 "read": true,98 "user_title": "",99 "bookmarked": false,100 "actions_summary": [101 {102 "id": 2,103 "count": 1104 }105 ],106 "moderator": false,107 "admin": false,108 "staff": false,109 "user_id": 7863,110 "hidden": false,111 "trust_level": 2,112 "deleted_at": null,113 "user_deleted": false,114 "edit_reason": null,115 "can_view_edit_history": true,116 "wiki": false,117 "post_url": "/t/store-the-latest-input-data-into-a-layer/88221/2",118 "can_accept_answer": false,119 "can_unaccept_answer": false,120 "accepted_answer": true,121 "topic_accepted_answer": true122 }123 ],124 "stream": [125 210037,126 210039127 ]128 },129 "timeline_lookup": [130 [131 1,132 1936133 ]134 ],135 "suggested_topics": [136 {137 "fancy_title": "Batch size at inference is influencing accuracy",138 "id": 218096,139 "title": "Batch size at inference is influencing accuracy",140 "slug": "batch-size-at-inference-is-influencing-accuracy",141 "posts_count": 1,142 "reply_count": 0,143 "highest_post_number": 1,144 "image_url": null,145 "created_at": "2025-03-20T21:02:58.000Z",146 "last_posted_at": "2025-03-20T21:02:58.052Z",147 "bumped": true,148 "bumped_at": "2025-03-20T21:02:58.052Z",149 "archetype": "regular",150 "unseen": false,151 "pinned": false,152 "unpinned": null,153 "visible": true,154 "closed": false,155 "archived": false,156 "bookmarked": null,157 "liked": null,158 "tags_descriptions": {},159 "like_count": 0,160 "views": 45,161 "category_id": 5,162 "featured_link": null,163 "has_accepted_answer": false,164 "posters": [165 {166 "extras": "latest single",167 "description": "Original Poster, Most Recent Poster",168 "user": {169 "id": 83393,170 "username": "danbull-scanabull",171 "name": "Danbull Scanabull",172 "avatar_template": "/user_avatar/discuss.pytorch.org/danbull-scanabull/{size}/76268_2.png",173 "trust_level": 1174 }175 }176 ]177 },178 {179 "fancy_title": "ValueError: You should supply an encoding or a list of encodings to this method that includes input_ids, but you provided [‘pixel_values’]",180 "id": 216220,181 "title": "ValueError: You should supply an encoding or a list of encodings to this method that includes input_ids, but you provided ['pixel_values']",182 "slug": "valueerror-you-should-supply-an-encoding-or-a-list-of-encodings-to-this-method-that-includes-input-ids-but-you-provided-pixel-values",183 "posts_count": 4,184 "reply_count": 1,185 "highest_post_number": 4,186 "image_url": null,187 "created_at": "2025-02-04T13:03:09.113Z",188 "last_posted_at": "2025-02-12T12:11:07.163Z",189 "bumped": true,190 "bumped_at": "2025-02-12T12:30:38.800Z",191 "archetype": "regular",192 "unseen": false,193 "pinned": false,194 "unpinned": null,195 "visible": true,196 "closed": false,197 "archived": false,198 "bookmarked": null,199 "liked": null,200 "tags_descriptions": {},201 "like_count": 0,202 "views": 445,203 "category_id": 5,204 "featured_link": null,205 "has_accepted_answer": false,206 "posters": [207 {208 "extras": "latest",209 "description": "Original Poster, Most Recent Poster",210 "user": {211 "id": 82473,212 "username": "milanalimova",213 "name": null,214 "avatar_template": "/user_avatar/discuss.pytorch.org/milanalimova/{size}/75456_2.png",215 "trust_level": 1216 }217 },218 {219 "extras": null,220 "description": "Frequent Poster",221 "user": {222 "id": 3534,223 "username": "ptrblck",224 "name": "",225 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",226 "admin": true,227 "moderator": true,228 "trust_level": 2229 }230 }231 ]232 },233 {234 "fancy_title": "How to Build a More Efficient DataLoader to Load Large Image Datasets?",235 "id": 213229,236 "title": "How to Build a More Efficient DataLoader to Load Large Image Datasets?",237 "slug": "how-to-build-a-more-efficient-dataloader-to-load-large-image-datasets",238 "posts_count": 3,239 "reply_count": 1,240 "highest_post_number": 3,241 "image_url": null,242 "created_at": "2024-11-20T20:09:54.513Z",243 "last_posted_at": "2024-11-22T16:09:19.099Z",244 "bumped": true,245 "bumped_at": "2024-11-22T16:09:19.099Z",246 "archetype": "regular",247 "unseen": false,248 "pinned": false,249 "unpinned": null,250 "visible": true,251 "closed": false,252 "archived": false,253 "bookmarked": null,254 "liked": null,255 "tags_descriptions": {},256 "like_count": 0,257 "views": 172,258 "category_id": 5,259 "featured_link": null,260 "has_accepted_answer": false,261 "posters": [262 {263 "extras": null,264 "description": "Original Poster",265 "user": {266 "id": 32574,267 "username": "Nick_ishere",268 "name": "",269 "avatar_template": "/user_avatar/discuss.pytorch.org/nick_ishere/{size}/25121_2.png",270 "trust_level": 1271 }272 },273 {274 "extras": null,275 "description": "Frequent Poster",276 "user": {277 "id": 72430,278 "username": "Eduardo_Lawson",279 "name": "Eduardo Lawson da Silva",280 "avatar_template": "/user_avatar/discuss.pytorch.org/eduardo_lawson/{size}/66899_2.png",281 "trust_level": 2282 }283 },284 {285 "extras": "latest",286 "description": "Most Recent Poster",287 "user": {288 "id": 64498,289 "username": "nickums",290 "name": "Nickums",291 "avatar_template": "/user_avatar/discuss.pytorch.org/nickums/{size}/58652_2.png",292 "trust_level": 1293 }294 }295 ]296 },297 {298 "fancy_title": "Understanding Optimal T, H, and W for R3D_18 Pretrained on Kinetics-400",299 "id": 217979,300 "title": "Understanding Optimal T, H, and W for R3D_18 Pretrained on Kinetics-400",301 "slug": "understanding-optimal-t-h-and-w-for-r3d-18-pretrained-on-kinetics-400",302 "posts_count": 1,303 "reply_count": 0,304 "highest_post_number": 1,305 "image_url": null,306 "created_at": "2025-03-18T08:42:02.547Z",307 "last_posted_at": "2025-03-18T08:42:02.587Z",308 "bumped": true,309 "bumped_at": "2025-03-18T08:42:02.587Z",310 "archetype": "regular",311 "unseen": false,312 "pinned": false,313 "unpinned": null,314 "visible": true,315 "closed": false,316 "archived": false,317 "bookmarked": null,318 "liked": null,319 "tags_descriptions": {},320 "like_count": 0,321 "views": 25,322 "category_id": 5,323 "featured_link": null,324 "has_accepted_answer": false,325 "posters": [326 {327 "extras": "latest single",328 "description": "Original Poster, Most Recent Poster",329 "user": {330 "id": 83341,331 "username": "Sid_1041",332 "name": "Sid",333 "avatar_template": "/letter_avatar_proxy/v4/letter/s/ac8455/{size}.png",334 "trust_level": 0335 }336 }337 ]338 },339 {340 "fancy_title": "Parity mismatch between torch and tensorRT for ultralytics yolo-v11 model",341 "id": 218602,342 "title": "Parity mismatch between torch and tensorRT for ultralytics yolo-v11 model",343 "slug": "parity-mismatch-between-torch-and-tensorrt-for-ultralytics-yolo-v11-model",344 "posts_count": 1,345 "reply_count": 0,346 "highest_post_number": 1,347 "image_url": "https://discuss.pytorch.org/uploads/default/original/3X/e/3/e31d9ba78eab2ae23d4b926bc034a4cf1a86eaa8.png",348 "created_at": "2025-04-04T00:22:22.544Z",349 "last_posted_at": "2025-04-04T00:22:22.590Z",350 "bumped": true,351 "bumped_at": "2025-04-04T00:22:22.590Z",352 "archetype": "regular",353 "unseen": false,354 "pinned": false,355 "unpinned": null,356 "visible": true,357 "closed": false,358 "archived": false,359 "bookmarked": null,360 "liked": null,361 "tags_descriptions": {},362 "like_count": 0,363 "views": 79,364 "category_id": 5,365 "featured_link": null,366 "has_accepted_answer": false,367 "posters": [368 {369 "extras": "latest single",370 "description": "Original Poster, Most Recent Poster",371 "user": {372 "id": 83626,373 "username": "d_utkarsh",374 "name": "Utkarsh Deshmukh",375 "avatar_template": "/letter_avatar_proxy/v4/letter/d/b9bd4f/{size}.png",376 "trust_level": 0377 }378 }379 ]380 }381 ],382 "tags_descriptions": {},383 "fancy_title": "Store the latest input data into a layer",384 "id": 88221,385 "title": "Store the latest input data into a layer",386 "posts_count": 2,387 "created_at": "2020-07-07T11:33:00.214Z",388 "views": 307,389 "reply_count": 0,390 "like_count": 1,391 "last_posted_at": "2020-07-07T11:42:04.043Z",392 "visible": true,393 "closed": false,394 "archived": false,395 "has_summary": false,396 "archetype": "regular",397 "slug": "store-the-latest-input-data-into-a-layer",398 "category_id": 5,399 "word_count": 182,400 "deleted_at": null,401 "user_id": 19388,402 "featured_link": null,403 "pinned_globally": false,404 "pinned_at": null,405 "pinned_until": null,406 "image_url": null,407 "slow_mode_seconds": 0,408 "draft": null,409 "draft_key": "topic_88221",410 "draft_sequence": null,411 "unpinned": null,412 "pinned": false,413 "current_post_number": 1,414 "highest_post_number": 2,415 "deleted_by": null,416 "actions_summary": [417 {418 "id": 4,419 "count": 0,420 "hidden": false,421 "can_act": false422 },423 {424 "id": 8,425 "count": 0,426 "hidden": false,427 "can_act": false428 },429 {430 "id": 10,431 "count": 0,432 "hidden": false,433 "can_act": false434 },435 {436 "id": 7,437 "count": 0,438 "hidden": false,439 "can_act": false440 }441 ],442 "chunk_size": 20,443 "bookmarked": false,444 "topic_timer": null,445 "message_bus_last_id": 0,446 "participant_count": 2,447 "show_read_indicator": false,448 "thumbnails": null,449 "slow_mode_enabled_until": null,450 "accepted_answer": {451 "post_number": 2,452 "username": "Shisho_Sama",453 "name": "A curious guy here!",454 "excerpt": "I guess your issue is your latest_input interfers with the current graph as the error suggest so, just do self.latest_input.clone().detach() so your only providing the data needed."455 },456 "can_vote": false,457 "vote_count": 0,458 "user_voted": false,459 "discourse_zendesk_plugin_zendesk_id": null,460 "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",461 "details": {462 "can_edit": false,463 "notification_level": 1,464 "participants": [465 {466 "id": 7863,467 "username": "Shisho_Sama",468 "name": "A curious guy here!",469 "avatar_template": "/user_avatar/discuss.pytorch.org/shisho_sama/{size}/6926_2.png",470 "post_count": 1,471 "primary_group_name": null,472 "flair_name": null,473 "flair_url": null,474 "flair_color": null,475 "flair_bg_color": null,476 "flair_group_id": null,477 "trust_level": 2478 },479 {480 "id": 19388,481 "username": "amin_sabet",482 "name": "Amin Sabet",483 "avatar_template": "/user_avatar/discuss.pytorch.org/amin_sabet/{size}/12866_2.png",484 "post_count": 1,485 "primary_group_name": null,486 "flair_name": null,487 "flair_url": null,488 "flair_color": null,489 "flair_bg_color": null,490 "flair_group_id": null,491 "trust_level": 1492 }493 ],494 "created_by": {495 "id": 19388,496 "username": "amin_sabet",497 "name": "Amin Sabet",498 "avatar_template": "/user_avatar/discuss.pytorch.org/amin_sabet/{size}/12866_2.png"499 },500 "last_poster": {501 "id": 7863,502 "username": "Shisho_Sama",503 "name": "A curious guy here!",504 "avatar_template": "/user_avatar/discuss.pytorch.org/shisho_sama/{size}/6926_2.png"505 }506 },507 "bookmarks": []508 },509 {510 "post_stream": {511 "posts": [512 {513 "id": 208536,514 "name": "Chris ",515 "username": "Chris_Freiburg",516 "avatar_template": "/user_avatar/discuss.pytorch.org/chris_freiburg/{size}/14874_2.png",517 "created_at": "2020-07-01T10:51:59.665Z",518 "cooked": "<p>Hallo I am a beginner and want to build a word prediction model with LSTM<br>\nbut I get the following error and I cant find the cause</p>\n<p>Thank you for your help</p>\n<pre><code class=\"lang-auto\">RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1536, 200]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).\n</code></pre>\n<pre><code class=\"lang-auto\">import torch\nimport torch.nn as nn\nimport string\nimport random\nimport sys\nimport unidecode\nfrom torch.utils.tensorboard import SummaryWriter\nimport numpy as np\nimport re\nimport math\nprint(torch.__version__)\n\ndef char_tensor(string):\n tensor = torch.zeros(len(string)).long()\n for c in range(len(string)):\n tensor[c] = all_characters.index(string[c])\n return tensor\n\ndef clean_text(text):\n text = text.replace('\\n',' ')\n text = re.sub('[^A-Za-z ]+', '', text)\n return text\n\n\ndef word_to_class(word, word_dict):\n word_class = word_dict[word]\n word_class_t = torch.zeros(1) + word_class\n return word_class_t\n\n\n\ndef one_hot_encode(y,output_size):\n one_hot = torch.zeros(output_size)\n one_hot[y] = 1\n return one_hot\n\ndef create_batches(X_train, y_train, choices, word_dict, output_size, batch_size):\n x_batch = []\n y_batch = []\n for i in range(batch_size):\n idx = choices.pop()\n x_batch.append(char_tensor((X_train[idx])))\n num = word_to_class(y_data[idx], word_dict)\n one_hot = one_hot_encode(int(num), output_size)\n y_batch.append(one_hot)\n \n xt_batch = torch.stack(x_batch)\n yt_batch = torch.stack(y_batch)\n \n return xt_batch, yt_batch, choices \n\nclass RNN(nn.Module):\n def __init__(self, input_size, hidden_size, num_layers, output_size):\n super(RNN, self).__init__()\n self.input_size = input_size\n self.hidden_size = hidden_size\n self.num_layers = num_layers\n\n #self.embed = nn.Embedding(input_size, hidden_size)\n #self.lstm = nn.LSTM(hidden_size, hidden_size, num_layers, batch_first=True)\n self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=False)\n self.fc = nn.Linear(hidden_size, output_size)\n #self.softmax = nn.LogSoftmax(dim=1)\n \n def forward(self, x, hidden, cell):\n #out = self.embed(x)\n out, (hidden, cell) = self.lstm(x, (hidden, cell))\n output = self.fc(out)\n #output = self.softmax(output)\n return output, (hidden, cell)\n\n def init_hidden(self, batch_size):\n hidden = torch.zeros(self.num_layers, batch_size, self.input_size).to(device)\n cell = torch.zeros(self.num_layers, batch_size, self.input_size).to(device)\n #hidden = torch.zeros(self.num_layers, batch_size, self.hidden_size).to(device)\n #cell = torch.zeros(self.num_layers, batch_size, self.hidden_size).to(device)\n return hidden, cell\n\n\n\nclass SentimentNet(nn.Module):\n def __init__(self, vocab_size, output_size, embedding_dim, hidden_dim, n_layers, device, drop_prob=0.5):\n super(SentimentNet, self).__init__()\n self.output_size = output_size\n self.n_layers = n_layers\n self.hidden_dim = hidden_dim\n self.device = device\n \n self.embedding = nn.Embedding(vocab_size, embedding_dim)\n self.lstm = nn.LSTM(embedding_dim, hidden_dim, n_layers, dropout=drop_prob, batch_first=True)\n self.dropout = nn.Dropout(drop_prob)\n self.fc = nn.Linear(hidden_dim, output_size)\n #self.sigmoid = nn.softmax()\n \n def forward(self, x, hidden):\n batch_size = x.size(0)\n x = x.long()\n embeds = self.embedding(x)\n lstm_out, hidden = self.lstm(embeds, hidden)\n #lstm_out = lstm_out.contiguous().view(-1, self.hidden_dim)\n \n out = self.dropout(lstm_out)\n #out = self.fc(out)\n out = self.fc(out[:, -1, :])\n #out = out[:,-1]\n print(\"out of fc\", out.shape)\n #out = self.sigmoid(out)\n \n #out = out.view(batch_size, -1)\n return out, hidden\n \n def init_hidden(self, batch_size):\n weight = next(self.parameters()).data\n hidden = (weight.new(self.n_layers, batch_size, self.hidden_dim).zero_().to(self.device), weight.new(self.n_layers, batch_size, self.hidden_dim).zero_().to(self.device))\n return hidden\n\n\n\n\n\n# Device configuration\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n#device = \"cpu\"\n# Get characters from string.printable\nall_characters = string.printable\nn_characters = len(all_characters)\n# Read large text file (Note can be any text file: not limited to just names)\ntext = unidecode.unidecode(open(\"wonderland.txt\").read())\ntext_clean = clean_text(text)\ntext_clean = text_clean.split()\nseq_length = 100\ny_data = []\ndata = []\npart = ''\nfor idx in range(0, len(text_clean) - 1):\n part += (text_clean[idx] + \" \")\n new_length = len(part) + len(text_clean[idx+1])\n if new_length > seq_length:\n part = part[:-1]\n part = part.rjust(100)\n y_data.append(text_clean[idx+1])\n data.append(part)\n part = ''\n continue\nprint(\"data size \", len(data))\nlen(y_data)\ntrain_size = round(len(data) * 0.9)\nX_train = data[:train_size] \nX_test = y_data[:train_size]\ny_train = data[train_size:]\ny_test = y_data[train_size:]\nunique_word = set(text_clean)\noutput_size = len(set(text_clean))\n\nseq_length = 100\nnum_epochs = 5000\nbatch_size = 16\nhidden_size = 128*3\nnum_layers = 3\nlr = 0.3\n\niterations = math.floor(len(X_train)/ batch_size)\ntrain_data_size = iterations * batch_size\nchoices = list(range(train_data_size))\nword_dict = {word:idx for idx,word in enumerate(unique_word)}\n#model = RNN(seq_length, hidden_size, num_layers,output_size).to(device)\nmodel = SentimentNet(seq_length, output_size, 200, hidden_size, num_layers, device).to(device)\noptimizer = torch.optim.Adam(model.parameters(), lr=lr)\ncriterion = nn.CrossEntropyLoss()\n#criterion = nn.BCELoss()\n\nprint(\"=> Starting training\")\nbest_loss = float(\"inf\")\nfor epoch in range(1, num_epochs + 1):\n hidden = model.init_hidden(batch_size=batch_size)\n epoch_loss = 0\n choices = list(range(train_data_size))\n \n for idx in range(iterations):\n \n \n x_batch, y_batch, choices = create_batches(X_train, y_train, choices, word_dict, output_size, batch_size)\n x_batch = x_batch.to(device)\n y_batch = y_batch.to(device).long()\n #x_batch = x_batch.unsqueeze(0)\n print(\"Input size \", x_batch.shape)\n # output, (hidden, cell) = model(x_batch, hidden, cell)\n output, hidden = model(x_batch, hidden)\n print(output.shape)\n print(\"target\", y_batch.shape)\n output = output.float()\n y_batch = y_batch.long()\n loss = criterion(output, torch.max(y_batch, 1)[1]).to(device)\n optimizer.zero_grad()\n loss.backward(retain_graph=True)\n optimizer.step()\n #epoch_loss += loss.item()\n epoch_loss = epoch_loss / iterations\n print(\"Epoch {} loss {}\".format(epoch, epoch_loss ))\n</code></pre>",519 "post_number": 1,520 "post_type": 1,521 "posts_count": 4,522 "updated_at": "2020-07-01T10:51:59.665Z",523 "reply_count": 0,524 "reply_to_post_number": null,525 "quote_count": 0,526 "incoming_link_count": 30,527 "reads": 10,528 "readers_count": 9,529 "score": 152.0,530 "yours": false,531 "topic_id": 87576,532 "topic_slug": "lstm-one-of-the-variables-needed",533 "display_username": "Chris ",534 "primary_group_name": null,535 "flair_name": null,536 "flair_url": null,537 "flair_bg_color": null,538 "flair_color": null,539 "flair_group_id": null,540 "badges_granted": [],541 "version": 1,542 "can_edit": false,543 "can_delete": false,544 "can_recover": false,545 "can_see_hidden_post": false,546 "can_wiki": false,547 "read": true,548 "user_title": null,549 "bookmarked": false,550 "actions_summary": [],551 "moderator": false,552 "admin": false,553 "staff": false,554 "user_id": 11810,555 "hidden": false,556 "trust_level": 1,557 "deleted_at": null,558 "user_deleted": false,559 "edit_reason": null,560 "can_view_edit_history": true,561 "wiki": false,562 "post_url": "/t/lstm-one-of-the-variables-needed/87576/1",563 "can_accept_answer": false,564 "can_unaccept_answer": false,565 "accepted_answer": false,566 "topic_accepted_answer": null,567 "can_vote": false568 },569 {570 "id": 209096,571 "name": "",572 "username": "ptrblck",573 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",574 "created_at": "2020-07-03T07:53:26.952Z",575 "cooked": "<p>The error is most likely raised, as you are not detaching the <code>hidden</code> state, keep the computation graph alive via <code>retain_graph=True</code>, and manipulate the parameters inplace via <code>optimizer.step()</code>.</p>\n<p>Are you sure you need to use <code>retain_graph=True</code>? If not, remove it and detach the hidden state via:</p>\n<pre><code class=\"lang-python\">hidden = (hidden[0].detach(), hidden[1].detach())\n</code></pre>\n<p>before passing it to the model.</p>",576 "post_number": 2,577 "post_type": 1,578 "posts_count": 4,579 "updated_at": "2020-07-03T07:53:26.952Z",580 "reply_count": 1,581 "reply_to_post_number": null,582 "quote_count": 0,583 "incoming_link_count": 0,584 "reads": 7,585 "readers_count": 6,586 "score": 6.4,587 "yours": false,588 "topic_id": 87576,589 "topic_slug": "lstm-one-of-the-variables-needed",590 "display_username": "",591 "primary_group_name": null,592 "flair_name": null,593 "flair_url": null,594 "flair_bg_color": null,595 "flair_color": null,596 "flair_group_id": null,597 "badges_granted": [],598 "version": 1,599 "can_edit": false,600 "can_delete": false,601 "can_recover": false,602 "can_see_hidden_post": false,603 "can_wiki": false,604 "read": true,605 "user_title": "",606 "bookmarked": false,607 "actions_summary": [],608 "moderator": true,609 "admin": true,610 "staff": true,611 "user_id": 3534,612 "hidden": false,613 "trust_level": 2,614 "deleted_at": null,615 "user_deleted": false,616 "edit_reason": null,617 "can_view_edit_history": true,618 "wiki": false,619 "post_url": "/t/lstm-one-of-the-variables-needed/87576/2",620 "can_accept_answer": false,621 "can_unaccept_answer": false,622 "accepted_answer": false,623 "topic_accepted_answer": null624 },625 {626 "id": 209142,627 "name": "Chris",628 "username": "vdw",629 "avatar_template": "/user_avatar/discuss.pytorch.org/vdw/{size}/10074_2.png",630 "created_at": "2020-07-03T09:23:49.239Z",631 "cooked": "<p>Alternatively to <a class=\"mention\" href=\"/u/ptrblck\">@ptrblck</a> suggestion, you might want to call</p>\n<pre><code>hidden = model.init_hidden(batch_size=batch_size) \n</code></pre>\n<p>For each batch not just for each epoch.</p>",632 "post_number": 3,633 "post_type": 1,634 "posts_count": 4,635 "updated_at": "2020-07-03T09:23:49.239Z",636 "reply_count": 0,637 "reply_to_post_number": 2,638 "quote_count": 0,639 "incoming_link_count": 3,640 "reads": 7,641 "readers_count": 6,642 "score": 61.4,643 "yours": false,644 "topic_id": 87576,645 "topic_slug": "lstm-one-of-the-variables-needed",646 "display_username": "Chris",647 "primary_group_name": null,648 "flair_name": null,649 "flair_url": null,650 "flair_bg_color": null,651 "flair_color": null,652 "flair_group_id": null,653 "badges_granted": [],654 "version": 1,655 "can_edit": false,656 "can_delete": false,657 "can_recover": false,658 "can_see_hidden_post": false,659 "can_wiki": false,660 "read": true,661 "user_title": null,662 "reply_to_user": {663 "id": 3534,664 "username": "ptrblck",665 "name": "",666 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png"667 },668 "bookmarked": false,669 "actions_summary": [670 {671 "id": 2,672 "count": 1673 }674 ],675 "moderator": false,676 "admin": false,677 "staff": false,678 "user_id": 1438,679 "hidden": false,680 "trust_level": 2,681 "deleted_at": null,682 "user_deleted": false,683 "edit_reason": null,684 "can_view_edit_history": true,685 "wiki": false,686 "post_url": "/t/lstm-one-of-the-variables-needed/87576/3",687 "can_accept_answer": false,688 "can_unaccept_answer": false,689 "accepted_answer": false,690 "topic_accepted_answer": null691 },692 {693 "id": 210025,694 "name": "Chris ",695 "username": "Chris_Freiburg",696 "avatar_template": "/user_avatar/discuss.pytorch.org/chris_freiburg/{size}/14874_2.png",697 "created_at": "2020-07-07T10:39:09.286Z",698 "cooked": "<p>Thank you both<br>\nIt really solved the issue</p>",699 "post_number": 4,700 "post_type": 1,701 "posts_count": 4,702 "updated_at": "2020-07-07T10:39:09.286Z",703 "reply_count": 0,704 "reply_to_post_number": null,705 "quote_count": 0,706 "incoming_link_count": 2,707 "reads": 7,708 "readers_count": 6,709 "score": 11.4,710 "yours": false,711 "topic_id": 87576,712 "topic_slug": "lstm-one-of-the-variables-needed",713 "display_username": "Chris ",714 "primary_group_name": null,715 "flair_name": null,716 "flair_url": null,717 "flair_bg_color": null,718 "flair_color": null,719 "flair_group_id": null,720 "badges_granted": [],721 "version": 1,722 "can_edit": false,723 "can_delete": false,724 "can_recover": false,725 "can_see_hidden_post": false,726 "can_wiki": false,727 "read": true,728 "user_title": null,729 "bookmarked": false,730 "actions_summary": [],731 "moderator": false,732 "admin": false,733 "staff": false,734 "user_id": 11810,735 "hidden": false,736 "trust_level": 1,737 "deleted_at": null,738 "user_deleted": false,739 "edit_reason": null,740 "can_view_edit_history": true,741 "wiki": false,742 "post_url": "/t/lstm-one-of-the-variables-needed/87576/4",743 "can_accept_answer": false,744 "can_unaccept_answer": false,745 "accepted_answer": false,746 "topic_accepted_answer": null747 }748 ],749 "stream": [750 208536,751 209096,752 209142,753 210025754 ]755 },756 "timeline_lookup": [757 [758 1,759 1943760 ],761 [762 2,763 1941764 ],765 [766 4,767 1937768 ]769 ],770 "suggested_topics": [771 {772 "fancy_title": "Initial D_KL loss is high and going down really slow",773 "id": 217877,774 "title": "Initial D_KL loss is high and going down really slow",775 "slug": "initial-d-kl-loss-is-high-and-going-down-really-slow",776 "posts_count": 1,777 "reply_count": 0,778 "highest_post_number": 1,779 "image_url": null,780 "created_at": "2025-03-15T12:04:06.828Z",781 "last_posted_at": "2025-03-15T12:04:06.870Z",782 "bumped": true,783 "bumped_at": "2025-03-15T12:07:55.407Z",784 "archetype": "regular",785 "unseen": false,786 "pinned": false,787 "unpinned": null,788 "visible": true,789 "closed": false,790 "archived": false,791 "bookmarked": null,792 "liked": null,793 "tags_descriptions": {},794 "like_count": 0,795 "views": 32,796 "category_id": 8,797 "featured_link": null,798 "has_accepted_answer": false,799 "posters": [800 {801 "extras": "latest single",802 "description": "Original Poster, Most Recent Poster",803 "user": {804 "id": 83290,805 "username": "User_Name",806 "name": "User Name",807 "avatar_template": "/user_avatar/discuss.pytorch.org/user_name/{size}/76177_2.png",808 "trust_level": 0809 }810 }811 ]812 },813 {814 "fancy_title": "Understanding logits in GPT2",815 "id": 213865,816 "title": "Understanding logits in GPT2",817 "slug": "understanding-logits-in-gpt2",818 "posts_count": 1,819 "reply_count": 0,820 "highest_post_number": 1,821 "image_url": null,822 "created_at": "2024-12-05T15:14:26.136Z",823 "last_posted_at": "2024-12-05T15:14:26.194Z",824 "bumped": true,825 "bumped_at": "2024-12-05T15:14:26.194Z",826 "archetype": "regular",827 "unseen": false,828 "pinned": false,829 "unpinned": null,830 "visible": true,831 "closed": false,832 "archived": false,833 "bookmarked": null,834 "liked": null,835 "tags_descriptions": {},836 "like_count": 0,837 "views": 200,838 "category_id": 8,839 "featured_link": null,840 "has_accepted_answer": false,841 "posters": [842 {843 "extras": "latest single",844 "description": "Original Poster, Most Recent Poster",845 "user": {846 "id": 81335,847 "username": "firolommones3",848 "name": "",849 "avatar_template": "/letter_avatar_proxy/v4/letter/f/b2d939/{size}.png",850 "trust_level": 0851 }852 }853 ]854 },855 {856 "fancy_title": "Correct way to batch custom masks in SDPA",857 "id": 214155,858 "title": "Correct way to batch custom masks in SDPA",859 "slug": "correct-way-to-batch-custom-masks-in-sdpa",860 "posts_count": 1,861 "reply_count": 0,862 "highest_post_number": 1,863 "image_url": null,864 "created_at": "2024-12-12T14:37:13.000Z",865 "last_posted_at": "2024-12-12T14:37:13.049Z",866 "bumped": true,867 "bumped_at": "2024-12-12T14:37:13.049Z",868 "archetype": "regular",869 "unseen": false,870 "pinned": false,871 "unpinned": null,872 "visible": true,873 "closed": false,874 "archived": false,875 "bookmarked": null,876 "liked": null,877 "tags_descriptions": {},878 "like_count": 0,879 "views": 75,880 "category_id": 8,881 "featured_link": null,882 "has_accepted_answer": false,883 "posters": [884 {885 "extras": "latest single",886 "description": "Original Poster, Most Recent Poster",887 "user": {888 "id": 81474,889 "username": "mm23",890 "name": "mm23",891 "avatar_template": "/user_avatar/discuss.pytorch.org/mm23/{size}/74491_2.png",892 "trust_level": 1893 }894 }895 ]896 },897 {898 "fancy_title": "Slow attention when using kvCache",899 "id": 216970,900 "title": "Slow attention when using kvCache",901 "slug": "slow-attention-when-using-kvcache",902 "posts_count": 2,903 "reply_count": 0,904 "highest_post_number": 2,905 "image_url": "https://discuss.pytorch.org/uploads/default/optimized/3X/4/8/48b8b2fe5bbc5b043e270063d7b0fd56f6ac7909_2_1023x299.jpeg",906 "created_at": "2025-02-21T01:42:07.857Z",907 "last_posted_at": "2025-02-21T14:02:17.595Z",908 "bumped": true,909 "bumped_at": "2025-02-21T14:02:17.595Z",910 "archetype": "regular",911 "unseen": false,912 "pinned": false,913 "unpinned": null,914 "visible": true,915 "closed": false,916 "archived": false,917 "bookmarked": null,918 "liked": null,919 "tags_descriptions": {},920 "like_count": 0,921 "views": 77,922 "category_id": 8,923 "featured_link": null,924 "has_accepted_answer": false,925 "posters": [926 {927 "extras": null,928 "description": "Original Poster",929 "user": {930 "id": 82829,931 "username": "ywha0929",932 "name": "영우 하",933 "avatar_template": "/user_avatar/discuss.pytorch.org/ywha0929/{size}/75789_2.png",934 "trust_level": 1935 }936 },937 {938 "extras": "latest",939 "description": "Most Recent Poster",940 "user": {941 "id": 3534,942 "username": "ptrblck",943 "name": "",944 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",945 "admin": true,946 "moderator": true,947 "trust_level": 2948 }949 }950 ]951 },952 {953 "fancy_title": "Gemma 3 throws RuntimeError CUDA misaligned address",954 "id": 220507,955 "title": "Gemma 3 throws RuntimeError CUDA misaligned address",956 "slug": "gemma-3-throws-runtimeerror-cuda-misaligned-address",957 "posts_count": 2,958 "reply_count": 0,959 "highest_post_number": 2,960 "image_url": null,961 "created_at": "2025-06-02T07:00:32.299Z",962 "last_posted_at": "2025-06-03T22:25:43.492Z",963 "bumped": true,964 "bumped_at": "2025-06-03T22:25:43.492Z",965 "archetype": "regular",966 "unseen": false,967 "pinned": false,968 "unpinned": null,969 "visible": true,970 "closed": false,971 "archived": false,972 "bookmarked": null,973 "liked": null,974 "tags_descriptions": {},975 "like_count": 0,976 "views": 116,977 "category_id": 8,978 "featured_link": null,979 "has_accepted_answer": false,980 "posters": [981 {982 "extras": null,983 "description": "Original Poster",984 "user": {985 "id": 84544,986 "username": "msi-sbraun-11",987 "name": "",988 "avatar_template": "/user_avatar/discuss.pytorch.org/msi-sbraun-11/{size}/77240_2.png",989 "trust_level": 0990 }991 },992 {993 "extras": "latest",994 "description": "Most Recent Poster",995 "user": {996 "id": 3534,997 "username": "ptrblck",998 "name": "",999 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",1000 "admin": true,1001 "moderator": true,1002 "trust_level": 21003 }1004 }1005 ]1006 }1007 ],1008 "tags_descriptions": {},1009 "fancy_title": "LSTM :RuntimeError: one of the variables needed",1010 "id": 87576,1011 "title": "LSTM :RuntimeError: one of the variables needed",1012 "posts_count": 4,1013 "created_at": "2020-07-01T10:51:59.597Z",1014 "views": 751,1015 "reply_count": 1,1016 "like_count": 1,1017 "last_posted_at": "2020-07-07T10:39:09.286Z",1018 "visible": true,1019 "closed": false,1020 "archived": false,1021 "has_summary": false,1022 "archetype": "regular",1023 "slug": "lstm-one-of-the-variables-needed",1024 "category_id": 8,1025 "word_count": 925,1026 "deleted_at": null,1027 "user_id": 11810,1028 "featured_link": null,1029 "pinned_globally": false,1030 "pinned_at": null,1031 "pinned_until": null,1032 "image_url": null,1033 "slow_mode_seconds": 0,1034 "draft": null,1035 "draft_key": "topic_87576",1036 "draft_sequence": null,1037 "unpinned": null,1038 "pinned": false,1039 "current_post_number": 1,1040 "highest_post_number": 4,1041 "deleted_by": null,1042 "actions_summary": [1043 {1044 "id": 4,1045 "count": 0,1046 "hidden": false,1047 "can_act": false1048 },1049 {1050 "id": 8,1051 "count": 0,1052 "hidden": false,1053 "can_act": false1054 },1055 {1056 "id": 10,1057 "count": 0,1058 "hidden": false,1059 "can_act": false1060 },1061 {1062 "id": 7,1063 "count": 0,1064 "hidden": false,1065 "can_act": false1066 }1067 ],1068 "chunk_size": 20,1069 "bookmarked": false,1070 "topic_timer": null,1071 "unicode_title": "LSTM :RuntimeError: one of the variables needed",1072 "message_bus_last_id": 0,1073 "participant_count": 3,1074 "show_read_indicator": false,1075 "thumbnails": null,1076 "slow_mode_enabled_until": null,1077 "can_vote": false,1078 "vote_count": 0,1079 "user_voted": false,1080 "discourse_zendesk_plugin_zendesk_id": null,1081 "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",1082 "details": {1083 "can_edit": false,1084 "notification_level": 1,1085 "participants": [1086 {1087 "id": 11810,1088 "username": "Chris_Freiburg",1089 "name": "Chris ",1090 "avatar_template": "/user_avatar/discuss.pytorch.org/chris_freiburg/{size}/14874_2.png",1091 "post_count": 2,1092 "primary_group_name": null,1093 "flair_name": null,1094 "flair_url": null,1095 "flair_color": null,1096 "flair_bg_color": null,1097 "flair_group_id": null,1098 "trust_level": 11099 },1100 {1101 "id": 1438,1102 "username": "vdw",1103 "name": "Chris",1104 "avatar_template": "/user_avatar/discuss.pytorch.org/vdw/{size}/10074_2.png",1105 "post_count": 1,1106 "primary_group_name": null,1107 "flair_name": null,1108 "flair_url": null,1109 "flair_color": null,1110 "flair_bg_color": null,1111 "flair_group_id": null,1112 "trust_level": 21113 },1114 {1115 "id": 3534,1116 "username": "ptrblck",1117 "name": "",1118 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",1119 "post_count": 1,1120 "primary_group_name": null,1121 "flair_name": null,1122 "flair_url": null,1123 "flair_color": null,1124 "flair_bg_color": null,1125 "flair_group_id": null,1126 "admin": true,1127 "moderator": true,1128 "trust_level": 21129 }1130 ],1131 "created_by": {1132 "id": 11810,1133 "username": "Chris_Freiburg",1134 "name": "Chris ",1135 "avatar_template": "/user_avatar/discuss.pytorch.org/chris_freiburg/{size}/14874_2.png"1136 },1137 "last_poster": {1138 "id": 11810,1139 "username": "Chris_Freiburg",1140 "name": "Chris ",1141 "avatar_template": "/user_avatar/discuss.pytorch.org/chris_freiburg/{size}/14874_2.png"1142 }1143 },1144 "bookmarks": []1145 },1146 {1147 "post_stream": {1148 "posts": [1149 {1150 "id": 205708,1151 "name": "Sally Goldin",1152 "username": "Sally_Goldin",1153 "avatar_template": "/user_avatar/discuss.pytorch.org/sally_goldin/{size}/18108_2.png",1154 "created_at": "2020-06-23T04:13:36.903Z",1155 "cooked": "<p>I am a newcomer to practical ML and PyTorch. I’m working on training an image discrimination model based mostly on textural features. My current model is very simple: 3 convolutional layers (plus ReLu/MaxPool), 3 fully connected layers. My latest validation gives me an accuracy of 61% for 5 classes, which is not sufficient for my application.</p>\n<p>Are there any guidelines for modifying my model to improve this performance? To someone as naive as I am, it appears there are almost infinite dimensions for experimentation. I could increase the number of filters in each layer (make the layers “broader”). I could increase the number of layers (“deeper”). I could try using dropout; I currently have about 1300 inputs per class, so I could well be having overfit problems. Of course I could also experiment with the changing the loss function (currently Cross-Entropy Loss) or the optimizer (Stochastic Gradient Descent), or other parameters.</p>\n<p>Can anyone offer suggestions on a systematic way to evaluate these many alternatives (as opposed to trial and error!) Or are there well-known rules of thumb as to what sort of modifications are likely to be most effective?</p>\n<p>I realize this is a very general question, compared to most in this forum. I hope it will generate some useful discussion.</p>\n<p>Thanks!</p>",1156 "post_number": 1,1157 "post_type": 1,1158 "posts_count": 13,1159 "updated_at": "2020-06-23T04:13:36.903Z",1160 "reply_count": 0,1161 "reply_to_post_number": null,1162 "quote_count": 0,1163 "incoming_link_count": 317,1164 "reads": 39,1165 "readers_count": 38,1166 "score": 1577.8,1167 "yours": false,1168 "topic_id": 86502,1169 "topic_slug": "broader-deeper-dropout-what-approach-to-try-first-to-increase-accuracy",1170 "display_username": "Sally Goldin",1171 "primary_group_name": null,1172 "flair_name": null,1173 "flair_url": null,1174 "flair_bg_color": null,1175 "flair_color": null,1176 "flair_group_id": null,1177 "badges_granted": [],1178 "version": 1,1179 "can_edit": false,1180 "can_delete": false,1181 "can_recover": false,1182 "can_see_hidden_post": false,1183 "can_wiki": false,1184 "read": true,1185 "user_title": null,1186 "bookmarked": false,1187 "actions_summary": [],1188 "moderator": false,1189 "admin": false,1190 "staff": false,1191 "user_id": 24797,1192 "hidden": false,1193 "trust_level": 2,1194 "deleted_at": null,1195 "user_deleted": false,1196 "edit_reason": null,1197 "can_view_edit_history": true,1198 "wiki": false,1199 "post_url": "/t/broader-deeper-dropout-what-approach-to-try-first-to-increase-accuracy/86502/1",1200 "can_accept_answer": false,