Skip to content

Commit 02ebebe

Browse files
Merge pull request #3713 from AI-Hypercomputer:hlo-identical-tests
PiperOrigin-RevId: 907074733
2 parents bbfcef6 + 925bf95 commit 02ebebe

10 files changed

Lines changed: 6429 additions & 8 deletions

.github/workflows/build_and_test_maxtext.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ jobs:
218218
base_image: maxtext-unit-test-tpu:py312
219219
cloud_runner: linux-x86-ct6e-180-4tpu
220220
pytest_marker: 'not cpu_only and not gpu_only and integration_test and not post_training'
221-
pytest_addopts: '--ignore=tests/post_training'
221+
pytest_addopts: '--ignore=tests/post_training --ignore=tests/integration/hlo_diff_test.py'
222222
xla_python_client_mem_fraction: 0.75
223223
tf_force_gpu_allow_growth: false
224224
container_resource_option: "--privileged"

.github/workflows/run_tests_against_package.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ on:
7070
description: 'If false, maxtext_sha must be provided for checkout'
7171
type: boolean
7272
default: false
73+
is_update_hlo:
74+
required: false
75+
type: boolean
76+
default: false
7377

7478
permissions:
7579
contents: read
@@ -168,13 +172,19 @@ jobs:
168172
else
169173
SPLIT_ARGS=""
170174
fi
171-
$PYTHON_EXE -m pytest ${INPUTS_PYTEST_ADDOPTS} \
172-
-v \
173-
-m "${FINAL_PYTEST_MARKER}" \
174-
--durations=0 \
175-
$PYTEST_COV_ARGS \
176-
$SPLIT_ARGS \
177-
${INPUTS_PYTEST_EXTRA_ARGS}
175+
176+
# Setup substitution: If manually updating HLO, skip tests execution and run only the update script instead!
177+
if [ "${INPUTS_IS_UPDATE_HLO}" == "true" ]; then
178+
python3 tests/utils/update_hlo_references.py
179+
else
180+
$PYTHON_EXE -m pytest ${INPUTS_PYTEST_ADDOPTS} \
181+
-v \
182+
-m "${FINAL_PYTEST_MARKER}" \
183+
--durations=0 \
184+
$PYTEST_COV_ARGS \
185+
$SPLIT_ARGS \
186+
${INPUTS_PYTEST_EXTRA_ARGS}
187+
fi
178188
179189
env:
180190
INPUTS_IS_SCHEDULED_RUN: ${{ inputs.is_scheduled_run }}
@@ -185,6 +195,14 @@ jobs:
185195
INPUTS_WORKER_GROUP: ${{ inputs.worker_group }}
186196
INPUTS_PYTEST_EXTRA_ARGS: ${{ inputs.pytest_extra_args }}
187197
INPUTS_MAXTEXT_INSTALLED: ${{ inputs.maxtext_installed }}
198+
INPUTS_IS_UPDATE_HLO: ${{ inputs.is_update_hlo }}
199+
- name: Upload Reference HLO
200+
if: ${{ inputs.is_update_hlo }}
201+
uses: actions/upload-artifact@v4
202+
with:
203+
name: reference-hlo
204+
path: tests/utils/reference_hlo_*.txt
205+
if-no-files-found: ignore
188206
- name: Upload results to Codecov
189207
if: ${{ !inputs.maxtext_installed }} # Skip code coverage upload for maxtext image testing
190208
uses: codecov/codecov-action@v5

.github/workflows/run_tests_coordinator.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ on:
4747
description: 'If false, maxtext_sha must be provided for checkout'
4848
type: boolean
4949
default: false
50+
is_update_hlo:
51+
required: false
52+
type: boolean
53+
default: false
5054

5155
permissions:
5256
contents: read
@@ -150,3 +154,4 @@ jobs:
150154
worker_group: ${{ matrix.worker_group }}
151155
total_workers: ${{ contains(inputs.flavor, 'cpu-unit') && 2 || 1 }}
152156
maxtext_sha: ${{ inputs.maxtext_sha }}
157+
is_update_hlo: ${{ inputs.is_update_hlo }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "Update HLO References (for hlo_diff_test.py)"
2+
3+
on:
4+
workflow_dispatch:
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
build-wheel:
10+
uses: ./.github/workflows/build_package.yml
11+
with:
12+
device_type: tpu
13+
device_name: v6e-4
14+
cloud_runner: linux-x86-n2-16-buildkit
15+
16+
run-tests:
17+
needs: build-wheel
18+
uses: ./.github/workflows/run_tests_coordinator.yml
19+
with:
20+
flavor: tpu-integration
21+
base_image: maxtext-unit-test-tpu:py312
22+
is_scheduled_run: false
23+
maxtext_sha: ${{ github.sha }}
24+
is_update_hlo: true
25+
26+
commit-changes:
27+
needs: run-tests # Wait for tests to finish
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: write
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
with:
35+
ref: ${{ github.ref }}
36+
37+
- name: Download Reference HLO
38+
uses: actions/download-artifact@v4
39+
with:
40+
name: reference-hlo
41+
path: tests/utils/
42+
43+
- name: Commit and Push changes
44+
run: |
45+
git config --global user.name "github-actions[bot]"
46+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
47+
git add tests/utils/reference_hlo_*.txt
48+
git commit -m "Update reference HLO from CI artifact"
49+
git push
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# HLO Graph Diff Verification Testing
2+
3+
This document provides context for the HLO Graph Diff tests, what HLO is, and how to manage reference baselines.
4+
5+
## Related Files
6+
7+
- **Test Logic**: `tests/integration/hlo_diff_test.py`
8+
- **Reference Checkpoints baselines**: `tests/utils/reference_hlo_*.txt`
9+
- **Update Helper script**: `tests/utils/update_hlo_references.py`
10+
- **GitHub Action Trigger Workflow**: `.github/workflows/update_reference_hlo.yml`
11+
12+
## What is HLO?
13+
14+
**HLO (High-Level Optimizer)** is the intermediate representation used by XLA (Accelerated Linear Algebra) to capture the lowering compiler graph structures.
15+
16+
An HLO module records:
17+
18+
- The sequences of low-level math operations (dot products, convolutions, additions).
19+
- Array tensor shapes and numerical precisions.
20+
- Multipod TPU cluster partitioning array sharding mappings.
21+
22+
## Purpose of HloDiffTest
23+
24+
The primary purpose of the `TestHloDiff` validation checks is to ensure that **refactoring PRs are purely refactoring code** and not unintentionally impacting graph compiler lowering or performance.
25+
26+
- **For pure refactors:** The HLO graph layout should remain *strictly identical*. Any detected deviation flags that execution boundaries or operation pipelines might have changed under the hood.
27+
- **For dependency updates:** Changes to framework dependencies (like updating JAX or XLA versions) *are expected* to slightly alter compiled HLO output layouts, which makes baseline updates appropriate in those scenarios.
28+
29+
______________________________________________________________________
30+
31+
## How the Test Works
32+
33+
This test runs automatically as part of the [`tpu-integration`](https://github.com/AI-Hypercomputer/maxtext/actions/workflows/build_and_test_maxtext.yml) CI test suite on every Pull Request.
34+
35+
When the test method executes, it performs the following sequence of actions:
36+
37+
1. **Triggers Compilation**: It runs the model training lifecycle compilation-only phase (invoking `train_compile.main()`) without actually allocating hardware compute nodes or running optimization passes.
38+
2. **Dumps HLO modules**: Instructs the XLA compiler back-end to capture optimizer operations lowering structure graphs and dump them to text files.
39+
3. **Strict comparison matches**: Compares the structural lines of the generated representation graph directly against baseline `.txt` copies stored under `tests/utils/`.
40+
41+
______________________________________________________________________
42+
43+
## Updating HLO reference files
44+
45+
When intended architectures transformations alter graph lowering, reference file baselines require updates.
46+
47+
> [!IMPORTANT]\
48+
> While running the update script locally is not the end of the world, **relying on local execution can cause remote CI tests to fail.**
49+
> The PR verification pipelines run the tests in a strictly locked GitHub Actions environment. The smallest discrepancies in local library installations will introduce slight backend lowering graph deviations. If your local execution leads to a remote CI check failure, rely on the GitHub Action trigger described below to generate environment-matching baselines.
50+
51+
### Method 1: Run the manual GitHub Action Workflow (Highly Recommended)
52+
53+
Triggering the CI workflow guarantees execution runs within the correct environment isolation scope.
54+
55+
#### Option A: Using the GitHub UI
56+
57+
1. Go to the Actions tab in the repository browser.
58+
2. Find the manual workflow: `Update HLO References (for hlo_diff_test.py)`.
59+
3. Run it targeting your PR workspace branch. It compiles the graph layout and commits the baseline update files back to the branch automatically.
60+
61+
#### Option B: Using the GitHub CLI (`gh`)
62+
63+
Alternatively, you can trigger the remote workflow via terminal CLI execution:
64+
65+
```bash
66+
gh workflow run update_reference_hlo.yml --ref <branch>
67+
```
68+
69+
> [!NOTE]
70+
> A successful run of the manual update workflow will add a new commit to your Pull Request branch. Once complete, you must:
71+
>
72+
> 1. Pull the new commit from remote.
73+
> 2. Squash the commits in your branch once again to keep your PR history clean.
74+
> 3. Push the squashed commit to remote.
75+
> 4. Retry the `tpu-integration` workflow to verify tests pass on your PR.
76+
77+
### Method 2: Local Execution
78+
79+
If you need to test or update baselines manually during development:
80+
81+
```bash
82+
source .venv/bin/activate
83+
pytest tests/integration/hlo_diff_test.py -v
84+
```
85+
86+
Or to force update the local baselines:
87+
88+
```bash
89+
python3 tests/utils/update_hlo_references.py
90+
```

0 commit comments

Comments
 (0)