Skip to content

Fix profiler unit tests - #180380

Closed
scotts wants to merge 15 commits into
pytorch:mainfrom
scotts:fix_profiler_unit_tests
Closed

scotts wants to merge 15 commits into
pytorch:mainfrom
scotts:fix_profiler_unit_tests

Conversation

@scotts

@scotts scotts commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Profiler unit tests were calling os.environ["key"] = "value" to change local behavior. But that changes the testing processes environment, polluting other tests.

This causes strange failures, where running python -m pytest test/profiler/test_memory_profiler.py would succeed, but then tests in that file would fail when all tests were run with python -m pytest test/profiler/. Using unittest.mock.patch ensures these changes are isolated.

cc @gujinghui @PenghuiCheng @XiaobingSuper @jianyuh @jgong5 @mingfeima @sanchitintel @ashokei @jingxu10 @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen @snadampal @mcarilli @ptrblck @leslie-fang-intel @EikanWang @voznesenskym @penguinwu @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @Lucaskabela @azahed98

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Apr 14, 2026
@pytorch-bot

pytorch-bot Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ No Failures, 60 Pending

As of commit e88e065 with merge base c90ce2b (image):
💚 Looks good so far! There are no failures yet. 💚

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

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

@scotts
scotts marked this pull request as ready for review April 14, 2026 21:06
@scotts

scotts commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 14, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@scotts

scotts commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

scotts and others added 15 commits April 15, 2026 10:37
…ytorch#176345)

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

Pull Request resolved: pytorch#176345
Approved by: https://github.com/shunting314
This PR is to upgrade oneDNN to v3.11.2.

## Improvements
- Improved fp32 matmul performance with fp4 compressed weights.
- Improved fp32 matmul performance for cases when one of the tensors has a trivial dimension on processors with Intel AVX-512 instruction set support.
- Improved fp16/bf16 matmul performance for large tensor cases on Intel Graphics for Intel Core Ultra processor Series 3 (formerly Panther Lake).
- Improved matmul performance for cases with 4-byte alignment on Intel GPUs based on Xe2 architecture.
- Improved performance of fp16/bf16 matmul with mxfp4 weights.
- Introduced destination tensor [dynamic quantization](https://uxlfoundation.github.io/oneDNN/v3.11/dev_guide_attributes_quantization.html#dynamic-quantization) in matmul primitive following Open Compute Microscaling (MX) formats specification.
- Introduced support for NVFP4 quantization scheme. The changes include support for fp8_e4m3 grouped scales and dynamic quantization support for destination tensor with NVFP4-specific formula for scales computation.
- Introduced support for dropout as a primitive attribute for matmul, softmax and eltwise primitives.

## Validation results on Xeon CPU
1. Dynamo benchmarks

The test results are based on the 3 dynamo benchmark suites with three data types.

<img width="787" height="231" alt="image" src="https://github.com/user-attachments/assets/5e31dc94-4b36-4354-9aa4-3223888d126d" />

According to the local test results, we found that two torchbench models on AMP_BF16 show over 7% performance regression:

- `torch_multimodal_clip` has 9% e2e regression.
- `BERT_pytorch` has 22% e2e performance regression.

# Validation results on Intel B60

Suite | Precision | Shape | Eager Speedup | Inductor Speedup
-- | -- | -- | -- | --
Huggingface | BF16 | Static | 1.003 | 1.002
Timm | Bf16 | Static | 1.001 | 0.999
Torchbench | BF16 | Static | 1.003 | 1.000

## Validation results on AArch64

### Dynamo Suite: Geomean over latency - prev version vs new version (**Higher is better**)
* for 16 Threads

Highlights for **Neoverse-V2** :
* MobileNetV3  1.15x lower latency with BF16.
* Detectron2  **1.6x** lower latency with BF16.
* AlexNet **6.2x** lower latency with BF16.

| Suite       | Precision | Shape   | Neoverse-V1 Eager Geomean | Neoverse-V1 Inductor Geomean | Neoverse-V2 Eager Geomean | Neoverse-V2 Inductor Geomean |
|------------|-----------|---------|---------------------------|------------------------------|--------------------------|-----------------------------|
| HuggingFace         | f32       | static  | 0.992358837               | 0.995203121                  | 1.0062                   | 1.007                       |
| HuggingFace         | f32       | dynamic | 0.991266938               | 0.993936984                  | 1.0082                   | 1.0081                      |
| HuggingFace         | bf16      | static  | 1.002295256               | 0.987069391                  | 0.997                    | 1.0134                      |
| HuggingFace         | bf16      | dynamic | 0.999110791               | 0.993443274                  | 1.00108                  | 1.0089                      |
| Timm       | f32       | static  | 0.989609104               | 0.997575891                  | 0.9168                   | -                      |
| Timm       | f32       | dynamic | 0.988387827               | 0.998601957                  | 0.92156                  |  -                      |
| Timm       | bf16      | static  | 1.007171058               | 1.01461039                   | 0.9925                   | 0.9949                      |
| Timm       | bf16      | dynamic | 1.008969741               | 1.016053648                  | 0.9928                   | 1.0321                      |
| Torchbench | f32       | static  | 0.997158099               | 1.00775975                   | 0.96                     | -                           |
| Torchbench | f32       | dynamic | 0.998372653               | 1.005439427                  | -                        | -                           |
| Torchbench | bf16      | static  | 1.011766848               | 1.02951623                   | 0.9815                   | 0.98613                     |
| Torchbench | bf16      | dynamic | 1.017915309               | 1.028806584                  | 0.9759                   | 0.9831                      |

### Torchbenchmark - Geomean over speedup (Higher is better)
* on 16 Threads

| Suite       | Precision | Shape   | Neoverse-V1 Eager Geomean | Neoverse-V1 TorchScript Geomean | Neoverse-V2 Eager Geomean | Neoverse-V2 TorchScript Geomean |
|------------|-----------|---------|---------------------------|---------------------------------|--------------------------|---------------------------------|
| Torchbench | amp_bf16  | inference | 1.00043                 | 1.02446                         | 1.023                    | 1.059                           |
| Torchbench | amp_bf16  | training  | 1.03322                 | -                               | -                        | -                               |
| Torchbench | fp32      | inference | 1.00452                 | 1.00715                         | 1.0675                   | 1.1086                          |
| Torchbench | fp32      | training  | 1.00121                 | -                               | -                        | -                               |

### NLP - FP32
* on 16 threads

| Suite | Neoverse-V1 Latency Geomean | Neoverse-V2 Latency Geomean |
|-------|-----------------------------|-----------------------------|
| NLP   | 0.996510961                 | 0.99651                     |

Pull Request resolved: pytorch#177607
Approved by: https://github.com/malfet, https://github.com/aditew01, https://github.com/atalman

Co-authored-by: fengqing.lu <[email protected]>
…h#180349)

Summary:

Default addmm path changes now to match NVIDIA/AMD and to prevent performance regressions. We fix the lookup table tests accordingly

Test Plan: buck2 run mode/opt caffe2/test/inductor:lookup_table

Reviewed By: njriasan

Differential Revision: D100810662

Pull Request resolved: pytorch#180349
Approved by: https://github.com/njriasan
…180270) (pytorch#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: pytorch#180270
Approved by: https://github.com/atalman
CUDA 13.2.1 is released today, prepare PR while we wait for the package to be available on pypi

Improvements in 13.2.1:
**Cublas** — CUDA 13.2.1
New data type support: NVFP4 inputs + bias epilogues now work on Blackwell (CC 10.x/11.0). BF16/FP16/FP8 inputs now work on Hopper, with FP8 supporting both tensorwide and block scaling (VEC128, BLK128x128).
Performance: Up to 20% faster Grouped GEMM on Blackwell for large problem sizes — directly benefits MoE model inference.
Bug fix: Fixed an issue in cublasLtMatmulAlgoGetHeuristic() could return zero algorithm candidates for Grouped GEMM on Blackwell, making it unusable in those cases. Now fixed. [CUB-9657]

Pull Request resolved: pytorch#180288
Approved by: https://github.com/Skylion007
pytorch#180070)

…al_types

Remove mypy suppressions. Add return type and parameter type annotations to constraint classes, generator, transformation, and z3 transform.

Authored with Claude.
Pull Request resolved: pytorch#180070
Approved by: https://github.com/Skylion007
The old implementation tagged backward nodes by running fx_traceback.annotate({"autograd_backward": True}) around traced autograd.grad. That stored autograd_backward in current_meta["custom"], which is also where user annotations such as {"ac_region_id": 0} live.

This was unsafe because some traceback save/restore paths only shallow-copy metadata. In particular, set_current_meta(node) does current_meta = node.meta.copy(), so current_meta["custom"] aliases node.meta["custom"]. A nested annotate({"autograd_backward": True}) then mutates that shared dict in place. When the nested scope exits, current_meta may be restored, but the source node metadata can stay polluted, which is how forward FlexAttention nodes ended up leaking autograd_backward.

Fix this by treating autograd_backward as internal tracing state instead of user custom metadata. Keep a dedicated current_meta["autograd_backward"] flag during tracing, stamp node.meta["autograd_backward"] on newly created nodes using setup_stacktrace_preservation_hook.

With this tagging, we can reorder backward nodes during partitioner, so regional_inductor now turns off remat pass. This is fine because, remat pass is intended to be consumed only after:
1. you torch.compile whole training step
2. you make_fx d whole training step

In relevant use cases, regional inductor will happen after SAC decision has been applied to the final graph.

Add non-strict tracing and FlexAttention regressions covering the leak.

Authored with Claude.

Pull Request resolved: pytorch#180251
Approved by: https://github.com/Skylion007, https://github.com/aorenste
Adds a deprecation warning for `metadata_json`, as we want to move away from using JSON as the default output for all things profiler and the info here is duplicated with `event_metadata`. I made it a property so that the warning prints when someone tries to use it.
Pull Request resolved: pytorch#179417
Approved by: https://github.com/scotts
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased fix_profiler_unit_tests onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout fix_profiler_unit_tests && git pull --rebase)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

