Skip to content

fix(encoders): honor exact GELU activation - #1801

Draft
JiaxinD wants to merge 5 commits into
NVIDIA:mainfrom
JiaxinD:fix/bert-exact-gelu
Draft

JiaxinD wants to merge 5 commits into
NVIDIA:mainfrom
JiaxinD:fix/bert-exact-gelu

Conversation

@JiaxinD

@JiaxinD JiaxinD commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Background

BERT, MPNet, DistilBERT, Electra and DPR map both gelu and gelu_new to the tanh approximation. Hugging Face defines gelu as exact erf GELU. Official BGE/MiniLM/BERT, all-mpnet-base-v2, DistilBERT, Electra-base and DPR context/question checkpoints select gelu. Sampled CPU output differs from exact GELU by up to approximately 0.00041246 before repair.

Exit Criteria

Honor both activation definitions in these five families. Preserve existing E2E references and thresholds. This extends the original correction in the same PR.

Implementation

  • Route gelu to TensorRT GELU_ERF, following upstream RoBERTa.
  • Retain the existing tanh implementation for gelu_new.
  • Execute each family's actual activation functions with numerical CPU network doubles over vector and multidimensional inputs.

All ten changed files belong to these families. No shared helper, cross-family import, API/ABI, dependency or bundle-format change. Current upstream is merged without rewriting published history.

Change categories

  • Model or runtime behavior
  • Public API
  • ABI
  • Bundle or artifact format
  • Dependencies
  • Documentation only
  • CI or developer tooling

Validation

Commands and Results

Executed check Result
BERT regressions before original repair 3 failed, 3 passed
MPNet/DistilBERT regressions before prior extension 6 failed, 6 passed
pytest families/electra/tests/test_activation_contract.py families/dpr/tests/test_activation_contract.py -q before this repair 6 failed, 6 passed; exact GELU fails, tanh controls pass
pytest families/{bert,mpnet,distilbert,electra,dpr}/tests -q with paths expanded Baseline 33 passed, 15 skipped; final 45 passed, 15 skipped
pytest tools/tests/test_{architecture,family_impact,public_source_hygiene,pr_metadata}.py -q with paths expanded 99 passed
Catalog/impact, legal headers, Ruff and diff checks Passed

Hardware, Environment, and Revisions

Windows CPU, Python 3.13, NumPy float32. Upstream a9cae5db; head 170479073e713112af9865d76b4a344624721b66. Official configs: Electra 1ae76a97c7e84a4e640876a07453fccd636f0667, DPR question d04a52f6d2f96c60117a925e8c24c4043a75f265, DPR context bb21a3c2b1656d60c6a8e920283bc40dabddadb8. Prior BGE/MiniLM/BERT, MPNet, DistilBERT configs and Transformers v5.2.0 definitions retained. No weights downloaded.

Not Run / Remaining Gaps

Fifteen E2E cases skipped without model selectors. TensorRT/GPU execution, FP16/BF16, checkpoint/config-route integration, TP and performance are unrun locally; Radix authentication expired. The CPU double proves dispatch and sampled math, not TensorRT dtype or fusion. Previous-head CPU/Stable/Dev passes do not qualify this head; current public/protected results are pending.

Contributor Self-Review

  • I have completed a self-review of this change.

Reviewed definitions, both builder call paths, scope and regression failures. Independent read-only review reran the family suites; its result is recorded with this revision.

Notes For Future Readers

Rebuild bundles selecting gelu. These graph fixes are independent of assigned Task SDK migrations, including #1584, and #1763's capability removal. Review each family independently. No reference, threshold or family-count guard is relaxed.

Risk level

  • Low
  • Medium
  • High

Exact-GELU checkpoints intentionally build a different graph. Target-hardware parity and performance remain qualification work.

Signed-off-by: JiaxinD <djx2048@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: JiaxinD <djx2048@gmail.com>
Signed-off-by: JiaxinD <djx2048@gmail.com>
@JiaxinD JiaxinD changed the title fix(bert): honor exact GELU activation fix(encoders): honor exact GELU activation Oct 19, 2026
@JiaxinD

JiaxinD commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@yifeif-nv Community CPU, Stable and Dev checks passed for 7367609. Please trigger protected CI for this head.

Signed-off-by: JiaxinD <djx2048@gmail.com>
Signed-off-by: JiaxinD <djx2048@gmail.com>
@JiaxinD

JiaxinD commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@yifeif-nv Community CPU passed for 1704790. Please trigger protected CI for this head.

@chaofengw-nv chaofengw-nv added the run-internal-ci Maintainer-approved dispatch to internal CI label Oct 23, 2026
@github-actions github-actions Bot removed the run-internal-ci Maintainer-approved dispatch to internal CI label Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants