Skip to content

Parallelize some L0 python tests across all GPUs - #3903

Open
kainzhong wants to merge 6 commits into
NVIDIA:mainfrom
kainzhong:parallelize_pytest
Open

kainzhong wants to merge 6 commits into
NVIDIA:mainfrom
kainzhong:parallelize_pytest

Conversation

@kainzhong

Copy link
Copy Markdown
Collaborator

On multi-GPU nodes, run selected PyTorch and JAX L0 test files with one pytest-xdist worker per GPU. A small pytest plugin gives each worker its own GPU. Only files whose tests don't share files on disk, don't depend on test order and need a single GPU opt in; the rest run as before.

Description

For a subset of python tests (both pytorch and jax), they are safe to run in parallel on multiple GPUs if they are available. By parallelizing these tests CI can run faster.

Note: there are some tests that assume that they will run in serial and will share files like test_attention.py. These cannot be parallelized and I skipped them.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Parallelize some python tests

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

On multi-GPU nodes, run selected PyTorch and JAX L0 test files with one
pytest-xdist worker per GPU. A small pytest plugin gives each worker its
own GPU. Only files whose tests don't share files on disk, don't depend
on test order and need a single GPU opt in; the rest run as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous coverage issue is fixed.

Summary

The PR runs selected PyTorch and JAX tests with one worker per GPU.

  • Selected L0 tests run across the available GPUs.

Reviews (5) · Last reviewed commit: "Note how to run multi-GPU JAX tests in t..." · Reviewed by Greptile

@kainzhong

Copy link
Copy Markdown
Collaborator Author

/te-ci

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
@kainzhong

Copy link
Copy Markdown
Collaborator Author

/te-ci

@ptrendx

ptrendx commented Nov 21, 2026

Copy link
Copy Markdown
Member

Looking at the CI timings, I do not see a lot of speedup coming from this on 8 GPU B200 node, with some tests taking nearly exactly the same amount of time - do you know why that is?

@kainzhong

Copy link
Copy Markdown
Collaborator Author

Looking at the CI timings, I do not see a lot of speedup coming from this on 8 GPU B200 node, with some tests taking nearly exactly the same amount of time - do you know why that is?

@ptrendx I compared https://gitlab-master.nvidia.com/dl/transformerengine/transformerengine/-/jobs/562748639 (parallel) and https://gitlab-master.nvidia.com/dl/transformerengine/transformerengine/-/jobs/560421016 (serial from some other PR) and the comparsion:

  ┌─────────────────────────────┬─────────────────────┬─────────────────────┬────────────────┬──────────┐
  │            File             │       Serial        │  Parallel (8 GPUs)  │    Speedup     │  Saved   │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ mxfp8/                      │             887.3 s │             149.2 s │          5.95× │    738 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_torch_compile.py       │             401.5 s │              82.5 s │          4.87× │    319 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_permutation.py         │             298.3 s │             141.9 s │          2.10× │    156 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_grouped_mlp.py         │             277.7 s │             307.1 s │ 0.90× (slower) │    −29 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_gdp_attention.py       │             222.2 s │              85.7 s │          2.59× │    137 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_cpu_offloading.py      │             144.2 s │              64.9 s │          2.22× │     79 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_kda_attention.py       │             134.1 s │              46.2 s │          2.90× │     88 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_cuda_graphs.py         │             132.1 s │              47.9 s │          2.76× │     84 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_gdn2_attention.py      │             114.8 s │              57.9 s │          1.98× │     57 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_kv_cache.py            │              98.1 s │              31.1 s │          3.16× │     67 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_fused_rope.py          │              79.1 s │              26.6 s │          2.97× │     52 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_gdn_attention.py       │              66.9 s │              45.8 s │          1.46× │     21 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ test_backward_override.py   │              61.6 s │              43.8 s │          1.41× │     18 s │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ Split total                 │ 2917.9 s (48.6 min) │ 1130.5 s (18.8 min) │          2.58× │ 29.8 min │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ Unsplit files (48 commands) │            2435.8 s │            2430.0 s │          1.00× │        — │
  ├─────────────────────────────┼─────────────────────┼─────────────────────┼────────────────┼──────────┤
  │ All pytest time             │ 5353.7 s (89.2 min) │ 3560.5 s (59.3 min) │          1.50× │          │
  └─────────────────────────────┴─────────────────────┴─────────────────────┴────────────────┴──────────┘

These are only a subset of all tests and for other tests they assume they run in serial and will edit files, which is a bit tricky to parallelize so I left them for now. I don't fully know why grouped MLP isn't faster which is weird.

I also don't understand how gitlab CI's "Duration" is calculated. Does it also including queuing time?

@kainzhong

Copy link
Copy Markdown
Collaborator Author

Hum I can't reproduce test_grouped_mlp.py. I suspect it's because that CI node doesn't have cache so compilation is a lot slower

Every worker's OpenMP pool defaulted to all physical cores, so eight workers
ran 896 threads on 224 CPUs and small CPU ops such as float64 reference
computations slowed down by orders of magnitude. Give each worker an equal
share of the CPUs unless OMP_NUM_THREADS is already set.

On 8x B200, this cuts the split L0 PyTorch commands from 1001s to 603s
(test_grouped_mlp.py: 307s to 97s); the JAX commands are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
@kainzhong

Copy link
Copy Markdown
Collaborator Author

OK I also evenly split the CPU resources on the pytest processes. This should make test_grouped_mlp.py faster since it's using CPU to compute references.

@kainzhong

Copy link
Copy Markdown
Collaborator Author

/te-ci

@fheinecke
fheinecke self-requested a review November 24, 2026 19:01
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread qa/L0_jax_unittest/test.sh Resolved
kainzhong and others added 2 commits November 24, 2026 21:01
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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