Skip to content

chore(toolchain): Update PTOAS to v0.52 and adapt ptoas discovery - #2135

Open
luohuan19 wants to merge 6 commits into
hw-native-sys:mainfrom
luohuan19:fix-potas
Open

chore(toolchain): Update PTOAS to v0.52 and adapt ptoas discovery#2135
luohuan19 wants to merge 6 commits into
hw-native-sys:mainfrom
luohuan19:fix-potas

Conversation

@luohuan19

@luohuan19 luohuan19 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What

Bump the pinned PTOAS toolchain to v0.52, adapt PyPTO's ptoas discovery to
the tarball layout change that came with v0.51, and add two DeepSeek-V4-Flash
examples to the pypto-lib-model CI job.

Changes

1. PTOAS v0.52 pin

toolchain/versions.envPTOAS_VERSION v0.48 → v0.52, with refreshed
aarch64 / x86_64 SHA256s. Both hashes were checked against the release asset
digests of hw-native-sys/PTOAS v0.52 (ptoas-bin-aarch64.tar.gz /
ptoas-bin-x86_64.tar.gz).

2. Adapt ptoas discovery to the post-v0.50 tarball layout

The v0.51 release reorganised the tarball. <root>/ptoas changed from a shell
launcher into a Python package directory, leaving <root>/bin/ptoas as the
only executable. PyPTO resolved $PTOAS_ROOT/ptoas, so from v0.51 on it
resolved a directory and every codegen call failed with:

PTOAS_ROOT is set to '.../ptoas-bin' but '.../ptoas-bin/ptoas'
does not exist or is not executable.

That took down system-tests, system-tests-direct, system-tests-a5sim,
dist-system-tests and pypto-lib-model.

Discovery now probes <root>/ptoas first and falls back to <root>/bin/ptoas.
The order is load-bearing, not cosmetic:

<root>/ptoas <root>/bin/ptoas
up to v0.50 shell launcher — exports LD_LIBRARY_PATH=<root>/lib, then execs the binary bare binary, no RUNPATHldd reports 337 missing objects
from v0.51 Python package directory self-sufficient — ldd clean, runs standalone

Launcher-first is correct on both layouts: pre-v0.51 it picks the launcher, and
from v0.51 the top-level entry is a directory so the probe falls through to
bin/ptoas. Probing bin/ptoas first would turn CI green while silently
breaking every pre-v0.51 toolchain on its bundled MLIR shared objects.

The probe is version-agnostic — it tests each candidate for being an executable
file rather than keying off the release — so the v0.52 bump needs no discovery
change on top of it.

The same logic was duplicated across three modules, so it moves to a shared
pypto/backend/_ptoas_locate.py. Two of the three call sites degrade
silently
rather than raising, which is why patching only the site CI exercises
was not enough:

  • pypto/jit/decorator.py_ptoas_available() returning False flips
    skip_ptoas on, so @pl.jit "compiles successfully" but emits only raw
    .pto, no kernel cpp/so, and no error.
  • pypto/runtime/debug/pto_rebuild.py — prints a one-line skip and rebuilds the
    stale kernel cpp, so an edited .pto appears not to take effect on replay.

3. DeepSeek-V4-Flash CI coverage

Two examples added to the pypto-lib-model job:

  • decode_attention_csa (single device)
  • moe (--device-num 2 --ep 2)

A duplicated prefill_attention_csa step is dropped in the same pass.

Note on InsertCommFence

An earlier revision of this PR also suspended the publish-side region
system.cacheinvalid, because ptoas 0.51 lowered it to
PTOAS__DCCI_SINGLE_CACHE_LINE(<GlobalTensor>) — whose body calls
dcci((__gm__ void*)ptr, ...), and GlobalTensor has no conversion to
__gm__ void* in any pto-isa revision — which broke 36 dist-system-tests and
the moe example.

