MCPcopy Create free account
hub / github.com/OpenSparseLLMs/Linear-MoE / forward

Method forward

linear_moe/sequence_modeling/ssm.py:209–250  ·  view source on GitHub ↗
(
        self,
        hidden_states: Tensor,
        attention_mask: Tensor,
        inference_params=None,
        rotary_pos_emb: Tensor = None,
    )

Source from the content-addressed store, hash-verified

207 self.input_tensor = input_tensor
208
209 def forward(
210 self,
211 hidden_states: Tensor,
212 attention_mask: Tensor,
213 inference_params=None,
214 rotary_pos_emb: Tensor = None,
215 ):
216 if not self.pre_process:
217 # See set_input_tensor()
218 hidden_states = self.input_tensor
219
220 if inference_params:
221 # NOTE(bnorick): match InferenceParams attributes for mamba_ssm.utils.generation.InferenceParams,
222 # this hack supports eval
223 inference_params.max_seqlen = inference_params.max_sequence_length
224 inference_params.seqlen_offset = inference_params.sequence_len_offset
225
226 for layer in self.layers:
227 hidden_states = layer(
228 hidden_states,
229 attention_mask,
230 inference_params=inference_params,
231 rotary_pos_emb=rotary_pos_emb,
232 )
233
234 # The attention layer (currently a simplified transformer layer)
235 # outputs a tuple of (hidden_states, context). Context is intended
236 # for cross-attention, and is not needed in our model.
237 if isinstance(hidden_states, tuple):
238 hidden_states = hidden_states[0]
239
240 # Final layer norm.
241 if self.post_process and self.post_layer_norm:
242 hidden_states = self.final_norm(hidden_states)
243
244 # Ensure that the tensor passed between pipeline parallel stages is
245 # viewless. See related notes in TransformerBlock and TransformerLayer
246 output = make_viewless_tensor(
247 inp=hidden_states, requires_grad=hidden_states.requires_grad, keep_graph=True
248 )
249
250 return hidden_states

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected