Skip to content

feat(language): deprecate pl.auto_chunk and remove legacy pl.at(optimization=, split=) kwargs#1504

Open
lyfne123 wants to merge 2 commits into
hw-native-sys:mainfrom
lyfne123:feat-remove-legacy-pl-at-kwargs
Open

feat(language): deprecate pl.auto_chunk and remove legacy pl.at(optimization=, split=) kwargs#1504
lyfne123 wants to merge 2 commits into
hw-native-sys:mainfrom
lyfne123:feat-remove-legacy-pl-at-kwargs

Conversation

@lyfne123
Copy link
Copy Markdown
Collaborator

Summary

  • Emit a DeprecationWarning at parse time whenever pl.auto_chunk appears in pl.at(optimizations=[...]). AutoInCore semantics will be derived implicitly in a follow-up; this gives users a heads-up that the explicit entry is going away.

  • Delete the older deprecated surface that was already pointing users at pl.auto_chunk:

    • pl.chunked_loop_optimizer sentinel + _ChunkedLoopOptimizer{,Call} types
    • pl.at(..., optimization=) kwarg
    • pl.at(..., split=) kwarg

    Replacement is the existing pl.at(..., optimizations=[pl.auto_chunk, pl.split(MODE)]). Removing the legacy surface resolves the awkward situation where the old DeprecationWarning was recommending migration to a now-deprecated form.

Layers updated

  • python/pypto/language/dsl_api.py — drop the chunked-loop-optimizer sentinel types; strip optimization= / split= from at() / AtContext.
  • python/pypto/language/__init__.py — drop the chunked_loop_optimizer re-export.
  • python/pypto/language/parser/ast_parser.py — drop the legacy keyword handlers (_handle_at_legacy_optimization_kw, _handle_at_legacy_split_kw, _validate_at_kwarg_combinations), the _parse_chunked_loop_optimizer / _eval_split_mode helpers, and the _AtKwargState fields that backed them. Add the pl.auto_chunk DeprecationWarning inside _parse_optimizations_list.
  • python/pypto/language/optimizations.py — mark AutoChunk and pl.auto_chunk as deprecated in their docstrings.
  • src/ir/transforms/python_printer.cppInCoreScopeStmt / AutoInCoreScopeStmt now print the new optimizations=[pl.split(...)] / optimizations=[pl.auto_chunk, pl.split(...)] form, so round-trip stays valid after the legacy kwargs are gone.
  • docs/{en,zh-cn}/{user,dev}/... — drop migration rows / examples that pointed at the deleted surface.

Test changes

  • Migrate every existing optimization=pl.chunked_loop_optimizer[(split=...)] callsite (UT transforms, codegen, ST runtime/codegen) to optimizations=[pl.auto_chunk[, pl.split(...)]].
  • Update printer-round-trip assertions (test_scope_stmt_hierarchy.py, test_parse_pl_at.py::test_printer_incore_with_split_roundtrip) to expect the new printed form.
  • Drop tests whose entire purpose was exercising the deleted kwargs (test_legacy_*, test_mix_optimizations_with_legacy_* in test_at_optimizations.py; the chunked_loop_optimizer / legacy-split= parser tests in test_parse_pl_at.py).
  • Add test_auto_chunk_emits_deprecation_warning to lock in the new DeprecationWarning, and keep test_new_optimizations_split_emits_no_warning to guarantee pl.split(...)-only usage stays warning-free.

Test plan

  • cmake --build build --parallel succeeds (verified locally on Darwin).
  • tests/ut/ir/parser/test_at_optimizations.py — all retained tests pass; new test_auto_chunk_emits_deprecation_warning triggers.
  • tests/ut/ir/parser/test_parse_pl_at.py::test_printer_incore_with_split_roundtrip — printer emits new optimizations=[pl.split(...)] form.
  • tests/ut/ir/statements/test_scope_stmt_hierarchy.py::test_printer_incore_scope_with_split — same printer assertion.
  • tests/ut/ir/transforms/test_{split_chunked_loops,interchange_chunk_loops,outline_incore_*}.py — migrated callsites still produce expected IR.
  • tests/ut/codegen/test_orchestration_codegen.py — single migrated callsite still passes.
  • tests/st/runtime/{ops,cross_core}/test_{abs,rsqrt,sort,cross_core}.py and tests/st/codegen/torch/test_torch_codegen_cross_core.py — migrated callsites compile and run on device.

Local sandbox can't run pytest end-to-end because pip show pypto shows the editable install points at the main repo (not this worktree) and its bundled .so is stale relative to current main; verified via cmake --build + syntax checks + the pre-commit pyright/ruff hooks. Reviewer should run CI / a fresh editable install.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR removes the deprecated optimization= and split= kwargs from pl.at(...), deletes the chunked_loop_optimizer export, migrates parsing/printer/doc/test usage to optimizations=[...], and emits a DeprecationWarning when pl.auto_chunk is used inside optimizations=[...].

Changes

Deprecated API Removal and Migration

Layer / File(s) Summary
API signature removal and public export cleanup
python/pypto/language/dsl_api.py, python/pypto/language/__init__.py
chunked_loop_optimizer sentinel is removed; AtContext.__init__() and at() drop optimization/split params; at() docstring deprecated-kw text deleted; pypto.language no longer re-exports chunked_loop_optimizer.
Parser keyword dispatch refactoring
python/pypto/language/parser/ast_parser.py
_AtKwargState now tracks only optimizations_kw; _dispatch_at_keyword no longer accepts optimization/split; legacy helpers and kwarg-combination validation removed; parsing now derives auto-chunk and split via optimizations=[...].
Deprecation warnings and optimizations docs
python/pypto/language/optimizations.py, python/pypto/language/parser/ast_parser.py
AutoChunk and auto_chunk docstrings marked deprecated; parser emits DeprecationWarning when pl.auto_chunk appears in optimizations=[...]; parser hints/docs updated to show optimizations=[pl.split(...)] / optimizations=[pl.auto_chunk] forms.
IR printer output for scopes
src/ir/transforms/python_printer.cpp
InCoreScopeStmt printer now renders split as optimizations=[pl.split(...)]; AutoInCoreScopeStmt printer emits optimizations=[auto_chunk, ...] with optional split(...) instead of chunked_loop_optimizer(...).
Documentation cleanup and example updates
docs/en/..., docs/zh-cn/...
Removed deprecated pl.at(..., optimization=...) and pl.at(..., split=...) examples; AutoInCore examples updated to with pl.auto_incore(): ...; only optimizations=[...] form documented.
Test input and assertion updates
tests/st/, tests/ut/
Extensive test migration: inputs and expected printer/parser round-trips updated from optimization=pl.chunked_loop_optimizer / split= to optimizations=[pl.auto_chunk] / optimizations=[pl.auto_chunk, pl.split(...)]; removed deprecated-form tests; added tests asserting pl.auto_chunk deprecation warning.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • hw-native-sys/pypto#1033: Earlier migration to optimizations + pl.split/pl.auto_chunk model; this PR finalizes removal of legacy kwargs.
  • hw-native-sys/pypto#922: Overlapping changes to Python-printer output for InCore/AutoInCore scopes and split mode rendering.
  • hw-native-sys/pypto#905: Introduced the original chunked_loop_optimizer/optimization= surface which this PR removes.

Suggested labels

enhancement

Suggested reviewers

  • Hzfengsy
  • zhangqi-chen

"🐰 I hopped through code and docs with care,
Removed old kwargs from here and there;
Now optimizations list leads the way —
Deprecation bells softly say,
The cleaner API blooms in the air!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.51% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: deprecating pl.auto_chunk and removing legacy pl.at() keyword arguments (optimization and split).
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing what is being deprecated, removed, and replaced across multiple layers and test updates.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the deprecated optimization and split keyword arguments from the pl.at context manager, finalizing the transition to the optimizations=[...] list API. The implementation involves removing the chunked_loop_optimizer sentinel, updating the AST parser to reject legacy arguments, and adjusting the Python printer, documentation, and test suites. Feedback recommends enhancing the deprecation notices for pl.auto_chunk in both docstrings and warning messages to clarify that AutoInCore semantics will be derived implicitly in future releases.