That is no longer part of this PR: #2138 reverted the whole InsertCommFence
pass (#2076), so the offending emission no longer exists on main and this
branch has been rebased on top of that revert. The underlying ptoas gap is
tracked at
hw-native-sys/PTOAS#995 and
must be resolved before InsertCommFence is re-landed.

Testing

  • Both v0.52 SHA256s verified against the published release asset digests
  • tests/ut/backend/test_ptoas_locate.py covers both tarball layouts and the
    launcher-first ordering
  • Full CI on this branch under the v0.52 pin

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

PTOAS v0.51 support adds centralized executable discovery for multiple release layouts, updates backend consumers and tests, and adds two DeepSeek-V4-Flash examples to model CI coverage.

Changes

PTOAS discovery and integration

Layer / File(s) Summary
PTOAS locator and validation
toolchain/versions.env, python/pypto/backend/_ptoas_locate.py, tests/ut/backend/test_ptoas_locate.py
PTOAS is pinned to v0.51; discovery checks configured root layouts in launcher-first order, with tests covering executable selection, invalid paths, and PATH behavior.
PTOAS consumer integration
python/pypto/backend/pto_backend.py, python/pypto/jit/decorator.py, python/pypto/runtime/debug/pto_rebuild.py
Backend execution, JIT availability checks, and kernel rebuilding use the shared locator; backend errors now report attempted paths or setup guidance.

Model CI coverage

Layer / File(s) Summary
DeepSeek-V4-Flash CI steps
.github/workflows/ci.yml
The model CI job runs CSA prefill attention and two-device MoE examples with the existing environment setup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A bunny found ptoas in a new little bin,
Checked every launcher before letting it in.
Two DeepSeek hops join the CI parade,
While v0.51 keeps the toolchain well-made. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed It summarizes the main change: updating PTOAS and adapting discovery, plus the CI additions.
Description check ✅ Passed The description is on-topic and describes the PTOAS bump, discovery update, and CI additions.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45edc35fb5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .github/workflows/ci.yml Outdated
@luohuan19
luohuan19 force-pushed the fix-potas branch 3 times, most recently from b66bb0b to b01223d Compare July 24, 2026 08:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 753-759: Remove the duplicate “Run pypto-lib DeepSeek-V4-Flash
prefill_attention_csa example” step from the workflow, while preserving the
existing identical prefill_attention_csa.py step elsewhere in the CI job.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a48c26e3-98c1-4c4e-a2b0-c51831aa892d

📥 Commits

Reviewing files that changed from the base of the PR and between efb7837 and 2133497.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • python/pypto/backend/_ptoas_locate.py
  • python/pypto/backend/pto_backend.py
  • python/pypto/jit/decorator.py
  • python/pypto/runtime/debug/pto_rebuild.py
  • tests/ut/backend/test_ptoas_locate.py
  • toolchain/versions.env

Comment thread .github/workflows/ci.yml Outdated
@luohuan19 luohuan19 changed the title Update PTOAS to v0.51, add DeepSeek-V4-Flash prefill_attention_csa and moe to CI job chore(toolchain): Update PTOAS to v0.51 and adapt ptoas discovery Jul 24, 2026
@georgebisbas

Copy link
Copy Markdown
Contributor

Hi! This PR will face an issue #2136 that is fixed in #2137 so maybe we can wait for 2137 first?

PTOAS v0.51 reorganised the release tarball: `<root>/ptoas` changed from a
shell launcher into a Python package *directory*, leaving `<root>/bin/ptoas`
as the only executable. Every codegen call resolved `$PTOAS_ROOT/ptoas` and
so failed with "does not exist or is not executable", taking down the
system-tests, system-tests-direct, system-tests-a5sim, dist-system-tests and
pypto-lib-model jobs.

Probe `<root>/ptoas` first and fall back to `<root>/bin/ptoas`. The order
matters and is not cosmetic: up to v0.50 the top-level entry is a launcher
that exports LD_LIBRARY_PATH=<root>/lib before exec'ing the bare binary,
which carries no RUNPATH and otherwise dies on its bundled MLIR shared
objects. From v0.51 the top-level entry is a directory, so the probe falls
through to the now self-sufficient bin/ptoas. Launcher-first is correct on
both layouts; bin/ptoas-first silently breaks every pre-v0.51 toolchain.

The same discovery logic was duplicated in three modules, two of which
degrade silently rather than raising: jit's `_ptoas_available()` flips
`skip_ptoas` on, and `pto_rebuild` prints a skip line and rebuilds the stale
kernel cpp. Both would have gone quiet under v0.51, so the probe is shared
rather than patched at the one site CI happens to exercise.

Also drop a trailing-whitespace-only line in the new pypto-lib CI steps that
failed the pre-commit hook.
`pypto-lib-model` already runs `models/deepseek/v4-flash/prefill_attention_csa.py`,
so the step added here was a byte-identical second copy: the example compiled
and ran twice and burned an extra device allocation for no added coverage.

The `moe` step is genuinely new and stays.
Placed with the other decode_attention_* steps in `pypto-lib-model`.

This is the step the branch was meant to add: the earlier revision added a
second `prefill_attention_csa`, which the job already ran.
Sharing the ptoas probe removed the module-level `_ptoas_binary`, which
`tests/ut/runtime/test_pto_rebuild.py` monkeypatches in 15 tests — they all
died with AttributeError. Bind the shared helper to that name instead of
importing it under a new one, so the seam the tests patch still exists.
Both sha256 values verified against the release asset digests of
hw-native-sys/PTOAS v0.52 (ptoas-bin-aarch64.tar.gz /
ptoas-bin-x86_64.tar.gz).

The tarball layout probe added for v0.51 (python/pypto/backend/
_ptoas_locate.py) is version-agnostic — it tests each candidate for
being an executable file rather than keying off the release — so no
discovery change is needed for v0.52.
@luohuan19 luohuan19 changed the title chore(toolchain): Update PTOAS to v0.51 and adapt ptoas discovery chore(toolchain): Update PTOAS to v0.52 and adapt ptoas discovery Jul 27, 2026
@luohuan19

Copy link
Copy Markdown
Contributor Author

Hi! This PR will face an issue #2136 that is fixed in #2137 so maybe we can wait for 2137 first?
yeah sure~!

@georgebisbas

Copy link
Copy Markdown
Contributor

Hi! This PR will face an issue #2136 that is fixed in #2137 so maybe we can wait for 2137 first?
yeah sure~!

feel free to continue with yours. My comment was obsolete since this PR was re-purposed

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants