Pytorch dynamic forward pass The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsPyTorch vs. Tensorflow FoldHow to install pytorch in windows?Forward and backward process in pyTorchPytorch CapabilitiesWhat is the use of torch.no_grad in pytorch?Inseting pretrained network to pytorchHow to re-initialise batch sampling with pytorch dataloader?static graphs v.s. dynamic graphsReplicating RNN within PyTorch

Can smartphones with the same camera sensor have different image quality?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

How to pronounce 1ターン?

Take groceries in checked luggage

Difference between "generating set" and free product?

Does the AirPods case need to be around while listening via an iOS Device?

Why did all the guest students take carriages to the Yule Ball?

Why can't devices on different VLANs, but on the same subnet, communicate?

When did F become S in typeography, and why?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Are spiders unable to hurt humans, especially very small spiders?

Windows 10: How to Lock (not sleep) laptop on lid close?

Does Parliament need to approve the new Brexit delay to 31 October 2019?

First use of “packing” as in carrying a gun

How is simplicity better than precision and clarity in prose?

Would it be possible to rearrange a dragon's flight muscle to somewhat circumvent the square-cube law?

Why does the Event Horizon Telescope (EHT) not include telescopes from Africa, Asia or Australia?

The variadic template constructor of my class cannot modify my class members, why is that so?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Typeface like Times New Roman but with "tied" percent sign

What's the point in a preamp?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

How does ice melt when immersed in water



Pytorch dynamic forward pass



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsPyTorch vs. Tensorflow FoldHow to install pytorch in windows?Forward and backward process in pyTorchPytorch CapabilitiesWhat is the use of torch.no_grad in pytorch?Inseting pretrained network to pytorchHow to re-initialise batch sampling with pytorch dataloader?static graphs v.s. dynamic graphsReplicating RNN within PyTorch










1












$begingroup$


Does there exist a fast and convenient way for handling such a problem:



class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

def forward(self, x, indices):
x = self.linears[indices](x)
return x


You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.










share|improve this question











$endgroup$
















    1












    $begingroup$


    Does there exist a fast and convenient way for handling such a problem:



    class MyModule(nn.Module):
    def __init__(self):
    super(MyModule, self).__init__()
    self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

    def forward(self, x, indices):
    x = self.linears[indices](x)
    return x


    You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.










    share|improve this question











    $endgroup$














      1












      1








      1





      $begingroup$


      Does there exist a fast and convenient way for handling such a problem:



      class MyModule(nn.Module):
      def __init__(self):
      super(MyModule, self).__init__()
      self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

      def forward(self, x, indices):
      x = self.linears[indices](x)
      return x


      You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.










      share|improve this question











      $endgroup$




      Does there exist a fast and convenient way for handling such a problem:



      class MyModule(nn.Module):
      def __init__(self):
      super(MyModule, self).__init__()
      self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

      def forward(self, x, indices):
      x = self.linears[indices](x)
      return x


      You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.







      pytorch






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 1 at 14:44







      Andreas Look

















      asked Mar 1 at 14:37









      Andreas LookAndreas Look

      441111




      441111




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          Here is my understanding of your problem:



          # Import
          from torch import nn

          # Define custom class
          class MyModule(nn.Module):
          def __init__(self):
          super(MyModule, self).__init__()
          self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

          def forward(self, x, indices):
          x = self.linears[indices](x)
          return x

          # Intialize custom class
          net = MyModule()

          # Access networks layers based on additional input
          additional_input = 1
          if additional_input == 1:
          idx = 0
          print(net.linears[idx].in_features)





          share|improve this answer









          $endgroup$












          • $begingroup$
            thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
            $endgroup$
            – Andreas Look
            Mar 1 at 18:57











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f46471%2fpytorch-dynamic-forward-pass%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0












          $begingroup$

          Here is my understanding of your problem:



          # Import
          from torch import nn

          # Define custom class
          class MyModule(nn.Module):
          def __init__(self):
          super(MyModule, self).__init__()
          self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

          def forward(self, x, indices):
          x = self.linears[indices](x)
          return x

          # Intialize custom class
          net = MyModule()

          # Access networks layers based on additional input
          additional_input = 1
          if additional_input == 1:
          idx = 0
          print(net.linears[idx].in_features)





          share|improve this answer









          $endgroup$












          • $begingroup$
            thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
            $endgroup$
            – Andreas Look
            Mar 1 at 18:57















          0












          $begingroup$

          Here is my understanding of your problem:



          # Import
          from torch import nn

          # Define custom class
          class MyModule(nn.Module):
          def __init__(self):
          super(MyModule, self).__init__()
          self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

          def forward(self, x, indices):
          x = self.linears[indices](x)
          return x

          # Intialize custom class
          net = MyModule()

          # Access networks layers based on additional input
          additional_input = 1
          if additional_input == 1:
          idx = 0
          print(net.linears[idx].in_features)





          share|improve this answer









          $endgroup$












          • $begingroup$
            thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
            $endgroup$
            – Andreas Look
            Mar 1 at 18:57













          0












          0








          0





          $begingroup$

          Here is my understanding of your problem:



          # Import
          from torch import nn

          # Define custom class
          class MyModule(nn.Module):
          def __init__(self):
          super(MyModule, self).__init__()
          self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

          def forward(self, x, indices):
          x = self.linears[indices](x)
          return x

          # Intialize custom class
          net = MyModule()

          # Access networks layers based on additional input
          additional_input = 1
          if additional_input == 1:
          idx = 0
          print(net.linears[idx].in_features)





          share|improve this answer









          $endgroup$



          Here is my understanding of your problem:



          # Import
          from torch import nn

          # Define custom class
          class MyModule(nn.Module):
          def __init__(self):
          super(MyModule, self).__init__()
          self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])

          def forward(self, x, indices):
          x = self.linears[indices](x)
          return x

          # Intialize custom class
          net = MyModule()

          # Access networks layers based on additional input
          additional_input = 1
          if additional_input == 1:
          idx = 0
          print(net.linears[idx].in_features)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 1 at 18:32









          Brian SpieringBrian Spiering

          4,2681129




          4,2681129











          • $begingroup$
            thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
            $endgroup$
            – Andreas Look
            Mar 1 at 18:57
















          • $begingroup$
            thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
            $endgroup$
            – Andreas Look
            Mar 1 at 18:57















          $begingroup$
          thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
          $endgroup$
          – Andreas Look
          Mar 1 at 18:57




          $begingroup$
          thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
          $endgroup$
          – Andreas Look
          Mar 1 at 18:57

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f46471%2fpytorch-dynamic-forward-pass%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

          Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?