@Inkyung posted a new topic, subject "LSTM source code question". It read:

   Hi
    
    I am trying to make customized LSTM cell but have some problems with figuring out what the really output is.
    
    From the source code, it seems like returned value of `output` and `permute_hidden` value.
    
    And `output` and `hidden` values are from `result`.
    
    I am wondering the what result means and where the `result` is coming from.
    [code] 
                if batch_sizes is None:
                    result = _VF.lstm(input, hx, self._flat_weights, self.bias, self.num_layers,
                                      self.dropout, self.training, self.bidirectional, self.batch_first)
                else:
                    result = _VF.lstm(input, batch_sizes, hx, self._flat_weights, self.bias,
                                      self.num_layers, self.dropout, self.training, self.bidirectional)
                output = result[0]
                hidden = result[1:]
                # xxx: isinstance check needs to be in conditional for TorchScript to compile
                if isinstance(orig_input, PackedSequence):
                    output_packed = PackedSequence(output, batch_sizes, sorted_indices, unsorted_indices)
                    return output_packed, self.permute_hidden(hidden, unsorted_indices)
                else:
                    return output, self.permute_hidden(hidden, unsorted_indices)
        
    [/code]
    
    Any help or comments would be appriciated!
    
    Thank you!

Then @ptrblck said

    Depending on which implementation and device you are using I assume the `result` is created in one of these methods.

So @Inkyung replied

    I am trying to understand what `result` means and how they are separated into `output` and `hidden` value!
    
    Since as far as I know the `output` of the LSTM is hidden and cell states continuously, but wondering how `output` is made of.


{'source': 'discourse', 'url': 'https://discuss.pytorch.org/t/lstm-source-code-question/104391', 'title': 'LSTM source code question', 'views': 210, 'has_accepted_answer': False, 'word_count': 224, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 3, 'tags': '', 'author': '@Inkyung', 'participants': '@Inkyung, @ptrblck', 'image_url': [None], 'created_at': '2020-11-28T02:14:14.619Z', 'last_posted_at': '2020-11-28T08:34:45.775Z'}