This PR updates submodules third_party/ideep

If those updates are intentional, please add "submodule" keyword to PR title/description.

@scotts

scotts commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

Closed in favor of #180454.

@scotts scotts closed this Apr 15, 2026
pytorchmergebot pushed a commit that referenced this pull request Apr 15, 2026
Profiler unit tests were calling `os.environ["key"] = "value"` to change local behavior. But that changes the testing processes environment, polluting other tests.

This causes strange failures, where running `python -m pytest test/profiler/test_memory_profiler.py` would succeed, but then tests in that file would fail when all tests were run with `python -m pytest test/profiler/`. Using `unittest.mock.patch` ensures these changes are isolated.

Note that this PR is a redo of #180380 because that PR got hosed during a bad rebase.
Pull Request resolved: #180454
Approved by: https://github.com/ryanzhang22
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Profiler unit tests were calling `os.environ["key"] = "value"` to change local behavior. But that changes the testing processes environment, polluting other tests.

This causes strange failures, where running `python -m pytest test/profiler/test_memory_profiler.py` would succeed, but then tests in that file would fail when all tests were run with `python -m pytest test/profiler/`. Using `unittest.mock.patch` ensures these changes are isolated.

Note that this PR is a redo of pytorch#180380 because that PR got hosed during a bad rebase.
Pull Request resolved: pytorch#180454
Approved by: https://github.com/ryanzhang22
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Profiler unit tests were calling `os.environ["key"] = "value"` to change local behavior. But that changes the testing processes environment, polluting other tests.

This causes strange failures, where running `python -m pytest test/profiler/test_memory_profiler.py` would succeed, but then tests in that file would fail when all tests were run with `python -m pytest test/profiler/`. Using `unittest.mock.patch` ensures these changes are isolated.

Note that this PR is a redo of pytorch#180380 because that PR got hosed during a bad rebase.
Pull Request resolved: pytorch#180454
Approved by: https://github.com/ryanzhang22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 ciflow/h100 ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request merging module: amp (automated mixed precision) autocast module: dynamo module: inductor module: mkldnn Related to Intel IDEEP or oneDNN (a.k.a. mkldnn) integration NNC topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants