Skip to content

[devtools] Add preprocessing support to NumericalComparatorBase#17433

Merged
Gasoonjia merged 8 commits intogh/gasoonjia/119/basefrom
gh/gasoonjia/119/head
Feb 25, 2026
Merged

[devtools] Add preprocessing support to NumericalComparatorBase#17433
Gasoonjia merged 8 commits intogh/gasoonjia/119/basefrom
gh/gasoonjia/119/head

Conversation

@Gasoonjia
Copy link
Copy Markdown
Contributor

@Gasoonjia Gasoonjia commented Feb 13, 2026

Stack from ghstack (oldest at bottom):

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:

  • Extended NumericalComparatorBase with:
    • __init__(inspector) to store optional Inspector reference for accessing graph metadata
    • preprocessing(mapping) method that can be overridden for custom tensor transformations (default: identity)
    • element_compare(a, b) abstract method for element-level tensor comparison
    • compare(mapping, ...) method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: D93169813

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 13, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/17433

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 Cancelled Job

As of commit 2c27e4d with merge base 63f9724 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 13, 2026
Gasoonjia added a commit that referenced this pull request Feb 13, 2026
This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

ghstack-source-id: 340935651
Pull Request resolved: #17433
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
Gasoonjia added a commit that referenced this pull request Feb 13, 2026
Pull Request resolved: #17433

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)
ghstack-source-id: 340943620
…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
Gasoonjia added a commit that referenced this pull request Feb 13, 2026
Pull Request resolved: #17433

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud
ghstack-source-id: 340952320

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)
…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
custom_comparator = ScalingComparator(scale_factor=2.0)

# Test with custom comparator
df = inspector_instance.calculate_numeric_gap(distance=custom_comparator)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Gasoonjia,
Thank you so much for the PR to support the preprocessing.
Sorry I am now having limited access to laptop and may not be able to try out this PR until next week.

For this unit test, could you add a case where we will be performing multiple comparisons? For example, perform custom_operator and then perform a snr comparator immediately, and both the comparator requires that same preprocessing function. I believe this would be a UT that can closely align with Qualcomm's use case, which also helps demonstrate how inspector expects users to handle the intermediate tensor map between comparison.
Thanks

Copy link
Copy Markdown
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@winskuo-quic
Copy link
Copy Markdown
Collaborator

Hi @Gasoonjia,
Thanks again for the PR.
I have left a comment above related to unit test. Besides, this PR looks good to me.
Thanks

…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
@Gasoonjia
Copy link
Copy Markdown
Contributor Author

thansk for comment @winskuo-quic
I've updated the existing test to support two consecutive numeric comparator with same preprocessor.
Plz let me know if there's any concern, or i will land them in recent days.

…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
…rBase"

This change extends NumericalComparatorBase to support custom preprocessing before numeric gap calculation, enabling backends like Qualcomm to apply necessary tensor transformations (e.g., dequantization, layout conversion) before comparison.

Key changes:
- Extended NumericalComparatorBase with:
  - `__init__(inspector)` to store optional Inspector reference for accessing graph metadata
  - `preprocessing(mapping)` method that can be overridden for custom tensor transformations (default: identity)
  - `element_compare(a, b)` abstract method for element-level tensor comparison
  - `compare(mapping, ...)` method that orchestrates the full pipeline: preprocessing → element-wise compare → aggregate to DataFrame

This is part of the operator-level numeric discrepancy detector project for ExecuTorch Qualcomm backend (#16381).

Design doc: https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision: [D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)

[ghstack-poisoned]
@Gasoonjia Gasoonjia merged commit b3f0a27 into gh/gasoonjia/119/base Feb 25, 2026
202 of 203 checks passed
@Gasoonjia Gasoonjia deleted the gh/gasoonjia/119/head branch February 25, 2026 08:02
Gasoonjia added a commit that referenced this pull request Feb 25, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* #17459
* __->__ #17434
* #17433

When `to_edge_transform_and_lower` is called with
`generate_etrecord=True` and custom `transform_passes` are applied, the
after-transform graph is now automatically recorded in the ETRecord's
`graph_map` under the key `"edge_after_transform"`. This enables
backends like Qualcomm to use the post-custom-transform graph as the
golden reference for numeric gap calculation, while have zero impact for
regular exportation.


This is part of the operator-level numeric discrepancy detector project
for ExecuTorch Qualcomm backend
(#16381).

Design doc:
https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision:
[D93176563](https://our.internmc.facebook.com/intern/diff/D93176563/)
Gasoonjia added a commit that referenced this pull request Feb 25, 2026
…7459)

Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* __->__ #17459
* #17434
* #17433

This change adds a `reference_graph` parameter to the
`calculate_numeric_gap` API, allowing users to explicitly select which
graph to use as the golden reference for numeric gap calculation, which
enables backends like Qualcomm to use the post-custom-transform graph as
the golden reference for numeric gap calculation.

This is part of the operator-level numeric discrepancy detector project
for ExecuTorch Qualcomm backend
(#16381).

Design doc:
https://docs.google.com/document/d/1GaCHiy9InytOsUrl2BKEgOiP1iKTfpCVdWg6QDh0N2E/edit?tab=t.0#heading=h.fcrpnrtb6cud

Differential Revision:
[D93266779](https://our.internmc.facebook.com/intern/diff/D93266779/)
Gasoonjia added a commit that referenced this pull request Feb 25, 2026
This PR was created by the merge bot to help merge the original PR into
the main branch.
ghstack PR number: #17433 by
@Gasoonjia
^ Please use this as the source of truth for the PR details, comments,
and reviews
ghstack PR base:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/119/base
ghstack PR head:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/119/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/main
Merge bot PR head:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/119/orig
Differential Revision:
[D93169813](https://our.internmc.facebook.com/intern/diff/D93169813/)
@diff-train-skip-merge

---------

Co-authored-by: gasoonjia <gasoonjia@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants