CoolFace
Datasetpublic

Anurag1734/cuda-error-resolution-analysis

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes7downloads
topics_batch_523.json67836 linesDownload Raw Back to raw
1[2  {3    "post_stream": {4      "posts": [5        {6          "id": 165483,7          "name": "Branikas",8          "username": "Branikas",9          "avatar_template": "/user_avatar/discuss.pytorch.org/branikas/{size}/20476_2.png",10          "created_at": "2020-02-12T16:35:55.392Z",11          "cooked": "<p>Hello everyone.</p>\n<p>I am trying to create an auto-encoder architecture for image segmentation using a framework for rotation invariance. The modules of this framework inherit from the torch.nn classes but have some extra attributes as well.<br>\nFor the Conv2d module, for example, they don’t have only the weight and bias attributes but some extra as well. When I train my network and save it normally (with with torch.save(model.state_dict(), PATH)) i notice that when I load it with model.load_state_dict(torch.load(PATH)) and try to predict an image I get errors referring to the keys of these extra attributes. More specifically, I get:  RuntimeError: Error(s) in loading state_dict :<br>\nMissing key(s) in state_dict: …<br>\nfor every convolutional block there is no value assigned for the extra attributes in the dictionary.<br>\nI suppose when the dictionary is created only the standard attributes of the model’s components (pooling, conv. etc) are considered for adding to the dictionary.<br>\nCan I somehow change that for custom classes that inherit from torch.nn modules?</p>\n<p>Thank you!</p>",12          "post_number": 1,13          "post_type": 1,14          "posts_count": 3,15          "updated_at": "2020-02-12T16:35:55.392Z",16          "reply_count": 0,17          "reply_to_post_number": null,18          "quote_count": 0,19          "incoming_link_count": 1023,20          "reads": 24,21          "readers_count": 23,22          "score": 5119.8,23          "yours": false,24          "topic_id": 69505,25          "topic_slug": "storing-and-loading-a-model-whose-modules-have-extra-attributes",26          "display_username": "Branikas",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": 24036,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/storing-and-loading-a-model-whose-modules-have-extra-attributes/69505/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": 165493,64          "name": "Juan Montesinos",65          "username": "JuanFMontesinos",66          "avatar_template": "/user_avatar/discuss.pytorch.org/juanfmontesinos/{size}/76115_2.png",67          "created_at": "2020-02-12T16:55:33.062Z",68          "cooked": "<p>I would say that it should work always you add nn.parameters or buffers which are the ones tracked by the state_dict.<br>\nIf you try to save other type of variables it will fail. I would recommend to pass them in the init function such that the constructor can recover them at the time of instantiating the class.</p>\n<p>Another possibility is you are kind of hardcoding them not using the tools provided which properly register parameters.</p>",69          "post_number": 2,70          "post_type": 1,71          "posts_count": 3,72          "updated_at": "2020-02-12T16:57:12.795Z",73          "reply_count": 1,74          "reply_to_post_number": null,75          "quote_count": 0,76          "incoming_link_count": 5,77          "reads": 24,78          "readers_count": 23,79          "score": 49.8,80          "yours": false,81          "topic_id": 69505,82          "topic_slug": "storing-and-loading-a-model-whose-modules-have-extra-attributes",83          "display_username": "Juan Montesinos",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": 9081,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/storing-and-loading-a-model-whose-modules-have-extra-attributes/69505/2",118          "can_accept_answer": false,119          "can_unaccept_answer": false,120          "accepted_answer": false,121          "topic_accepted_answer": null122        },123        {124          "id": 165495,125          "name": "Branikas",126          "username": "Branikas",127          "avatar_template": "/user_avatar/discuss.pytorch.org/branikas/{size}/20476_2.png",128          "created_at": "2020-02-12T16:59:15.803Z",129          "cooked": "<p>Thank you very much, I actually didn’t think of passing them in the init, struggling to integrate 2 models. I will try your suggestions.</p>",130          "post_number": 3,131          "post_type": 1,132          "posts_count": 3,133          "updated_at": "2020-02-12T16:59:15.803Z",134          "reply_count": 0,135          "reply_to_post_number": 2,136          "quote_count": 0,137          "incoming_link_count": 5,138          "reads": 20,139          "readers_count": 19,140          "score": 29.0,141          "yours": false,142          "topic_id": 69505,143          "topic_slug": "storing-and-loading-a-model-whose-modules-have-extra-attributes",144          "display_username": "Branikas",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": 9081,162            "username": "JuanFMontesinos",163            "name": "Juan Montesinos",164            "avatar_template": "/user_avatar/discuss.pytorch.org/juanfmontesinos/{size}/76115_2.png"165          },166          "bookmarked": false,167          "actions_summary": [],168          "moderator": false,169          "admin": false,170          "staff": false,171          "user_id": 24036,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/storing-and-loading-a-model-whose-modules-have-extra-attributes/69505/3",180          "can_accept_answer": false,181          "can_unaccept_answer": false,182          "accepted_answer": false,183          "topic_accepted_answer": null184        }185      ],186      "stream": [187        165483,188        165493,189        165495190      ]191    },192    "timeline_lookup": [193      [194        1,195        2082196      ]197    ],198    "suggested_topics": [199      {200        "fancy_title": "NVIDIA L40S-48Q and &ldquo;RuntimeError: CUDA error: operation not supported&rdquo;",201        "id": 212716,202        "title": "NVIDIA L40S-48Q and \"RuntimeError: CUDA error: operation not supported\"",203        "slug": "nvidia-l40s-48q-and-runtimeerror-cuda-error-operation-not-supported",204        "posts_count": 11,205        "reply_count": 9,206        "highest_post_number": 11,207        "image_url": null,208        "created_at": "2024-11-08T19:29:41.292Z",209        "last_posted_at": "2025-02-11T14:25:17.459Z",210        "bumped": true,211        "bumped_at": "2025-02-11T14:26:35.274Z",212        "archetype": "regular",213        "unseen": false,214        "pinned": false,215        "unpinned": null,216        "visible": true,217        "closed": false,218        "archived": false,219        "bookmarked": null,220        "liked": null,221        "tags_descriptions": {},222        "like_count": 1,223        "views": 1360,224        "category_id": 1,225        "featured_link": null,226        "has_accepted_answer": false,227        "posters": [228          {229            "extras": null,230            "description": "Original Poster",231            "user": {232              "id": 7291,233              "username": "Chris_Palmer",234              "name": "Chris Palmer",235              "avatar_template": "/user_avatar/discuss.pytorch.org/chris_palmer/{size}/12322_2.png",236              "trust_level": 1237            }238          },239          {240            "extras": null,241            "description": "Frequent Poster",242            "user": {243              "id": 3534,244              "username": "ptrblck",245              "name": "",246              "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",247              "admin": true,248              "moderator": true,249              "trust_level": 2250            }251          },252          {253            "extras": "latest",254            "description": "Most Recent Poster",255            "user": {256              "id": 82625,257              "username": "briskajanis1",258              "name": "Briskajanis1",259              "avatar_template": "/user_avatar/discuss.pytorch.org/briskajanis1/{size}/75599_2.png",260              "trust_level": 0261            }262          }263        ]264      },265      {266        "fancy_title": "Flash attention with padding mask or nested tensors",267        "id": 213327,268        "title": "Flash attention with padding mask or nested tensors",269        "slug": "flash-attention-with-padding-mask-or-nested-tensors",270        "posts_count": 3,271        "reply_count": 0,272        "highest_post_number": 3,273        "image_url": null,274        "created_at": "2024-11-22T20:49:24.448Z",275        "last_posted_at": "2025-08-30T16:54:44.355Z",276        "bumped": true,277        "bumped_at": "2025-08-30T16:54:44.355Z",278        "archetype": "regular",279        "unseen": false,280        "pinned": false,281        "unpinned": null,282        "visible": true,283        "closed": false,284        "archived": false,285        "bookmarked": null,286        "liked": null,287        "tags_descriptions": {},288        "like_count": 0,289        "views": 613,290        "category_id": 1,291        "featured_link": null,292        "has_accepted_answer": false,293        "posters": [294          {295            "extras": null,296            "description": "Original Poster",297            "user": {298              "id": 80680,299              "username": "SlavPsh",300              "name": "",301              "avatar_template": "/user_avatar/discuss.pytorch.org/slavpsh/{size}/73757_2.png",302              "trust_level": 1303            }304          },305          {306            "extras": null,307            "description": "Frequent Poster",308            "user": {309              "id": 85656,310              "username": "Kshitiz_Khandelwal",311              "name": "Kshitiz Khandelwal",312              "avatar_template": "/user_avatar/discuss.pytorch.org/kshitiz_khandelwal/{size}/78061_2.png",313              "trust_level": 0314            }315          },316          {317            "extras": "latest",318            "description": "Most Recent Poster",319            "user": {320              "id": 67276,321              "username": "Arunprakash-A",322              "name": "Arun Prakash A",323              "avatar_template": "/user_avatar/discuss.pytorch.org/arunprakash-a/{size}/78115_2.png",324              "trust_level": 2325            }326          }327        ]328      },329      {330        "fancy_title": "Restored optimizer always report: [rank0]: AssertionError: No inf checks were recorded for this optimizer",331        "id": 214495,332        "title": "Restored optimizer always report: [rank0]: AssertionError: No inf checks were recorded for this optimizer",333        "slug": "restored-optimizer-always-report-rank0-assertionerror-no-inf-checks-were-recorded-for-this-optimizer",334        "posts_count": 1,335        "reply_count": 0,336        "highest_post_number": 1,337        "image_url": null,338        "created_at": "2024-12-21T13:24:07.951Z",339        "last_posted_at": "2024-12-21T13:24:07.988Z",340        "bumped": true,341        "bumped_at": "2024-12-21T13:24:07.988Z",342        "archetype": "regular",343        "unseen": false,344        "pinned": false,345        "unpinned": null,346        "visible": true,347        "closed": false,348        "archived": false,349        "bookmarked": null,350        "liked": null,351        "tags_descriptions": {},352        "like_count": 0,353        "views": 107,354        "category_id": 1,355        "featured_link": null,356        "has_accepted_answer": false,357        "posters": [358          {359            "extras": "latest single",360            "description": "Original Poster, Most Recent Poster",361            "user": {362              "id": 17807,363              "username": "AlexLuya",364              "name": "Alex Luya",365              "avatar_template": "/user_avatar/discuss.pytorch.org/alexluya/{size}/15408_2.png",366              "trust_level": 1367            }368          }369        ]370      },371      {372        "fancy_title": "Problem in Backpropagation through a sample in Beta distribution in pytorch",373        "id": 215599,374        "title": "Problem in Backpropagation through a sample in Beta distribution in pytorch",375        "slug": "problem-in-backpropagation-through-a-sample-in-beta-distribution-in-pytorch",376        "posts_count": 2,377        "reply_count": 0,378        "highest_post_number": 2,379        "image_url": null,380        "created_at": "2025-01-19T16:54:31.198Z",381        "last_posted_at": "2025-01-19T17:14:39.424Z",382        "bumped": true,383        "bumped_at": "2025-01-19T17:14:39.424Z",384        "archetype": "regular",385        "unseen": false,386        "pinned": false,387        "unpinned": null,388        "visible": true,389        "closed": false,390        "archived": false,391        "bookmarked": null,392        "liked": null,393        "tags_descriptions": {},394        "like_count": 0,395        "views": 99,396        "category_id": 1,397        "featured_link": null,398        "has_accepted_answer": true,399        "posters": [400          {401            "extras": "latest single",402            "description": "Original Poster, Most Recent Poster, Accepted Answer",403            "user": {404              "id": 37790,405              "username": "Jimut123",406              "name": "Jimut Bahan Pal",407              "avatar_template": "/user_avatar/discuss.pytorch.org/jimut123/{size}/29864_2.png",408              "trust_level": 1409            }410          }411        ]412      },413      {414        "fancy_title": "Encoder Decoder Pytorch Predictions not matched for Time Series",415        "id": 212145,416        "title": "Encoder Decoder Pytorch Predictions not matched for Time Series",417        "slug": "encoder-decoder-pytorch-predictions-not-matched-for-time-series",418        "posts_count": 4,419        "reply_count": 2,420        "highest_post_number": 4,421        "image_url": null,422        "created_at": "2024-10-26T18:00:30.800Z",423        "last_posted_at": "2024-10-31T01:08:31.047Z",424        "bumped": true,425        "bumped_at": "2024-10-31T01:08:31.047Z",426        "archetype": "regular",427        "unseen": false,428        "pinned": false,429        "unpinned": null,430        "visible": true,431        "closed": false,432        "archived": false,433        "bookmarked": null,434        "liked": null,435        "tags_descriptions": {},436        "like_count": 0,437        "views": 75,438        "category_id": 1,439        "featured_link": null,440        "has_accepted_answer": false,441        "posters": [442          {443            "extras": "latest",444            "description": "Original Poster, Most Recent Poster",445            "user": {446              "id": 59266,447              "username": "talmaashani2016",448              "name": "Tariq B AL-Maashani ",449              "avatar_template": "/user_avatar/discuss.pytorch.org/talmaashani2016/{size}/53141_2.png",450              "trust_level": 1451            }452          },453          {454            "extras": null,455            "description": "Frequent Poster",456            "user": {457              "id": 3534,458              "username": "ptrblck",459              "name": "",460              "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",461              "admin": true,462              "moderator": true,463              "trust_level": 2464            }465          }466        ]467      }468    ],469    "tags_descriptions": {},470    "fancy_title": "Storing and loading a model whose modules have extra attributes",471    "id": 69505,472    "title": "Storing and loading a model whose modules have extra attributes",473    "posts_count": 3,474    "created_at": "2020-02-12T16:35:55.333Z",475    "views": 1582,476    "reply_count": 2,477    "like_count": 1,478    "last_posted_at": "2020-02-12T16:59:15.803Z",479    "visible": true,480    "closed": false,481    "archived": false,482    "has_summary": false,483    "archetype": "regular",484    "slug": "storing-and-loading-a-model-whose-modules-have-extra-attributes",485    "category_id": 1,486    "word_count": 292,487    "deleted_at": null,488    "user_id": 24036,489    "featured_link": null,490    "pinned_globally": false,491    "pinned_at": null,492    "pinned_until": null,493    "image_url": null,494    "slow_mode_seconds": 0,495    "draft": null,496    "draft_key": "topic_69505",497    "draft_sequence": null,498    "unpinned": null,499    "pinned": false,500    "current_post_number": 1,501    "highest_post_number": 3,502    "deleted_by": null,503    "actions_summary": [504      {505        "id": 4,506        "count": 0,507        "hidden": false,508        "can_act": false509      },510      {511        "id": 8,512        "count": 0,513        "hidden": false,514        "can_act": false515      },516      {517        "id": 10,518        "count": 0,519        "hidden": false,520        "can_act": false521      },522      {523        "id": 7,524        "count": 0,525        "hidden": false,526        "can_act": false527      }528    ],529    "chunk_size": 20,530    "bookmarked": false,531    "topic_timer": null,532    "message_bus_last_id": 0,533    "participant_count": 2,534    "show_read_indicator": false,535    "thumbnails": null,536    "slow_mode_enabled_until": null,537    "can_vote": false,538    "vote_count": 0,539    "user_voted": false,540    "discourse_zendesk_plugin_zendesk_id": null,541    "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",542    "details": {543      "can_edit": false,544      "notification_level": 1,545      "participants": [546        {547          "id": 24036,548          "username": "Branikas",549          "name": "Branikas",550          "avatar_template": "/user_avatar/discuss.pytorch.org/branikas/{size}/20476_2.png",551          "post_count": 2,552          "primary_group_name": null,553          "flair_name": null,554          "flair_url": null,555          "flair_color": null,556          "flair_bg_color": null,557          "flair_group_id": null,558          "trust_level": 1559        },560        {561          "id": 9081,562          "username": "JuanFMontesinos",563          "name": "Juan Montesinos",564          "avatar_template": "/user_avatar/discuss.pytorch.org/juanfmontesinos/{size}/76115_2.png",565          "post_count": 1,566          "primary_group_name": null,567          "flair_name": null,568          "flair_url": null,569          "flair_color": null,570          "flair_bg_color": null,571          "flair_group_id": null,572          "trust_level": 2573        }574      ],575      "created_by": {576        "id": 24036,577        "username": "Branikas",578        "name": "Branikas",579        "avatar_template": "/user_avatar/discuss.pytorch.org/branikas/{size}/20476_2.png"580      },581      "last_poster": {582        "id": 24036,583        "username": "Branikas",584        "name": "Branikas",585        "avatar_template": "/user_avatar/discuss.pytorch.org/branikas/{size}/20476_2.png"586      }587    },588    "bookmarks": []589  },590  {591    "post_stream": {592      "posts": [593        {594          "id": 165705,595          "name": "Had",596          "username": "hadaev8",597          "avatar_template": "/user_avatar/discuss.pytorch.org/hadaev8/{size}/16280_2.png",598          "created_at": "2020-02-13T11:09:36.751Z",599          "cooked": "<p>For now, I have it like this<br>\nStill, it’s not clear how to apply attention to lstm outputs</p>\n<pre><code>class Encoder(nn.Module):\n\tdef __init__(self, hparams):\n\t\tsuper(Encoder, self).__init__()\n\n\t\tself.conv = ResidualBlock1d(in_channels=hparams.encoder_embedding_dim,\n\t\t\t\t\t\tout_channels=hparams.encoder_embedding_dim,\n\t\t\t\t\t\tkernel_size=hparams.encoder_kernel_size,\n\t\t\t\t\t\tactivation=hparams.activation, normtype=hparams.normtype,\n\t\t\t\t\t\tnum_layers=hparams.encoder_n_convolutions - 1)\n\n\t\tself.lstm = nn.LSTM(hparams.encoder_embedding_dim,\n\t\t\t\t\tint(hparams.encoder_embedding_dim / 2), 1,\n\t\t\t\t\tbatch_first=False, bidirectional=True)\n\n\t\tself.attn = nn.MultiheadAttention(hparams.encoder_embedding_dim, 8)\n\n\tdef attn_pad_mask(self, lengths):\n\t\tmax_len = torch.max(lengths).item()\n\t\tmask = torch.arange(max_len, out=torch.cuda.LongTensor(max_len))[\n\t\t\tNone, :] &gt;= lengths[:, None]\n\t\treturn mask\n\n\tdef forward(self, x, input_lengths):\n\t\tx = x.transpose(1, 2)\n\n\t\tx = self.conv(x)\n\n\t\tx = x.transpose(1, 2).transpose(0, 1)\n\n\t\tx = nn.utils.rnn.pack_padded_sequence(\n\t\t\tx, input_lengths, batch_first=False)\n\n\t\tself.lstm.flatten_parameters()\n\t\toutputs, _ = self.lstm(x)\n\t\toutputs, _ = nn.utils.rnn.pad_packed_sequence(\n\t\t\toutputs, batch_first=False)\n\n\t\tattn_mask = self.attn_pad_mask(input_lengths)\n\t\toutputs = self.attn(\n\t\t\toutputs, outputs, outputs, key_padding_mask=attn_mask, need_weights=False)[0]\n\t\toutputs = outputs.transpose(0, 1)\n\n\t\treturn outputs</code></pre>",600          "post_number": 1,601          "post_type": 1,602          "posts_count": 1,603          "updated_at": "2020-02-13T11:10:46.702Z",604          "reply_count": 0,605          "reply_to_post_number": null,606          "quote_count": 0,607          "incoming_link_count": 98,608          "reads": 14,609          "readers_count": 13,610          "score": 492.8,611          "yours": false,612          "topic_id": 69582,613          "topic_slug": "right-way-to-apply-self-attention-on-lstm-outputs",614          "display_username": "Had",615          "primary_group_name": null,616          "flair_name": null,617          "flair_url": null,618          "flair_bg_color": null,619          "flair_color": null,620          "flair_group_id": null,621          "badges_granted": [],622          "version": 1,623          "can_edit": false,624          "can_delete": false,625          "can_recover": false,626          "can_see_hidden_post": false,627          "can_wiki": false,628          "read": true,629          "user_title": null,630          "bookmarked": false,631          "actions_summary": [],632          "moderator": false,633          "admin": false,634          "staff": false,635          "user_id": 22803,636          "hidden": false,637          "trust_level": 2,638          "deleted_at": null,639          "user_deleted": false,640          "edit_reason": null,641          "can_view_edit_history": true,642          "wiki": false,643          "post_url": "/t/right-way-to-apply-self-attention-on-lstm-outputs/69582/1",644          "can_accept_answer": false,645          "can_unaccept_answer": false,646          "accepted_answer": false,647          "topic_accepted_answer": null,648          "can_vote": false649        }650      ],651      "stream": [652        165705653      ]654    },655    "timeline_lookup": [656      [657        1,658        2082659      ]660    ],661    "suggested_topics": [662      {663        "fancy_title": "Where can I find the Declarations.yaml for a given Pytorch version?",664        "id": 213045,665        "title": "Where can I find the Declarations.yaml for a given Pytorch version?",666        "slug": "where-can-i-find-the-declarations-yaml-for-a-given-pytorch-version",667        "posts_count": 2,668        "reply_count": 0,669        "highest_post_number": 2,670        "image_url": null,671        "created_at": "2024-11-16T12:39:33.420Z",672        "last_posted_at": "2024-11-16T15:52:17.384Z",673        "bumped": true,674        "bumped_at": "2024-11-16T15:52:17.384Z",675        "archetype": "regular",676        "unseen": false,677        "pinned": false,678        "unpinned": null,679        "visible": true,680        "closed": false,681        "archived": false,682        "bookmarked": null,683        "liked": null,684        "tags_descriptions": {},685        "like_count": 2,686        "views": 41,687        "category_id": 1,688        "featured_link": null,689        "has_accepted_answer": true,690        "posters": [691          {692            "extras": null,693            "description": "Original Poster",694            "user": {695              "id": 80935,696              "username": "darioteixeira",697              "name": "Dario Teixeira",698              "avatar_template": "/user_avatar/discuss.pytorch.org/darioteixeira/{size}/74017_2.png",699              "trust_level": 0700            }701          },702          {703            "extras": "latest",704            "description": "Most Recent Poster, Accepted Answer",705            "user": {706              "id": 41997,707              "username": "bdhirsh",708              "name": "Brian Hirsh",709              "avatar_template": "/user_avatar/discuss.pytorch.org/bdhirsh/{size}/74038_2.png",710              "trust_level": 2711            }712          }713        ]714      },715      {716        "fancy_title": "FlexAttention with sparse edge bias",717        "id": 216376,718        "title": "FlexAttention with sparse edge bias",719        "slug": "flexattention-with-sparse-edge-bias",720        "posts_count": 1,721        "reply_count": 0,722        "highest_post_number": 1,723        "image_url": null,724        "created_at": "2025-02-07T18:02:41.974Z",725        "last_posted_at": "2025-02-07T18:02:42.019Z",726        "bumped": true,727        "bumped_at": "2025-02-07T18:02:42.019Z",728        "archetype": "regular",729        "unseen": false,730        "pinned": false,731        "unpinned": null,732        "visible": true,733        "closed": false,734        "archived": false,735        "bookmarked": null,736        "liked": null,737        "tags_descriptions": {},738        "like_count": 0,739        "views": 92,740        "category_id": 1,741        "featured_link": null,742        "has_accepted_answer": false,743        "posters": [744          {745            "extras": "latest single",746            "description": "Original Poster, Most Recent Poster",747            "user": {748              "id": 82551,749              "username": "mbaranov",750              "name": "Max Baranov",751              "avatar_template": "/letter_avatar_proxy/v4/letter/m/76d3ee/{size}.png",752              "trust_level": 0753            }754          }755        ]756      },757      {758        "fancy_title": "How to Selectively Clear Gradients Accumulated from Previous Time Steps in RNN Backpropagation?",759        "id": 216888,760        "title": "How to Selectively Clear Gradients Accumulated from Previous Time Steps in RNN Backpropagation?",761        "slug": "how-to-selectively-clear-gradients-accumulated-from-previous-time-steps-in-rnn-backpropagation",762        "posts_count": 1,763        "reply_count": 0,764        "highest_post_number": 1,765        "image_url": null,766        "created_at": "2025-02-19T12:13:58.278Z",767        "last_posted_at": "2025-02-19T12:13:58.320Z",768        "bumped": true,769        "bumped_at": "2025-02-19T12:44:07.484Z",770        "archetype": "regular",771        "unseen": false,772        "pinned": false,773        "unpinned": null,774        "visible": true,775        "closed": false,776        "archived": false,777        "bookmarked": null,778        "liked": null,779        "tags_descriptions": {},780        "like_count": 0,781        "views": 56,782        "category_id": 1,783        "featured_link": null,784        "has_accepted_answer": false,785        "posters": [786          {787            "extras": "latest single",788            "description": "Original Poster, Most Recent Poster",789            "user": {790              "id": 68895,791              "username": "DawidL",792              "name": "",793              "avatar_template": "/user_avatar/discuss.pytorch.org/dawidl/{size}/62949_2.png",794              "trust_level": 1795            }796          }797        ]798      },799      {800        "fancy_title": "PyTorch for RTX 5090? When will it be out? Thank you",801        "id": 217908,802        "title": "PyTorch for RTX 5090? When will it be out? Thank you",803        "slug": "pytorch-for-rtx-5090-when-will-it-be-out-thank-you",804        "posts_count": 2,805        "reply_count": 0,806        "highest_post_number": 2,807        "image_url": null,808        "created_at": "2025-03-16T10:10:27.595Z",809        "last_posted_at": "2025-03-16T14:00:28.491Z",810        "bumped": true,811        "bumped_at": "2025-03-16T14:00:28.491Z",812        "archetype": "regular",813        "unseen": false,814        "pinned": false,815        "unpinned": null,816        "visible": true,817        "closed": false,818        "archived": false,819        "bookmarked": null,820        "liked": null,821        "tags_descriptions": {},822        "like_count": 0,823        "views": 149,824        "category_id": 1,825        "featured_link": null,826        "has_accepted_answer": false,827        "posters": [828          {829            "extras": null,830            "description": "Original Poster",831            "user": {832              "id": 83305,833              "username": "Raf_Duran",834              "name": "Raf Duran",835              "avatar_template": "/user_avatar/discuss.pytorch.org/raf_duran/{size}/76163_2.png",836              "trust_level": 0837            }838          },839          {840            "extras": "latest",841            "description": "Most Recent Poster",842            "user": {843              "id": 3534,844              "username": "ptrblck",845              "name": "",846              "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",847              "admin": true,848              "moderator": true,849              "trust_level": 2850            }851          }852        ]853      },854      {855        "fancy_title": "A good first issue for beginners",856        "id": 219185,857        "title": "A good first issue for beginners",858        "slug": "a-good-first-issue-for-beginners",859        "posts_count": 2,860        "reply_count": 0,861        "highest_post_number": 2,862        "image_url": null,863        "created_at": "2025-04-17T05:09:22.444Z",864        "last_posted_at": "2025-04-17T12:04:43.979Z",865        "bumped": true,866        "bumped_at": "2025-04-17T12:04:43.979Z",867        "archetype": "regular",868        "unseen": false,869        "pinned": false,870        "unpinned": null,871        "visible": true,872        "closed": false,873        "archived": false,874        "bookmarked": null,875        "liked": null,876        "tags_descriptions": {},877        "like_count": 1,878        "views": 60,879        "category_id": 1,880        "featured_link": null,881        "has_accepted_answer": false,882        "posters": [883          {884            "extras": null,885            "description": "Original Poster",886            "user": {887              "id": 83865,888              "username": "kandgesid",889              "name": "Siddhant Kandge",890              "avatar_template": "/user_avatar/discuss.pytorch.org/kandgesid/{size}/76682_2.png",891              "trust_level": 0892            }893          },894          {895            "extras": "latest",896            "description": "Most Recent Poster",897            "user": {898              "id": 3534,899              "username": "ptrblck",900              "name": "",901              "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",902              "admin": true,903              "moderator": true,904              "trust_level": 2905            }906          }907        ]908      }909    ],910    "tags_descriptions": {},911    "fancy_title": "Right way to apply self attention on lstm outputs?",912    "id": 69582,913    "title": "Right way to apply self attention on lstm outputs?",914    "posts_count": 1,915    "created_at": "2020-02-13T11:09:36.699Z",916    "views": 421,917    "reply_count": 0,918    "like_count": 0,919    "last_posted_at": "2020-02-13T11:09:36.751Z",920    "visible": true,921    "closed": false,922    "archived": false,923    "has_summary": false,924    "archetype": "regular",925    "slug": "right-way-to-apply-self-attention-on-lstm-outputs",926    "category_id": 1,927    "word_count": 168,928    "deleted_at": null,929    "user_id": 22803,930    "featured_link": null,931    "pinned_globally": false,932    "pinned_at": null,933    "pinned_until": null,934    "image_url": null,935    "slow_mode_seconds": 0,936    "draft": null,937    "draft_key": "topic_69582",938    "draft_sequence": null,939    "unpinned": null,940    "pinned": false,941    "current_post_number": 1,942    "highest_post_number": 1,943    "deleted_by": null,944    "actions_summary": [945      {946        "id": 4,947        "count": 0,948        "hidden": false,949        "can_act": false950      },951      {952        "id": 8,953        "count": 0,954        "hidden": false,955        "can_act": false956      },957      {958        "id": 10,959        "count": 0,960        "hidden": false,961        "can_act": false962      },963      {964        "id": 7,965        "count": 0,966        "hidden": false,967        "can_act": false968      }969    ],970    "chunk_size": 20,971    "bookmarked": false,972    "topic_timer": null,973    "message_bus_last_id": 0,974    "participant_count": 1,975    "show_read_indicator": false,976    "thumbnails": null,977    "slow_mode_enabled_until": null,978    "can_vote": false,979    "vote_count": 0,980    "user_voted": false,981    "discourse_zendesk_plugin_zendesk_id": null,982    "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",983    "details": {984      "can_edit": false,985      "notification_level": 1,986      "participants": [987        {988          "id": 22803,989          "username": "hadaev8",990          "name": "Had",991          "avatar_template": "/user_avatar/discuss.pytorch.org/hadaev8/{size}/16280_2.png",992          "post_count": 1,993          "primary_group_name": null,994          "flair_name": null,995          "flair_url": null,996          "flair_color": null,997          "flair_bg_color": null,998          "flair_group_id": null,999          "trust_level": 21000        }1001      ],1002      "created_by": {1003        "id": 22803,1004        "username": "hadaev8",1005        "name": "Had",1006        "avatar_template": "/user_avatar/discuss.pytorch.org/hadaev8/{size}/16280_2.png"1007      },1008      "last_poster": {1009        "id": 22803,1010        "username": "hadaev8",1011        "name": "Had",1012        "avatar_template": "/user_avatar/discuss.pytorch.org/hadaev8/{size}/16280_2.png"1013      }1014    },1015    "bookmarks": []1016  },1017  {1018    "post_stream": {1019      "posts": [1020        {1021          "id": 165586,1022          "name": "Siddharth Vashishtha",1023          "username": "Siddharth_Vashishtha",1024          "avatar_template": "/user_avatar/discuss.pytorch.org/siddharth_vashishtha/{size}/6070_2.png",1025          "created_at": "2020-02-13T02:32:53.398Z",1026          "cooked": "<p>I have a situation for which I am using nested for-loops, but I want to know if there’s a faster way of doing this using some advanced indexing in Pytorch.</p>\n<p>I have a tensor named <code>t</code>:</p>\n<pre><code class=\"lang-auto\">t = torch.randn(3,8)\nprint(t)\ntensor([[-1.1258, -1.1524, -0.2506, -0.4339,  0.8487,  0.6920, -0.3160, -2.1152],\n        [ 0.4681, -0.1577,  1.4437,  0.2660,  0.1665,  0.8744, -0.1435, -0.1116],\n        [ 0.9318,  1.2590,  2.0050,  0.0537,  0.6181, -0.4128, -0.8411, -2.3160]])\n</code></pre>\n<p>I want to create a new tensor which indexes values from <code>t</code>.<br>\nLet’s say these indexes are stored in variable <code>indexes</code></p>\n<pre><code class=\"lang-auto\">indexes = [[(0, 1, 4, 5), (0, 1, 6, 7), (4, 5, 6, 7)],\n           [(2, 3, 4, 5)],\n           [(4, 5, 6, 7), (2, 3, 6, 7)]]\n\n</code></pre>\n<p>Each inner tuple in <code>indexes</code> represents four indexes that are to be taken from a row in t.</p>\n<p>As an example, based on these indexes my output would be a 6x4 dimension tensor (6 is the total number of tuples in <code>indexes</code>, and 4 corresponds to one value in a tuple)</p>\n<p>For instance, this is what I want to do:</p>\n<pre><code class=\"lang-auto\">#counting the number of tuples in indexes\ncount_instances = sum([1 for lst in indexes for tupl in lst])\n\n#creating a zero output matrix \nfinal_tensor = torch.zeros(count_instances,4)\n\nfinal_tensor[0] = t[0,indexes[0][0]]\nfinal_tensor[1] = t[0,indexes[0][1]]\nfinal_tensor[2] = t[0,indexes[0][2]]\nfinal_tensor[3] = t[1,indexes[1][0]]\nfinal_tensor[4] = t[2,indexes[2][0]]\nfinal_tensor[5] = t[2,indexes[2][1]]\n</code></pre>\n<p>The final output looks like this:<br>\nprint(final_tensor)</p>\n<pre><code class=\"lang-auto\">tensor([[-1.1258, -1.1524,  0.8487,  0.6920],\n        [-1.1258, -1.1524, -0.3160, -2.1152],\n        [ 0.8487,  0.6920, -0.3160, -2.1152],\n        [ 1.4437,  0.2660,  0.1665,  0.8744],\n        [ 0.6181, -0.4128, -0.8411, -2.3160],\n        [ 2.0050,  0.0537, -0.8411, -2.3160]])\n\n</code></pre>\n<p>I created a function <code>build_tensor</code> (shown below) to achieve this with nested for-loops, but I want to know if there’s a faster way of doing it with simple indexing in Pytorch. I want a faster way of doing it because I’m doing this operation hundreds of times with bigger index and t sizes.</p>\n<p>Any help?</p>\n<pre><code class=\"lang-auto\">def build_tensor(indexes, t):\n    #count tuples\n    count_instances = sum([1 for lst in indexes for tupl in lst])\n    #create a zero tensor\n    final_tensor = torch.zeros(count_instances,4)\n    final_tensor_idx = 0\n\n    for curr_idx, lst in enumerate(indexes):\n        for tupl in lst:\n            final_tensor[final_tensor_idx] = t[curr_idx,tupl]\n            final_tensor_idx+=1\n    return final_tensor\n</code></pre>",1027          "post_number": 1,1028          "post_type": 1,1029          "posts_count": 2,1030          "updated_at": "2020-02-13T02:33:48.164Z",1031          "reply_count": 0,1032          "reply_to_post_number": null,1033          "quote_count": 0,1034          "incoming_link_count": 390,1035          "reads": 21,1036          "readers_count": 20,1037          "score": 1944.2,1038          "yours": false,1039          "topic_id": 69549,1040          "topic_slug": "advance-indexing-of-tensor-to-get-rid-of-nested-for-loops",1041          "display_username": "Siddharth Vashishtha",1042          "primary_group_name": null,1043          "flair_name": null,1044          "flair_url": null,1045          "flair_bg_color": null,1046          "flair_color": null,1047          "flair_group_id": null,1048          "badges_granted": [],1049          "version": 1,1050          "can_edit": false,1051          "can_delete": false,1052          "can_recover": false,1053          "can_see_hidden_post": false,1054          "can_wiki": false,1055          "read": true,1056          "user_title": null,1057          "bookmarked": false,1058          "actions_summary": [],1059          "moderator": false,1060          "admin": false,1061          "staff": false,1062          "user_id": 10346,1063          "hidden": false,1064          "trust_level": 1,1065          "deleted_at": null,1066          "user_deleted": false,1067          "edit_reason": null,1068          "can_view_edit_history": true,1069          "wiki": false,1070          "post_url": "/t/advance-indexing-of-tensor-to-get-rid-of-nested-for-loops/69549/1",1071          "can_accept_answer": false,1072          "can_unaccept_answer": false,1073          "accepted_answer": false,1074          "topic_accepted_answer": null,1075          "can_vote": false1076        },1077        {1078          "id": 165668,1079          "name": "",1080          "username": "mmisiur",1081          "avatar_template": "/user_avatar/discuss.pytorch.org/mmisiur/{size}/10162_2.png",1082          "created_at": "2020-02-13T10:15:51.028Z",1083          "cooked": "<p>Have you tried <a href=\"https://pytorch.org/docs/stable/torch.html#torch.index_select\" rel=\"nofollow noopener\">index_select</a> ? It’s an easy way to select parts of tensor along one dimension by the indexes, so one for loop can be replaced.</p>",1084          "post_number": 2,1085          "post_type": 1,1086          "posts_count": 2,1087          "updated_at": "2020-02-13T10:15:51.028Z",1088          "reply_count": 0,1089          "reply_to_post_number": null,1090          "quote_count": 0,1091          "incoming_link_count": 4,1092          "reads": 18,1093          "readers_count": 17,1094          "score": 23.6,1095          "yours": false,1096          "topic_id": 69549,1097          "topic_slug": "advance-indexing-of-tensor-to-get-rid-of-nested-for-loops",1098          "display_username": "",1099          "primary_group_name": null,1100          "flair_name": null,1101          "flair_url": null,1102          "flair_bg_color": null,1103          "flair_color": null,1104          "flair_group_id": null,1105          "badges_granted": [],1106          "version": 1,1107          "can_edit": false,1108          "can_delete": false,1109          "can_recover": false,1110          "can_see_hidden_post": false,1111          "can_wiki": false,1112          "link_counts": [1113            {1114              "url": "https://pytorch.org/docs/stable/torch.html#torch.index_select",1115              "internal": false,1116              "reflection": false,1117              "title": "torch — PyTorch master documentation",1118              "clicks": 1031119            }1120          ],1121          "read": true,1122          "user_title": null,1123          "bookmarked": false,1124          "actions_summary": [],1125          "moderator": false,1126          "admin": false,1127          "staff": false,1128          "user_id": 15953,1129          "hidden": false,1130          "trust_level": 2,1131          "deleted_at": null,1132          "user_deleted": false,1133          "edit_reason": null,1134          "can_view_edit_history": true,1135          "wiki": false,1136          "post_url": "/t/advance-indexing-of-tensor-to-get-rid-of-nested-for-loops/69549/2",1137          "can_accept_answer": false,1138          "can_unaccept_answer": false,1139          "accepted_answer": false,1140          "topic_accepted_answer": null1141        }1142      ],1143      "stream": [1144        165586,1145        1656681146      ]1147    },1148    "timeline_lookup": [1149      [1150        1,1151        20821152      ]1153    ],1154    "suggested_topics": [1155      {1156        "fancy_title": "Why my Traing accuracy remains constant",1157        "id": 215399,1158        "title": "Why my Traing accuracy remains constant",1159        "slug": "why-my-traing-accuracy-remains-constant",1160        "posts_count": 3,1161        "reply_count": 0,1162        "highest_post_number": 3,1163        "image_url": null,1164        "created_at": "2025-01-15T00:27:15.842Z",1165        "last_posted_at": "2025-01-20T00:33:10.329Z",1166        "bumped": true,1167        "bumped_at": "2025-01-20T00:33:10.329Z",1168        "archetype": "regular",1169        "unseen": false,1170        "pinned": false,1171        "unpinned": null,1172        "visible": true,1173        "closed": false,1174        "archived": false,1175        "bookmarked": null,1176        "liked": null,1177        "tags_descriptions": {},1178        "like_count": 0,1179        "views": 176,1180        "category_id": 8,1181        "featured_link": null,1182        "has_accepted_answer": false,1183        "posters": [1184          {1185            "extras": null,1186            "description": "Original Poster",1187            "user": {1188              "id": 82093,1189              "username": "arsh_sharma",1190              "name": "arsh sharma",1191              "avatar_template": "/user_avatar/discuss.pytorch.org/arsh_sharma/{size}/75107_2.png",1192              "trust_level": 01193            }1194          },1195          {1196            "extras": null,1197            "description": "Frequent Poster",1198            "user": {1199              "id": 3534,1200              "username": "ptrblck",

Showing the first 1,200 of 67836 lines. Download the file for the rest.