← Back to Pull requests

Fix MPS GPT-2 NaNs and T5Gemma2 beam expansion #2155

Closed
unknown closed this pull request without merging on Nov 17, 2026 15:12 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 18:31 UTC
Author

Fix two inference regressions reported with GPT-2 and T5Gemma2 on MPS.

  • Use precise::tanh for Metal tanh and tanh-GELU. The fast-math implementation can return NaNs for large finite inputs, including through fused bias and GEMM activation epilogues.

  • Calculate the merged-attention beam size after restoring padding to the projected encoder keys. Live encoder memory can contain packed token rows; its first dimension is not the batch size.
  • Regression tests cover large finite tanh/GELU inputs, including fused epilogues, and a padded batch with beam_size=2 on CPU and MPS. The attention test compares packed and unpacked memory on the first step and with cached encoder projections on the next step. Both regressions fail against the unmodified upstream library.

    Validation on an Apple M1:

  • Native CPU/MPS suite: 599 passed, 31 skipped. Separate MPS-disabled build: 370 passed, 16 skipped.

  • Existing Python storage/translation tests: 72 passed, 5 skipped.

  • Real GPT-2 FP32: all 251,285 prefill logits finite; maximum difference from CPU 0.000321. Greedy and beam-size-2 generation matched CPU tokens.

  • Real jordimas/t5gemma-2-270m-270m: eight padded inputs of lengths 185, 166, 178, 348, 233, 200, 293 and 110, beam_size=2, maximum output length 64. Two runs per device completed with finite scores and valid tokens. CPU and MPS tokens matched for all eight inputs.
  • The T5Gemma2 reproduction uses the unchanged upstream converter and no new masking code. Masking, FP16 rescaling and converter changes are tracked separately in draft #2157.

    Fixes #2153
    Fixes #2154

    Diff: 198 lines (+148 / -50) across 2 files Reviewer: jordimas Review duration: 2681m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 198 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.317
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2155"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.1% (MEDIUM) · Higher = larger blast radius
    36.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.3% · Safe to merge
    14.3%