re-add debugs
Browse files- modeling_myolmoe.py +6 -0
modeling_myolmoe.py
CHANGED
|
@@ -318,11 +318,13 @@ class MyOLMoESparseMoeBlock(nn.Module):
|
|
| 318 |
self.experts = nn.ModuleList([OlmoeMLP(config) for _ in range(self.num_experts)])
|
| 319 |
|
| 320 |
def forward(self, hidden_states: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
|
|
|
| 321 |
batch_size, seq_len = hidden_states.shape
|
| 322 |
hidden_states = hidden_states.view(-1, self.hidden_size)
|
| 323 |
|
| 324 |
# Get routing weights and selected experts
|
| 325 |
routing_weights, selected_experts, router_logits = self.router(hidden_states)
|
|
|
|
| 326 |
|
| 327 |
if self.norm_topk_prob:
|
| 328 |
routing_weights = routing_weights / routing_weights.sum(dim=-1, keepdim=True)
|
|
@@ -354,6 +356,7 @@ class MyOLMoESparseMoeBlock(nn.Module):
|
|
| 354 |
# Return 3 values: (hidden_states, router_logits, aux_loss)
|
| 355 |
# For now, we'll return None for aux_loss - you can compute it here if needed
|
| 356 |
aux_loss = None
|
|
|
|
| 357 |
return final_hidden_states, router_logits, aux_loss
|
| 358 |
|
| 359 |
class MyOLMoEDecoderLayer(nn.Module):
|
|
@@ -389,6 +392,7 @@ class MyOLMoEDecoderLayer(nn.Module):
|
|
| 389 |
|
| 390 |
# Self-attention
|
| 391 |
hidden_states = self.input_layernorm(hidden_states)
|
|
|
|
| 392 |
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
| 393 |
hidden_states=hidden_states,
|
| 394 |
attention_mask=attention_mask,
|
|
@@ -399,6 +403,7 @@ class MyOLMoEDecoderLayer(nn.Module):
|
|
| 399 |
cache_position=cache_position,
|
| 400 |
position_embeddings=position_embeddings,
|
| 401 |
)
|
|
|
|
| 402 |
hidden_states = residual + hidden_states
|
| 403 |
|
| 404 |
# MoE layer
|
|
@@ -406,6 +411,7 @@ class MyOLMoEDecoderLayer(nn.Module):
|
|
| 406 |
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 407 |
hidden_states, router_logits, aux_loss = self.mlp(hidden_states)
|
| 408 |
hidden_states = residual + hidden_states
|
|
|
|
| 409 |
|
| 410 |
# Always return 4 values in consistent order
|
| 411 |
return (
|
|
|
|
| 318 |
self.experts = nn.ModuleList([OlmoeMLP(config) for _ in range(self.num_experts)])
|
| 319 |
|
| 320 |
def forward(self, hidden_states: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 321 |
+
print(f"DEBUG: MoE forward start - hidden_states shape: {hidden_states.shape}")
|
| 322 |
batch_size, seq_len = hidden_states.shape
|
| 323 |
hidden_states = hidden_states.view(-1, self.hidden_size)
|
| 324 |
|
| 325 |
# Get routing weights and selected experts
|
| 326 |
routing_weights, selected_experts, router_logits = self.router(hidden_states)
|
| 327 |
+
print(f"DEBUG: MoE forward mid - routing_weights shape: {routing_weights.shape}, selected_experts shape: {selected_experts.shape}")
|
| 328 |
|
| 329 |
if self.norm_topk_prob:
|
| 330 |
routing_weights = routing_weights / routing_weights.sum(dim=-1, keepdim=True)
|
|
|
|
| 356 |
# Return 3 values: (hidden_states, router_logits, aux_loss)
|
| 357 |
# For now, we'll return None for aux_loss - you can compute it here if needed
|
| 358 |
aux_loss = None
|
| 359 |
+
print(f"DEBUG: MoE forward returning - final_hidden_states shape: {final_hidden_states.shape}, router_logits shape: {router_logits.shape}, aux_loss: {aux_loss}")
|
| 360 |
return final_hidden_states, router_logits, aux_loss
|
| 361 |
|
| 362 |
class MyOLMoEDecoderLayer(nn.Module):
|
|
|
|
| 392 |
|
| 393 |
# Self-attention
|
| 394 |
hidden_states = self.input_layernorm(hidden_states)
|
| 395 |
+
print(f"DEBUG: Before MoE call - hidden_states shape: {hidden_states.shape}")
|
| 396 |
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
| 397 |
hidden_states=hidden_states,
|
| 398 |
attention_mask=attention_mask,
|
|
|
|
| 403 |
cache_position=cache_position,
|
| 404 |
position_embeddings=position_embeddings,
|
| 405 |
)
|
| 406 |
+
print(f"DEBUG: After MoE call - hidden_states shape: {hidden_states.shape}")
|
| 407 |
hidden_states = residual + hidden_states
|
| 408 |
|
| 409 |
# MoE layer
|
|
|
|
| 411 |
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 412 |
hidden_states, router_logits, aux_loss = self.mlp(hidden_states)
|
| 413 |
hidden_states = residual + hidden_states
|
| 414 |
+
print(f"DEBUG: End Decoder call - hidden_states shape: {hidden_states.shape}")
|
| 415 |
|
| 416 |
# Always return 4 values in consistent order
|
| 417 |
return (
|