vllm - 💡(How to fix) Fix Early Stopping for Ouro models [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vllm-project/vllm#37668Fetched 2026-04-08 01:04:11
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
labeled ×1

Code Example

## ouro.py

    def forward(
        self,
        input_ids: torch.Tensor | None,
        positions: torch.Tensor,
        intermediate_tensors: IntermediateTensors | None = None,
        inputs_embeds: torch.Tensor | None = None,
    ) -> torch.Tensor | IntermediateTensors:
        if inputs_embeds is not None:
            hidden_states = inputs_embeds
        else:
            hidden_states = self.embed_input_ids(input_ids)

        # self.early_exit_threshold = getattr(config, "early_exit_threshold", None)
        # self.use_early_exit = self.early_exit_threshold is not None and 0<=self.early_exit_threshold<=1

        gate_probs = None
        unfinished = torch.full(fill_value = True, 
                                size = (hidden_states.shape[0],), 
                                dtype=torch.bool, device=hidden_states.device)

        early_exist_hidden_state = hidden_states

        for current_ut in range(self.total_ut_steps):
            residual = None
            for layer in self.layers[self.start_layer : self.end_layer]:
                hidden_states, residual = layer(
                    positions, hidden_states, current_ut, residual
                )
            hidden_states, _ = self.norm(hidden_states, residual)

            early_exist_hidden_state[unfinished] = hidden_states[unfinished]

            if self.use_early_exit:
                ut_logits, _ = self.early_exit_gate(hidden_states)
                ut_probs = torch.sigmoid(ut_logits.squeeze(-1))                
                gate_probs = ut_probs if gate_probs is None else gate_probs + (1 - gate_probs) * ut_probs
                unfinished[(gate_probs>=self.early_exit_threshold)] = False
   
        return early_exist_hidden_state
RAW_BUFFERClick to expand / collapse

Your current environment

Python 3.12.13 vllm 0.17.1 torch 2.10.0+cu129

Question

Hello,

I want to add early exit for "ouro" models (ouro.py). However I'm not completely sure how model runner is using "hidden_states" from the model.

Basically will it break the runner if instead of last hidden states I will return hidden state based on the decoder layer probability?

## ouro.py

    def forward(
        self,
        input_ids: torch.Tensor | None,
        positions: torch.Tensor,
        intermediate_tensors: IntermediateTensors | None = None,
        inputs_embeds: torch.Tensor | None = None,
    ) -> torch.Tensor | IntermediateTensors:
        if inputs_embeds is not None:
            hidden_states = inputs_embeds
        else:
            hidden_states = self.embed_input_ids(input_ids)

        # self.early_exit_threshold = getattr(config, "early_exit_threshold", None)
        # self.use_early_exit = self.early_exit_threshold is not None and 0<=self.early_exit_threshold<=1

        gate_probs = None
        unfinished = torch.full(fill_value = True, 
                                size = (hidden_states.shape[0],), 
                                dtype=torch.bool, device=hidden_states.device)

        early_exist_hidden_state = hidden_states

        for current_ut in range(self.total_ut_steps):
            residual = None
            for layer in self.layers[self.start_layer : self.end_layer]:
                hidden_states, residual = layer(
                    positions, hidden_states, current_ut, residual
                )
            hidden_states, _ = self.norm(hidden_states, residual)

            early_exist_hidden_state[unfinished] = hidden_states[unfinished]

            if self.use_early_exit:
                ut_logits, _ = self.early_exit_gate(hidden_states)
                ut_probs = torch.sigmoid(ut_logits.squeeze(-1))                
                gate_probs = ut_probs if gate_probs is None else gate_probs + (1 - gate_probs) * ut_probs
                unfinished[(gate_probs>=self.early_exit_threshold)] = False
   
        return early_exist_hidden_state

How would you like to use vllm

I want to use vllm to run LoopLM architecture inference

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

extent analysis

Fix Plan

To implement early exit for "ouro" models, you need to modify the forward method in ouro.py to return the hidden state based on the decoder layer probability.

Here are the steps:

  • Calculate the gate probabilities for each decoder layer
  • Update the early_exist_hidden_state based on the gate probabilities
  • Return the early_exist_hidden_state at the end of the forward method

Code Changes

def forward(
    self,
    input_ids: torch.Tensor | None,
    positions: torch.Tensor,
    intermediate_tensors: IntermediateTensors | None = None,
    inputs_embeds: torch.Tensor | None = None,
) -> torch.Tensor | IntermediateTensors:
    # ... (rest of the code remains the same)

    gate_probs = None
    unfinished = torch.full(fill_value = True, 
                            size = (hidden_states.shape[0],), 
                            dtype=torch.bool, device=hidden_states.device)

    early_exist_hidden_state = hidden_states

    for current_ut in range(self.total_ut_steps):
        # ... (rest of the code remains the same)

        if self.use_early_exit:
            ut_logits, _ = self.early_exit_gate(hidden_states)
            ut_probs = torch.sigmoid(ut_logits.squeeze(-1))                
            gate_probs = ut_probs if gate_probs is None else gate_probs + (1 - gate_probs) * ut_probs
            unfinished[(gate_probs>=self.early_exit_threshold)] = False

            # Update early_exist_hidden_state based on gate probabilities
            early_exist_hidden_state[unfinished] = hidden_states[unfinished]

    # Return early_exist_hidden_state
    return early_exist_hidden_state

Verification

To verify that the fix worked, you can test the model with different input sequences and check if the early exit is triggered correctly. You can also compare the output of the model with and without early exit to ensure that the results are consistent.

Extra Tips

  • Make sure to adjust the early_exit_threshold value according to your specific use case.
  • You can also consider adding additional logging or debugging statements to monitor the early exit behavior and adjust the threshold value accordingly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

vllm - 💡(How to fix) Fix Early Stopping for Ouro models [1 participants]