Anurag1734/cuda-error-resolution-analysis
07
1[2 {3 "post_stream": {4 "posts": [5 {6 "id": 298117,7 "name": "Younes Sellimi",8 "username": "Younes_Sellimi",9 "avatar_template": "/user_avatar/discuss.pytorch.org/younes_sellimi/{size}/40688_2.png",10 "created_at": "2021-07-27T16:37:09.808Z",11 "cooked": "<pre><code class=\"lang-auto\"></code></pre>\n<pre><code class=\"lang-auto\">import os\nimport numpy as np\nimport torch\nfrom torch.utils.data import Dataset\nimport matplotlib\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\n\n\nclass TSPDataset(Dataset):\n\n def __init__(self, size=50, num_samples=1e6, seed=None):\n super(TSPDataset, self).__init__()\n\n if seed is None:\n seed = np.random.randint(123456789)\n\n np.random.seed(seed)\n torch.manual_seed(seed)\n self.dataset = torch.rand((num_samples, 2, size))\n self.dynamic = torch.zeros(num_samples, 1, size)\n self.num_nodes = size\n self.size = num_samples\n \n\n def __len__(self):\n return self.size\n\n def __getitem__(self, idx):\n # (static, dynamic, start_loc)\n return (self.dataset[idx], self.dynamic[idx], self.dataset[idx, :, 0:1])\n\n\ndef update_mask(mask, dynamic, chosen_idx):\n \"\"\"Marks the visited city, so it can't be selected a second time.\"\"\"\n mask.scatter_(1, chosen_idx.unsqueeze(1), 0)\n return mask\n</code></pre>\n<pre><code class=\"lang-auto\"></code></pre>",12 "post_number": 1,13 "post_type": 1,14 "posts_count": 3,15 "updated_at": "2021-07-27T16:42:32.040Z",16 "reply_count": 0,17 "reply_to_post_number": null,18 "quote_count": 0,19 "incoming_link_count": 15,20 "reads": 5,21 "readers_count": 4,22 "score": 76.0,23 "yours": false,24 "topic_id": 127859,25 "topic_slug": "i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help",26 "display_username": "Younes Sellimi",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": 2,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": 47586,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/i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help/127859/1",56 "can_accept_answer": false,57 "can_unaccept_answer": false,58 "accepted_answer": false,59 "topic_accepted_answer": null,60 "can_vote": false61 },62 {63 "id": 298195,64 "name": "",65 "username": "ptrblck",66 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",67 "created_at": "2021-07-28T04:28:05.610Z",68 "cooked": "<p>I don’t quite understand the question in the title related to the posted code snippet.<br>\nCould you explain your use case as well as the problem you are facing a bit more?</p>",69 "post_number": 2,70 "post_type": 1,71 "posts_count": 3,72 "updated_at": "2021-07-28T04:28:05.610Z",73 "reply_count": 1,74 "reply_to_post_number": null,75 "quote_count": 0,76 "incoming_link_count": 4,77 "reads": 4,78 "readers_count": 3,79 "score": 40.8,80 "yours": false,81 "topic_id": 127859,82 "topic_slug": "i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help",83 "display_username": "",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": true,107 "admin": true,108 "staff": true,109 "user_id": 3534,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/i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help/127859/2",118 "can_accept_answer": false,119 "can_unaccept_answer": false,120 "accepted_answer": false,121 "topic_accepted_answer": null122 },123 {124 "id": 298336,125 "name": "Younes Sellimi",126 "username": "Younes_Sellimi",127 "avatar_template": "/user_avatar/discuss.pytorch.org/younes_sellimi/{size}/40688_2.png",128 "created_at": "2021-07-28T18:25:42.151Z",129 "cooked": "<p>Ok , i 'am looking for create a TSP envirenement to solving by deep reinforcment learning<br>\nthe class TSPDataset is my env_tsp, getItem is the methods to selecte the action in every step, i assume that is the key to fixed the start city in each predicted tour. The TSPdataset is a combination of dataset which contain the (xcoords, ycoords) and a dynamic vector contain the city index.<br>\nIn briefly i whish to help me, to fixed the start city that is city with index 1 and used it as a rule for agent policy .<br>\nfor example : i want to give me a permutatio n of city like this:<br>\n0,4,8,1,4,9…,0<br>\n0,1,3,9,5,7,…,0<br>\nthank’s</p>",130 "post_number": 3,131 "post_type": 1,132 "posts_count": 3,133 "updated_at": "2021-07-28T18:25:42.151Z",134 "reply_count": 0,135 "reply_to_post_number": 2,136 "quote_count": 0,137 "incoming_link_count": 2,138 "reads": 4,139 "readers_count": 3,140 "score": 10.8,141 "yours": false,142 "topic_id": 127859,143 "topic_slug": "i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help",144 "display_username": "Younes Sellimi",145 "primary_group_name": null,146 "flair_name": null,147 "flair_url": null,148 "flair_bg_color": null,149 "flair_color": null,150 "flair_group_id": null,151 "badges_granted": [],152 "version": 1,153 "can_edit": false,154 "can_delete": false,155 "can_recover": false,156 "can_see_hidden_post": false,157 "can_wiki": false,158 "read": true,159 "user_title": null,160 "reply_to_user": {161 "id": 3534,162 "username": "ptrblck",163 "name": "",164 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png"165 },166 "bookmarked": false,167 "actions_summary": [],168 "moderator": false,169 "admin": false,170 "staff": false,171 "user_id": 47586,172 "hidden": false,173 "trust_level": 1,174 "deleted_at": null,175 "user_deleted": false,176 "edit_reason": null,177 "can_view_edit_history": true,178 "wiki": false,179 "post_url": "/t/i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help/127859/3",180 "can_accept_answer": false,181 "can_unaccept_answer": false,182 "accepted_answer": false,183 "topic_accepted_answer": null184 }185 ],186 "stream": [187 298117,188 298195,189 298336190 ]191 },192 "timeline_lookup": [193 [194 1,195 1551196 ],197 [198 3,199 1550200 ]201 ],202 "suggested_topics": [203 {204 "fancy_title": "TruncatedNormal loc argument",205 "id": 220898,206 "title": "TruncatedNormal loc argument",207 "slug": "truncatednormal-loc-argument",208 "posts_count": 4,209 "reply_count": 1,210 "highest_post_number": 4,211 "image_url": null,212 "created_at": "2025-06-18T09:07:00.537Z",213 "last_posted_at": "2025-06-19T07:24:25.681Z",214 "bumped": true,215 "bumped_at": "2025-06-19T07:24:25.681Z",216 "archetype": "regular",217 "unseen": false,218 "pinned": false,219 "unpinned": null,220 "visible": true,221 "closed": false,222 "archived": false,223 "bookmarked": null,224 "liked": null,225 "tags_descriptions": {},226 "like_count": 3,227 "views": 49,228 "category_id": 6,229 "featured_link": null,230 "has_accepted_answer": true,231 "posters": [232 {233 "extras": null,234 "description": "Original Poster",235 "user": {236 "id": 83384,237 "username": "alicemabille",238 "name": "Alice Mabille",239 "avatar_template": "/user_avatar/discuss.pytorch.org/alicemabille/{size}/76264_2.png",240 "trust_level": 1241 }242 },243 {244 "extras": null,245 "description": "Frequent Poster, Accepted Answer",246 "user": {247 "id": 18088,248 "username": "KFrank",249 "name": "K. Frank",250 "avatar_template": "/letter_avatar_proxy/v4/letter/k/ecb155/{size}.png",251 "trust_level": 2252 }253 },254 {255 "extras": null,256 "description": "Frequent Poster",257 "user": {258 "id": 3534,259 "username": "ptrblck",260 "name": "",261 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",262 "admin": true,263 "moderator": true,264 "trust_level": 2265 }266 },267 {268 "extras": "latest",269 "description": "Most Recent Poster",270 "user": {271 "id": 33609,272 "username": "vmoens",273 "name": "Vincent Moens",274 "avatar_template": "/user_avatar/discuss.pytorch.org/vmoens/{size}/26121_2.png",275 "trust_level": 2276 }277 }278 ]279 },280 {281 "fancy_title": "RTX 5090 interconnection with pytorch",282 "id": 221631,283 "title": "RTX 5090 interconnection with pytorch",284 "slug": "rtx-5090-interconnection-with-pytorch",285 "posts_count": 7,286 "reply_count": 5,287 "highest_post_number": 7,288 "image_url": null,289 "created_at": "2025-07-18T08:31:51.623Z",290 "last_posted_at": "2025-07-28T13:49:22.043Z",291 "bumped": true,292 "bumped_at": "2025-07-28T13:49:22.043Z",293 "archetype": "regular",294 "unseen": false,295 "pinned": false,296 "unpinned": null,297 "visible": true,298 "closed": false,299 "archived": false,300 "bookmarked": null,301 "liked": null,302 "tags_descriptions": {},303 "like_count": 3,304 "views": 169,305 "category_id": 6,306 "featured_link": null,307 "has_accepted_answer": false,308 "posters": [309 {310 "extras": "latest",311 "description": "Original Poster, Most Recent Poster",312 "user": {313 "id": 85140,314 "username": "AliNoutash",315 "name": "",316 "avatar_template": "/letter_avatar_proxy/v4/letter/a/7bcc69/{size}.png",317 "trust_level": 1318 }319 },320 {321 "extras": null,322 "description": "Frequent Poster",323 "user": {324 "id": 3534,325 "username": "ptrblck",326 "name": "",327 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",328 "admin": true,329 "moderator": true,330 "trust_level": 2331 }332 }333 ]334 },335 {336 "fancy_title": "What loss function should the inner loop of MAML use?",337 "id": 214371,338 "title": "What loss function should the inner loop of MAML use?",339 "slug": "what-loss-function-should-the-inner-loop-of-maml-use",340 "posts_count": 3,341 "reply_count": 0,342 "highest_post_number": 4,343 "image_url": null,344 "created_at": "2024-12-18T18:52:49.378Z",345 "last_posted_at": "2025-06-27T18:47:36.830Z",346 "bumped": true,347 "bumped_at": "2025-06-27T18:47:36.830Z",348 "archetype": "regular",349 "unseen": false,350 "pinned": false,351 "unpinned": null,352 "visible": true,353 "closed": false,354 "archived": false,355 "bookmarked": null,356 "liked": null,357 "tags_descriptions": {},358 "like_count": 0,359 "views": 84,360 "category_id": 6,361 "featured_link": null,362 "has_accepted_answer": false,363 "posters": [364 {365 "extras": null,366 "description": "Original Poster",367 "user": {368 "id": 81535,369 "username": "Vulcan88",370 "name": "Mark Taylor",371 "avatar_template": "/user_avatar/discuss.pytorch.org/vulcan88/{size}/74543_2.png",372 "trust_level": 1373 }374 },375 {376 "extras": null,377 "description": "Frequent Poster",378 "user": {379 "id": 84857,380 "username": "clark598dahl",381 "name": "Clark Dahl",382 "avatar_template": "/letter_avatar_proxy/v4/letter/c/958977/{size}.png",383 "trust_level": 0384 }385 },386 {387 "extras": "latest",388 "description": "Most Recent Poster",389 "user": {390 "id": 84865,391 "username": "Hamza_Javaid",392 "name": "Hamza Javaid",393 "avatar_template": "/user_avatar/discuss.pytorch.org/hamza_javaid/{size}/77517_2.png",394 "trust_level": 2395 }396 }397 ]398 },399 {400 "fancy_title": "Training Machine Learning Model In Browser For Reinforcement Learning",401 "id": 218074,402 "title": "Training Machine Learning Model In Browser For Reinforcement Learning",403 "slug": "training-machine-learning-model-in-browser-for-reinforcement-learning",404 "posts_count": 1,405 "reply_count": 0,406 "highest_post_number": 1,407 "image_url": null,408 "created_at": "2025-03-20T13:12:14.662Z",409 "last_posted_at": "2025-03-20T13:12:14.696Z",410 "bumped": true,411 "bumped_at": "2025-03-20T13:12:14.696Z",412 "archetype": "regular",413 "unseen": false,414 "pinned": false,415 "unpinned": null,416 "visible": true,417 "closed": false,418 "archived": false,419 "bookmarked": null,420 "liked": null,421 "tags_descriptions": {},422 "like_count": 0,423 "views": 78,424 "category_id": 6,425 "featured_link": null,426 "has_accepted_answer": false,427 "posters": [428 {429 "extras": "latest single",430 "description": "Original Poster, Most Recent Poster",431 "user": {432 "id": 83382,433 "username": "Sliferslacker",434 "name": "",435 "avatar_template": "/letter_avatar_proxy/v4/letter/s/ecccb3/{size}.png",436 "trust_level": 1437 }438 }439 ]440 },441 {442 "fancy_title": "Batching a multicategorical spec",443 "id": 221780,444 "title": "Batching a multicategorical spec",445 "slug": "batching-a-multicategorical-spec",446 "posts_count": 5,447 "reply_count": 2,448 "highest_post_number": 5,449 "image_url": null,450 "created_at": "2025-07-24T11:34:39.452Z",451 "last_posted_at": "2025-08-27T07:41:52.199Z",452 "bumped": true,453 "bumped_at": "2025-08-27T07:41:52.199Z",454 "archetype": "regular",455 "unseen": false,456 "pinned": false,457 "unpinned": null,458 "visible": true,459 "closed": false,460 "archived": false,461 "bookmarked": null,462 "liked": null,463 "tags_descriptions": {},464 "like_count": 0,465 "views": 83,466 "category_id": 6,467 "featured_link": null,468 "has_accepted_answer": false,469 "posters": [470 {471 "extras": "latest",472 "description": "Original Poster, Most Recent Poster",473 "user": {474 "id": 74393,475 "username": "rsarpongstreetor",476 "name": "Richard Sarpong-Streetor",477 "avatar_template": "/user_avatar/discuss.pytorch.org/rsarpongstreetor/{size}/68703_2.png",478 "trust_level": 1479 }480 },481 {482 "extras": null,483 "description": "Frequent Poster",484 "user": {485 "id": 33609,486 "username": "vmoens",487 "name": "Vincent Moens",488 "avatar_template": "/user_avatar/discuss.pytorch.org/vmoens/{size}/26121_2.png",489 "trust_level": 2490 }491 }492 ]493 }494 ],495 "tags_descriptions": {},496 "fancy_title": "I wanna to fixed the start city 0 for each tour solution…. please i need some help?",497 "id": 127859,498 "title": "I wanna to fixed the start city 0 for each tour solution.... please i need some help?",499 "posts_count": 3,500 "created_at": "2021-07-27T16:37:09.740Z",501 "views": 631,502 "reply_count": 1,503 "like_count": 1,504 "last_posted_at": "2021-07-28T18:25:42.151Z",505 "visible": true,506 "closed": false,507 "archived": false,508 "has_summary": false,509 "archetype": "regular",510 "slug": "i-wanna-to-fixed-the-start-city-0-for-each-tour-solution-please-i-need-some-help",511 "category_id": 6,512 "word_count": 285,513 "deleted_at": null,514 "user_id": 47586,515 "featured_link": null,516 "pinned_globally": false,517 "pinned_at": null,518 "pinned_until": null,519 "image_url": null,520 "slow_mode_seconds": 0,521 "draft": null,522 "draft_key": "topic_127859",523 "draft_sequence": null,524 "unpinned": null,525 "pinned": false,526 "current_post_number": 1,527 "highest_post_number": 3,528 "deleted_by": null,529 "actions_summary": [530 {531 "id": 4,532 "count": 0,533 "hidden": false,534 "can_act": false535 },536 {537 "id": 8,538 "count": 0,539 "hidden": false,540 "can_act": false541 },542 {543 "id": 10,544 "count": 0,545 "hidden": false,546 "can_act": false547 },548 {549 "id": 7,550 "count": 0,551 "hidden": false,552 "can_act": false553 }554 ],555 "chunk_size": 20,556 "bookmarked": false,557 "topic_timer": null,558 "message_bus_last_id": 0,559 "participant_count": 2,560 "show_read_indicator": false,561 "thumbnails": null,562 "slow_mode_enabled_until": null,563 "can_vote": false,564 "vote_count": 0,565 "user_voted": false,566 "discourse_zendesk_plugin_zendesk_id": null,567 "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",568 "details": {569 "can_edit": false,570 "notification_level": 1,571 "participants": [572 {573 "id": 47586,574 "username": "Younes_Sellimi",575 "name": "Younes Sellimi",576 "avatar_template": "/user_avatar/discuss.pytorch.org/younes_sellimi/{size}/40688_2.png",577 "post_count": 2,578 "primary_group_name": null,579 "flair_name": null,580 "flair_url": null,581 "flair_color": null,582 "flair_bg_color": null,583 "flair_group_id": null,584 "trust_level": 1585 },586 {587 "id": 3534,588 "username": "ptrblck",589 "name": "",590 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",591 "post_count": 1,592 "primary_group_name": null,593 "flair_name": null,594 "flair_url": null,595 "flair_color": null,596 "flair_bg_color": null,597 "flair_group_id": null,598 "admin": true,599 "moderator": true,600 "trust_level": 2601 }602 ],603 "created_by": {604 "id": 47586,605 "username": "Younes_Sellimi",606 "name": "Younes Sellimi",607 "avatar_template": "/user_avatar/discuss.pytorch.org/younes_sellimi/{size}/40688_2.png"608 },609 "last_poster": {610 "id": 47586,611 "username": "Younes_Sellimi",612 "name": "Younes Sellimi",613 "avatar_template": "/user_avatar/discuss.pytorch.org/younes_sellimi/{size}/40688_2.png"614 }615 },616 "bookmarks": []617 },618 {619 "post_stream": {620 "posts": [621 {622 "id": 296601,623 "name": "",624 "username": "iamctR",625 "avatar_template": "/user_avatar/discuss.pytorch.org/iamctr/{size}/40412_2.png",626 "created_at": "2021-07-18T21:39:45.753Z",627 "cooked": "<p>Hi all, I want to parametrize two Gaussian distributions, but their parameters are related. But it seems like that the variable will be freed during the training. What can I do to fix this problem?<br>\nHere is the minimum code. Thank you!</p>\n<pre><code class=\"lang-auto\">import torch.nn as nn\nimport torch.distributions as D\nclass GaussianModel(nn.Module):\n def __init__(self):\n super(GaussianModel, self).__init__()\n self.v1 = nn.Parameter(torch.zeros(1))\n self.v2 = self.v1*2\n self.g1=D.Normal(torch.tensor([4.0]), self.v1)\n self.g2=D.Normal(torch.tensor([4.0]), self.v2)\n def forward(self,x):\n return torch.mean(self.g1.log_prob(x)+self.g2.log_prob(x))\nmodel=GaussianModel()\nopt=torch.optim.SGD(params=model.parameters(), lr=1e-3)\nfor i in range(10):\n opt.zero_grad()\n x=torch.randn(10)\n loss=model(x)\n loss.backward()\n opt.step()\n</code></pre>\n<p>And this is the message from terminal:</p>\n<pre><code class=\"lang-auto\">RuntimeErrorTraceback (most recent call last)\n<ipython-input-92-46e3175cfeff> in <module>\n 3 x=torch.randn(10)\n 4 loss=model(x)\n----> 5 loss.backward()\n 6 opt.step()\n 7 # model.p1.detach()\n\n~/.virtualenvs/ddp-pytorch/lib/python3.6/site-packages/torch/tensor.py in backward(self, gradient, retain_graph, create_graph)\n 219 retain_graph=retain_graph,\n 220 create_graph=create_graph)\n--> 221 torch.autograd.backward(self, gradient, retain_graph, create_graph)\n 222 \n 223 def register_hook(self, hook):\n\n~/.virtualenvs/ddp-pytorch/lib/python3.6/site-packages/torch/autograd/__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)\n 130 Variable._execution_engine.run_backward(\n 131 tensors, grad_tensors_, retain_graph, create_graph,\n--> 132 allow_unreachable=True) # allow_unreachable flag\n 133 \n 134 \n\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\n</code></pre>",628 "post_number": 1,629 "post_type": 1,630 "posts_count": 3,631 "updated_at": "2021-07-18T21:41:01.052Z",632 "reply_count": 1,633 "reply_to_post_number": null,634 "quote_count": 0,635 "incoming_link_count": 241,636 "reads": 9,637 "readers_count": 8,638 "score": 1206.6,639 "yours": false,640 "topic_id": 127102,641 "topic_slug": "parametrized-gaussian-shared-same-trainable-parameter",642 "display_username": "",643 "primary_group_name": null,644 "flair_name": null,645 "flair_url": null,646 "flair_bg_color": null,647 "flair_color": null,648 "flair_group_id": null,649 "badges_granted": [],650 "version": 2,651 "can_edit": false,652 "can_delete": false,653 "can_recover": false,654 "can_see_hidden_post": false,655 "can_wiki": false,656 "read": true,657 "user_title": null,658 "bookmarked": false,659 "actions_summary": [],660 "moderator": false,661 "admin": false,662 "staff": false,663 "user_id": 47331,664 "hidden": false,665 "trust_level": 1,666 "deleted_at": null,667 "user_deleted": false,668 "edit_reason": null,669 "can_view_edit_history": true,670 "wiki": false,671 "post_url": "/t/parametrized-gaussian-shared-same-trainable-parameter/127102/1",672 "can_accept_answer": false,673 "can_unaccept_answer": false,674 "accepted_answer": false,675 "topic_accepted_answer": null,676 "can_vote": false677 },678 {679 "id": 296715,680 "name": "K. Frank",681 "username": "KFrank",682 "avatar_template": "/letter_avatar_proxy/v4/letter/k/ecb155/{size}.png",683 "created_at": "2021-07-19T15:44:40.739Z",684 "cooked": "<p>Hi Iam!</p>\n<aside class=\"quote no-group\" data-username=\"iamctR\" data-post=\"1\" data-topic=\"127102\" data-full=\"true\">\n<div class=\"title\">\n<div class=\"quote-controls\"></div>\n<img loading=\"lazy\" alt=\"\" width=\"24\" height=\"24\" src=\"https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/iamctr/48/40412_2.png\" class=\"avatar\"> iamctR:</div>\n<blockquote>\n<pre><code class=\"lang-auto\">class GaussianModel(nn.Module):\n def __init__(self):\n super(GaussianModel, self).__init__()\n self.v1 = nn.Parameter(torch.zeros(1))\n self.v2 = self.v1*2\n self.g1=D.Normal(torch.tensor([4.0]), self.v1)\n self.g2=D.Normal(torch.tensor([4.0]), self.v2)\n def forward(self,x):\n return torch.mean(self.g1.log_prob(x)+self.g2.log_prob(x))\n</code></pre>\n</blockquote>\n</aside>\n<p>The problem is that <code>self.v2 = self.v1*2</code> creates a new tensor<br>\nfor <code>v2</code>, and does so only once at <code>__init__()</code> time. Subsequent<br>\nupdates to <code>v1</code> (made by the optimizer) never get reflected in <code>v2</code><br>\n(nor in <code>g2</code>).</p>\n<p>(I don’t really understand how this leads to the specific autograd<br>\n<code>RuntimeError</code> you see, but this is the key error in your code.)</p>\n<p>I would probably just do:</p>\n<pre data-code-wrap=\"python\"><code class=\"lang-python\">class GaussianModel (nn.Module):\n def __init__ (self):\n super (GaussianModel, self).__init__()\n self.v1 = nn.Parameter (torch.zeros (1))\n def forward (self, x):\n return torch.mean (D.Normal (torch.tensor ([4.0]), self.v1).log_prob (x) + D.Normal (torch.tensor ([4.0]), 2 * self.v1).log_prob (x))\n</code></pre>\n<p>I believe you could also implement this as:</p>\n<pre data-code-wrap=\"python\"><code class=\"lang-python\">class GaussianModel (nn.Module):\n def __init__ (self):\n super (GaussianModel, self).__init__()\n self.v1 = nn.Parameter (torch.zeros (1))\n self.v2 = self.v1 * 2 # these initial values will be overwritten\n self.g1=D.Normal (torch.tensor ([4.0]), self.v1)\n self.g2=D.Normal (torch.tensor ([4.0]), self.v2)\n def forward (self, x):\n self.v2.copy_ (self.v1 * 2)\n return torch.mean (self.g1.log_prob (x)+self.g2.log_prob (x))\n</code></pre>\n<p>but, to me, my first version is more readable.</p>\n<p>As an aside, you are initializing <code>g1</code> and <code>g2</code> with a <code>scale</code> (standard<br>\ndeviation) of <code>0.0</code>. I would expect this to lead to <code>nan</code>s in your first<br>\nforward pass. Up-to-date versions of pytorch will flag this:</p>\n<pre><code class=\"lang-plaintext\">>>> import torch\n>>> torch.__version__\n'1.9.0'\n>>> d = torch.distributions.Normal (torch.tensor ([4.0]), torch.zeros (1), validate_args = False)\n>>> d\nNormal(loc: tensor([4.]), scale: tensor([0.]))\n>>> d.log_prob (torch.tensor ([1.0]))\ntensor([nan])\n>>> d = torch.distributions.Normal (torch.tensor ([4.0]), torch.zeros (1))\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"C:\\Users\\LisaBrown\\Documents\\admin\\programs\\Miniconda3\\lib\\site-packages\\torch\\distributions\\normal.py\", line 50, in __init__\n super(Normal, self).__init__(batch_shape, validate_args=validate_args)\n File \"C:\\Users\\LisaBrown\\Documents\\admin\\programs\\Miniconda3\\lib\\site-packages\\torch\\distributions\\distribution.py\", line 53, in __init__\n raise ValueError(\"The parameter {} has invalid values\".format(param))\nValueError: The parameter scale has invalid values\n</code></pre>\n<p>Best.</p>\n<p>K. Frank</p>",685 "post_number": 2,686 "post_type": 1,687 "posts_count": 3,688 "updated_at": "2021-07-19T15:44:40.739Z",689 "reply_count": 1,690 "reply_to_post_number": null,691 "quote_count": 1,692 "incoming_link_count": 3,693 "reads": 9,694 "readers_count": 8,695 "score": 36.6,696 "yours": false,697 "topic_id": 127102,698 "topic_slug": "parametrized-gaussian-shared-same-trainable-parameter",699 "display_username": "K. Frank",700 "primary_group_name": null,701 "flair_name": null,702 "flair_url": null,703 "flair_bg_color": null,704 "flair_color": null,705 "flair_group_id": null,706 "badges_granted": [],707 "version": 1,708 "can_edit": false,709 "can_delete": false,710 "can_recover": false,711 "can_see_hidden_post": false,712 "can_wiki": false,713 "read": true,714 "user_title": null,715 "bookmarked": false,716 "actions_summary": [717 {718 "id": 2,719 "count": 1720 }721 ],722 "moderator": false,723 "admin": false,724 "staff": false,725 "user_id": 18088,726 "hidden": false,727 "trust_level": 2,728 "deleted_at": null,729 "user_deleted": false,730 "edit_reason": null,731 "can_view_edit_history": true,732 "wiki": false,733 "post_url": "/t/parametrized-gaussian-shared-same-trainable-parameter/127102/2",734 "can_accept_answer": false,735 "can_unaccept_answer": false,736 "accepted_answer": false,737 "topic_accepted_answer": null738 },739 {740 "id": 298333,741 "name": "",742 "username": "iamctR",743 "avatar_template": "/user_avatar/discuss.pytorch.org/iamctr/{size}/40412_2.png",744 "created_at": "2021-07-28T18:00:02.245Z",745 "cooked": "<p>Thank you Frank! It works!</p>",746 "post_number": 3,747 "post_type": 1,748 "posts_count": 3,749 "updated_at": "2021-07-28T18:00:02.245Z",750 "reply_count": 0,751 "reply_to_post_number": 2,752 "quote_count": 0,753 "incoming_link_count": 0,754 "reads": 7,755 "readers_count": 6,756 "score": 1.2,757 "yours": false,758 "topic_id": 127102,759 "topic_slug": "parametrized-gaussian-shared-same-trainable-parameter",760 "display_username": "",761 "primary_group_name": null,762 "flair_name": null,763 "flair_url": null,764 "flair_bg_color": null,765 "flair_color": null,766 "flair_group_id": null,767 "badges_granted": [],768 "version": 1,769 "can_edit": false,770 "can_delete": false,771 "can_recover": false,772 "can_see_hidden_post": false,773 "can_wiki": false,774 "read": true,775 "user_title": null,776 "reply_to_user": {777 "id": 18088,778 "username": "KFrank",779 "name": "K. Frank",780 "avatar_template": "/letter_avatar_proxy/v4/letter/k/ecb155/{size}.png"781 },782 "bookmarked": false,783 "actions_summary": [],784 "moderator": false,785 "admin": false,786 "staff": false,787 "user_id": 47331,788 "hidden": false,789 "trust_level": 1,790 "deleted_at": null,791 "user_deleted": false,792 "edit_reason": null,793 "can_view_edit_history": true,794 "wiki": false,795 "post_url": "/t/parametrized-gaussian-shared-same-trainable-parameter/127102/3",796 "can_accept_answer": false,797 "can_unaccept_answer": false,798 "accepted_answer": false,799 "topic_accepted_answer": null800 }801 ],802 "stream": [803 296601,804 296715,805 298333806 ]807 },808 "timeline_lookup": [809 [810 1,811 1560812 ],813 [814 2,815 1559816 ],817 [818 3,819 1550820 ]821 ],822 "suggested_topics": [823 {824 "fancy_title": "FlexAttention customizability",825 "id": 216077,826 "title": "FlexAttention customizability",827 "slug": "flexattention-customizability",828 "posts_count": 1,829 "reply_count": 0,830 "highest_post_number": 1,831 "image_url": null,832 "created_at": "2025-01-31T03:29:15.775Z",833 "last_posted_at": "2025-01-31T03:29:15.819Z",834 "bumped": true,835 "bumped_at": "2025-01-31T03:29:15.819Z",836 "archetype": "regular",837 "unseen": false,838 "pinned": false,839 "unpinned": null,840 "visible": true,841 "closed": false,842 "archived": false,843 "bookmarked": null,844 "liked": null,845 "tags_descriptions": {},846 "like_count": 0,847 "views": 104,848 "category_id": 1,849 "featured_link": null,850 "has_accepted_answer": false,851 "posters": [852 {853 "extras": "latest single",854 "description": "Original Poster, Most Recent Poster",855 "user": {856 "id": 10472,857 "username": "veritas",858 "name": "",859 "avatar_template": "/user_avatar/discuss.pytorch.org/veritas/{size}/11018_2.png",860 "trust_level": 2861 }862 }863 ]864 },865 {866 "fancy_title": "Why is custom RNN implementation so slow?",867 "id": 213168,868 "title": "Why is custom RNN implementation so slow?",869 "slug": "why-is-custom-rnn-implementation-so-slow",870 "posts_count": 6,871 "reply_count": 4,872 "highest_post_number": 6,873 "image_url": null,874 "created_at": "2024-11-19T19:27:11.458Z",875 "last_posted_at": "2024-11-23T01:41:42.810Z",876 "bumped": true,877 "bumped_at": "2024-11-23T01:41:42.810Z",878 "archetype": "regular",879 "unseen": false,880 "pinned": false,881 "unpinned": null,882 "visible": true,883 "closed": false,884 "archived": false,885 "bookmarked": null,886 "liked": null,887 "tags_descriptions": {},888 "like_count": 3,889 "views": 219,890 "category_id": 1,891 "featured_link": null,892 "has_accepted_answer": false,893 "posters": [894 {895 "extras": null,896 "description": "Original Poster",897 "user": {898 "id": 81008,899 "username": "omnomc",900 "name": "",901 "avatar_template": "/user_avatar/discuss.pytorch.org/omnomc/{size}/74086_2.png",902 "trust_level": 1903 }904 },905 {906 "extras": null,907 "description": "Frequent Poster",908 "user": {909 "id": 3534,910 "username": "ptrblck",911 "name": "",912 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",913 "admin": true,914 "moderator": true,915 "trust_level": 2916 }917 },918 {919 "extras": "latest",920 "description": "Most Recent Poster",921 "user": {922 "id": 41458,923 "username": "J_Johnson",924 "name": "J Johnson",925 "avatar_template": "/user_avatar/discuss.pytorch.org/j_johnson/{size}/55494_2.png",926 "trust_level": 2927 }928 }929 ]930 },931 {932 "fancy_title": "Are there two valid Gradient Descent approaches in PyTorch?",933 "id": 214273,934 "title": "Are there two valid Gradient Descent approaches in PyTorch?",935 "slug": "are-there-two-valid-gradient-descent-approaches-in-pytorch",936 "posts_count": 4,937 "reply_count": 2,938 "highest_post_number": 4,939 "image_url": null,940 "created_at": "2024-12-16T13:08:08.779Z",941 "last_posted_at": "2024-12-30T10:37:15.573Z",942 "bumped": true,943 "bumped_at": "2024-12-30T10:37:15.573Z",944 "archetype": "regular",945 "unseen": false,946 "pinned": false,947 "unpinned": null,948 "visible": true,949 "closed": false,950 "archived": false,951 "bookmarked": null,952 "liked": null,953 "tags_descriptions": {},954 "like_count": 2,955 "views": 65,956 "category_id": 1,957 "featured_link": null,958 "has_accepted_answer": false,959 "posters": [960 {961 "extras": null,962 "description": "Original Poster",963 "user": {964 "id": 80540,965 "username": "na50r",966 "name": "",967 "avatar_template": "/user_avatar/discuss.pytorch.org/na50r/{size}/73632_2.png",968 "trust_level": 1969 }970 },971 {972 "extras": "latest",973 "description": "Most Recent Poster",974 "user": {975 "id": 211,976 "username": "albanD",977 "name": "Alban D",978 "avatar_template": "/user_avatar/discuss.pytorch.org/alband/{size}/215_2.png",979 "admin": true,980 "moderator": true,981 "trust_level": 4982 }983 }984 ]985 },986 {987 "fancy_title": "Pytorch question : loss backward takes 8 seconds!",988 "id": 213471,989 "title": "Pytorch question : loss backward takes 8 seconds!",990 "slug": "pytorch-question-loss-backward-takes-8-seconds",991 "posts_count": 4,992 "reply_count": 2,993 "highest_post_number": 4,994 "image_url": null,995 "created_at": "2024-11-26T13:49:34.401Z",996 "last_posted_at": "2024-12-03T13:15:33.417Z",997 "bumped": true,998 "bumped_at": "2024-12-03T13:15:33.417Z",999 "archetype": "regular",1000 "unseen": false,1001 "pinned": false,1002 "unpinned": null,1003 "visible": true,1004 "closed": false,1005 "archived": false,1006 "bookmarked": null,1007 "liked": null,1008 "tags_descriptions": {},1009 "like_count": 1,1010 "views": 74,1011 "category_id": 1,1012 "featured_link": null,1013 "has_accepted_answer": false,1014 "posters": [1015 {1016 "extras": null,1017 "description": "Original Poster",1018 "user": {1019 "id": 81134,1020 "username": "LeslisXu",1021 "name": "Silent_Hill",1022 "avatar_template": "/user_avatar/discuss.pytorch.org/leslisxu/{size}/74207_2.png",1023 "trust_level": 01024 }1025 },1026 {1027 "extras": null,1028 "description": "Frequent Poster",1029 "user": {1030 "id": 81135,1031 "username": "Leslie_Green",1032 "name": "Leslie_Green",1033 "avatar_template": "/letter_avatar_proxy/v4/letter/l/53a042/{size}.png",1034 "trust_level": 01035 }1036 },1037 {1038 "extras": "latest",1039 "description": "Most Recent Poster",1040 "user": {1041 "id": 3534,1042 "username": "ptrblck",1043 "name": "",1044 "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",1045 "admin": true,1046 "moderator": true,1047 "trust_level": 21048 }1049 }1050 ]1051 },1052 {1053 "fancy_title": "Advice to _overfit_ a model",1054 "id": 216542,1055 "title": "Advice to _overfit_ a model",1056 "slug": "advice-to-overfit-a-model",1057 "posts_count": 3,1058 "reply_count": 1,1059 "highest_post_number": 3,1060 "image_url": null,1061 "created_at": "2025-02-11T15:41:54.999Z",1062 "last_posted_at": "2025-02-12T19:46:30.826Z",1063 "bumped": true,1064 "bumped_at": "2025-02-12T19:46:30.826Z",1065 "archetype": "regular",1066 "unseen": false,1067 "pinned": false,1068 "unpinned": null,1069 "visible": true,1070 "closed": false,1071 "archived": false,1072 "bookmarked": null,1073 "liked": null,1074 "tags_descriptions": {},1075 "like_count": 0,1076 "views": 45,1077 "category_id": 1,1078 "featured_link": null,1079 "has_accepted_answer": false,1080 "posters": [1081 {1082 "extras": "latest",1083 "description": "Original Poster, Most Recent Poster",1084 "user": {1085 "id": 78333,1086 "username": "emerth",1087 "name": "",1088 "avatar_template": "/user_avatar/discuss.pytorch.org/emerth/{size}/75379_2.png",1089 "trust_level": 11090 }1091 },1092 {1093 "extras": null,1094 "description": "Frequent Poster",1095 "user": {1096 "id": 18088,1097 "username": "KFrank",1098 "name": "K. Frank",1099 "avatar_template": "/letter_avatar_proxy/v4/letter/k/ecb155/{size}.png",1100 "trust_level": 21101 }1102 }1103 ]1104 }1105 ],1106 "tags_descriptions": {},1107 "fancy_title": "Parametrized Gaussian shared same trainable parameter",1108 "id": 127102,1109 "title": "Parametrized Gaussian shared same trainable parameter",1110 "posts_count": 3,1111 "created_at": "2021-07-18T21:39:45.701Z",1112 "views": 839,1113 "reply_count": 1,1114 "like_count": 1,1115 "last_posted_at": "2021-07-28T18:00:02.245Z",1116 "visible": true,1117 "closed": false,1118 "archived": false,1119 "has_summary": false,1120 "archetype": "regular",1121 "slug": "parametrized-gaussian-shared-same-trainable-parameter",1122 "category_id": 1,1123 "word_count": 717,1124 "deleted_at": null,1125 "user_id": 47331,1126 "featured_link": null,1127 "pinned_globally": false,1128 "pinned_at": null,1129 "pinned_until": null,1130 "image_url": null,1131 "slow_mode_seconds": 0,1132 "draft": null,1133 "draft_key": "topic_127102",1134 "draft_sequence": null,1135 "unpinned": null,1136 "pinned": false,1137 "current_post_number": 1,1138 "highest_post_number": 3,1139 "deleted_by": null,1140 "actions_summary": [1141 {1142 "id": 4,1143 "count": 0,1144 "hidden": false,1145 "can_act": false1146 },1147 {1148 "id": 8,1149 "count": 0,1150 "hidden": false,1151 "can_act": false1152 },1153 {1154 "id": 10,1155 "count": 0,1156 "hidden": false,1157 "can_act": false1158 },1159 {1160 "id": 7,1161 "count": 0,1162 "hidden": false,1163 "can_act": false1164 }1165 ],1166 "chunk_size": 20,1167 "bookmarked": false,1168 "topic_timer": null,1169 "message_bus_last_id": 0,1170 "participant_count": 2,1171 "show_read_indicator": false,1172 "thumbnails": null,1173 "slow_mode_enabled_until": null,1174 "can_vote": false,1175 "vote_count": 0,1176 "user_voted": false,1177 "discourse_zendesk_plugin_zendesk_id": null,1178 "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",1179 "details": {1180 "can_edit": false,1181 "notification_level": 1,1182 "participants": [1183 {1184 "id": 47331,1185 "username": "iamctR",1186 "name": "",1187 "avatar_template": "/user_avatar/discuss.pytorch.org/iamctr/{size}/40412_2.png",1188 "post_count": 2,1189 "primary_group_name": null,1190 "flair_name": null,1191 "flair_url": null,1192 "flair_color": null,1193 "flair_bg_color": null,1194 "flair_group_id": null,1195 "trust_level": 11196 },1197 {1198 "id": 18088,1199 "username": "KFrank",1200 "name": "K. Frank",