Comment thread python/pypto/language/parser/ast_parser.py Outdated
Comment thread python/pypto/language/parser/ast_parser.py Outdated
Comment thread python/pypto/language/optimizations.py
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 `@python/pypto/language/parser/ast_parser.py`:
- Around line 2709-2713: The DeprecationWarning is emitted unconditionally for
pl.auto_chunk; change it so the warnings.warn call only runs when the parser is
handling the pl.at call path (i.e., when the call/attribute target is the "at"
attribute of the pl module), not when pl.auto_chunk appears elsewhere (for
example inside pl.spmd(optimizations=[pl.auto_chunk])). Concretely, guard the
existing warnings.warn with a test on the AST node representing the
call/attribute (check the target name or attribute == "at" or the fully
qualified call target matches pl.at) so only pl.at triggers the deprecation
warning.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9f300320-a5e0-4e71-925e-27f6182fd02f

📥 Commits

Reviewing files that changed from the base of the PR and between 53d0c27 and d3e8784.

📒 Files selected for processing (22)
  • docs/en/dev/language/00-python_syntax.md
  • docs/en/user/01-language_guide.md
  • docs/zh-cn/dev/language/00-python_syntax.md
  • docs/zh-cn/user/01-language_guide.md
  • python/pypto/language/__init__.py
  • python/pypto/language/dsl_api.py
  • python/pypto/language/optimizations.py
  • python/pypto/language/parser/ast_parser.py
  • src/ir/transforms/python_printer.cpp
  • tests/st/codegen/torch/test_torch_codegen_cross_core.py
  • tests/st/runtime/cross_core/test_cross_core.py
  • tests/st/runtime/ops/test_abs.py
  • tests/st/runtime/ops/test_rsqrt.py
  • tests/st/runtime/ops/test_sort.py
  • tests/ut/codegen/test_orchestration_codegen.py
  • tests/ut/ir/parser/test_at_optimizations.py
  • tests/ut/ir/parser/test_parse_pl_at.py
  • tests/ut/ir/statements/test_scope_stmt_hierarchy.py
  • tests/ut/ir/transforms/test_interchange_chunk_loops.py
  • tests/ut/ir/transforms/test_outline_incore_interleaved_ops.py
  • tests/ut/ir/transforms/test_outline_incore_scopes.py
  • tests/ut/ir/transforms/test_split_chunked_loops.py
💤 Files with no reviewable changes (6)
  • docs/en/dev/language/00-python_syntax.md
  • docs/zh-cn/user/01-language_guide.md
  • docs/zh-cn/dev/language/00-python_syntax.md
  • python/pypto/language/init.py
  • docs/en/user/01-language_guide.md
  • python/pypto/language/dsl_api.py

Comment thread python/pypto/language/parser/ast_parser.py Outdated
lyfne123 added a commit to lyfne123/pypto that referenced this pull request May 25, 2026
- ast_parser.py: scope the pl.auto_chunk DeprecationWarning to owner == "pl.at"
  so it no longer fires for pl.spmd(optimizations=[pl.auto_chunk]) — that path
  already raises a hard ParserSyntaxError a few lines later, so the
  deprecation warning was misleading noise (CodeRabbit).
- ast_parser.py: note in _parse_at_kwargs docstring that pl.auto_chunk is
  deprecated and emits a DeprecationWarning at parse time (gemini).
zhangqi-chen pushed a commit to hw-native-sys/pypto-lib that referenced this pull request May 26, 2026
…k] (#373)

## Summary

[pypto#1504](hw-native-sys/pypto#1504) removed
the deprecated `pl.at(optimization=, split=)` kwargs and the
`chunked_loop_optimizer` sentinel. This migrates every callsite in
pypto-lib to the supported `optimizations=[pl.auto_chunk]` form and
refreshes stale comments.

- 18 files: examples + qwen3/deepseek/kimi/milm kernels
- No `split=` usage existed, so all become a plain
`optimizations=[pl.auto_chunk]`
- `pl.auto_chunk` is itself deprecation-warned but still functional;
kept to keep examples runnable
lyfne123 added 2 commits May 26, 2026 14:14
…ization=, split=) kwargs

`pl.auto_chunk` now emits a `DeprecationWarning` at parse time whenever
it appears inside `pl.at(optimizations=[...])`. AutoInCore semantics will
be derived implicitly in a follow-up; the warning gives users a heads-up
that the explicit entry is going away.

Hand-in-hand with that, drop the older deprecated surface that pointed
users at `pl.auto_chunk` in the first place:

  - `pl.chunked_loop_optimizer` sentinel + `_ChunkedLoopOptimizer{,Call}` types
  - `pl.at(..., optimization=)` kwarg
  - `pl.at(..., split=)` kwarg

The replacement was already in place: write the same intent as
`pl.at(..., optimizations=[pl.auto_chunk, pl.split(MODE)])`. Removing the
old surface also resolves the contradiction where the legacy
DeprecationWarning recommended migrating *to* a now-deprecated form.

Layers updated:

  - `dsl_api.py`: drop the chunked-loop-optimizer sentinel types and
    strip `optimization=` / `split=` from `at()` / `AtContext`.
  - `language/__init__.py`: drop the `chunked_loop_optimizer` re-export.
  - `language/parser/ast_parser.py`: drop the legacy keyword handlers
    (`_handle_at_legacy_optimization_kw`, `_handle_at_legacy_split_kw`,
    `_validate_at_kwarg_combinations`), the `_parse_chunked_loop_optimizer`
    / `_eval_split_mode` helpers, and the `_AtKwargState` fields that
    backed them. Add the `pl.auto_chunk` DeprecationWarning inside
    `_parse_optimizations_list`.
  - `optimizations.py`: mark `AutoChunk` and `pl.auto_chunk` as
    deprecated in their docstrings.
  - `python_printer.cpp`: `InCoreScopeStmt` / `AutoInCoreScopeStmt` now
    print the new `optimizations=[pl.split(...)]` /
    `optimizations=[pl.auto_chunk, pl.split(...)]` form, so round-trip
    stays valid after the legacy kwargs are gone.
  - Docs (`docs/{en,zh-cn}/{user,dev}/...`): drop migration rows /
    examples that pointed at the deleted surface.

Tests:

  - Migrate every existing `optimization=pl.chunked_loop_optimizer[(split=...)]`
    callsite (UT transforms, codegen, ST runtime/codegen) to
    `optimizations=[pl.auto_chunk[, pl.split(...)]]`.
  - Update printer-round-trip assertions (`test_scope_stmt_hierarchy.py`,
    `test_parse_pl_at.py::test_printer_incore_with_split_roundtrip`) to
    expect the new printed form.
  - Drop tests whose entire purpose was exercising the deleted kwargs
    (`test_legacy_*`, `test_mix_optimizations_with_legacy_*` in
    `test_at_optimizations.py`; the `chunked_loop_optimizer` /
    legacy-`split=` parser tests in `test_parse_pl_at.py`).
  - Add `test_auto_chunk_emits_deprecation_warning` to lock in the new
    DeprecationWarning, and keep `test_new_optimizations_split_emits_no_warning`
    to guarantee `pl.split(...)`-only usage stays warning-free.
- ast_parser.py: scope the pl.auto_chunk DeprecationWarning to owner == "pl.at"
  so it no longer fires for pl.spmd(optimizations=[pl.auto_chunk]) — that path
  already raises a hard ParserSyntaxError a few lines later, so the
  deprecation warning was misleading noise (CodeRabbit).
- ast_parser.py: note in _parse_at_kwargs docstring that pl.auto_chunk is
  deprecated and emits a DeprecationWarning at parse time (gemini).
@lyfne123 lyfne123 force-pushed the feat-remove-legacy-pl-at-kwargs branch from 4fba2fb to 2af1302 Compare May 26, 2026 06:14
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.

1 participant