lynx-dynamic-exits

Enable models to stop generating when confident through lightweight hidden-state probes with distributional guarantees. LYNX achieves cross-domain transferability without retraining—ideal when you nee

SKILL.md

GitHub

Overview

LYNX implements online early-exit mechanisms that leverage model hidden states to make confidence-controlled stopping decisions. A lightweight probe operates during generation without auxiliary verifiers, with conformal prediction providing calibrated confidence thresholds.

When to Use

  • Reasoning models that generate unnecessarily long outputs
  • Need for confidence-aware early stopping
  • Efficiency improvements without separate verifiers
  • Cross-domain transfer without retraining
  • Balancing accuracy and latency

When NOT to Use

  • Models with unavailable hidden states
  • Scenarios where full generation is always needed
  • Real-time systems with strict latency bounds

Core Technique

Hidden state confidence estimation with conformal prediction:

# LYNX: Dynamic early exit via confidence
class LYNXEarlyExit:
    def __init__(self, model):
        self.model = model
        self.exit_probe = nn.Linear(hidden_dim, 1)

    def identify_reasoning_cues(self, generation):
        """Find natural exit points like 'hmm', 'wait', period."""
        cues = ['hmm', 'wait', '.', ':', 'therefore']
        cue_positions = []

        for cue in cues:
            positions = [i for i, token in enumerate(generation)
                        if token.lower() == cue]
            cue_positions.extend(positions)

        return sorted(set(cue_positions))

    def extract_hidden_states_at_cues(self, generation, cue_positions):
        """Get hidden states at natural reasoning cues."""
        hidden_states = []

        for pos in cue_positions:
            hidden = self.model.get_hidden_at_position(pos)
            hidden_states.append(hidden)

        return hidden_states

    def compute_exit_scores(self, hidden_states):
        """Predict confidence for early termination."""
        scores = [self.exit_probe(h).item() for h in hidden_states]
        return scores

    def apply_conformal_prediction(self, scores):
        """Calibrated confidence thresholds via split conformal."""
        # Conformal prediction: distribution-free guarantees
        threshold = torch.quantile(torch.tensor(scores), 0.9)
        return threshold

    def generate_with_early_exit(self, prompt):
        """Generate with confidence-controlled stopping."""
        generation = []

        for step in range(max_steps):
            # Standard generation
            token = self.model.generate_token(prompt)
            generation.append(token)

            # Check for reasoning cues
            if token in ['hmm', 'wait', '.']:
                hidden = self.model.get_hidden_at_position(len(generation)-1)
                score = self.exit_probe(hidden)

                # Conformal threshold
                threshold = self.get_calibrated_threshold()

                if score > threshold:
                    # Exit with confidence
                    break

        return generation

Key Results

  • Lightweight probe design
  • Cross-domain transferability
  • Distribution-free confidence guarantees
  • Model family independent

References