to_edge_transform_and_lower ignores some ops_to_not_decompose requests: multi-output ops, and non-core ops without a decomposition
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 66/100
調査の方向性
両方の preservation パスは exir/program/_program.py にあります。エイリアシングチェックのために _remove_invalid_ops_for_not_decompose (~L1089) から始め、次にデフォルトの分解テーブルを参照する check_op_support=None 分岐 (~L1205) を読んでください。まず issue 本文の再現プログラムを実行して、aminmax が分割され、sort.stable が SpecViolationError を発生させることを確認し、その後 2 つの修正を適用して再実行し、partitioner が aten.aminmax.default と aten.sort.stable を認識できるようにしてください。完了とは、両方のケースが partitioner に到達し、既存の exir lowering テストが引き続き成功することを意味します。
索引モデルが issue の本文から書いたものです。
説明
to_edge_transform_and_lower ignores some of the ops a partitioner asks to keep through ops_to_not_decompose. There are two cases, one on each preservation path in exir/program/_program.py.
1. With check_op_support, ops with more than one output are treated as aliasing. _remove_invalid_ops_for_not_decompose drops an op when native_schema.aliased_return_names() != [None]. For an op with two outputs that don't alias, such as aminmax or sort, that list is [None, None]. The request is dropped with "This request is ignored because it aliases output", and the op is decomposed before the partitioner sees it.
2. With check_op_support=None, a non-core op that has no decomposition fails the Core ATen check. On this path a requested op is only added to the preserved set if it appears in the default decomposition table. aten.sort.stable has no decomposition, so it is never added, and lowering fails with SpecViolationError: Operator torch._ops.aten.sort.stable is not in Core ATen opset before the partitioner runs. This is why torch.sort(x, stable=True) can't be delegated to MLX: #25364 registers aten.sort.stable, and its tests fail at export. torch.argsort(x, stable=True) works, because argsort.stable is in the table.
Repro with a partitioner that records the ops it is shown:
import torch
from executorch.exir import to_edge_transform_and_lower
from executorch.exir.backend.partitioner import (
DelegationSpec,
Partitioner,
PartitionResult,
)
class RecordingPartitioner(Partitioner):
"""Requests preservation of `op` and records the ops it is shown."""
def __init__(self, op, check_op_support):
super().__init__()
self.delegation_spec = DelegationSpec("NoBackend", [])
self.op = op
self.check_op_support = check_op_support
self.seen = None
def ops_to_not_decompose(self, ep):
return [self.op], self.check_op_support
def partition(self, ep):
self.seen = sorted(
{
n.target.__name__
for n in ep.graph.nodes
if n.op == "call_function" and hasattr(n.target, "__name__")
}
)
return PartitionResult(tagged_exported_program=ep, partition_tags={})
class Aminmax(torch.nn.Module):
def forward(self, x):
return torch.aminmax(x, dim=-1)
class StableSort(torch.nn.Module):
def forward(self, x):
return torch.sort(x, stable=True)
cases = [
# check_op_support given -> EDGE_DO_NOT_DECOMP path
("aminmax, check_op_support given", Aminmax(), torch.ops.aten.aminmax.default, lambda n: True),
# check_op_support None -> decomposition-table path
("sort.stable, check_op_support=None", StableSort(), torch.ops.aten.sort.stable, None),
]
for name, model, op, check in cases:
part = RecordingPartitioner(op, check)
ep = torch.export.export(model, (torch.randn(3, 4),))
try:
to_edge_transform_and_lower(ep, partitioner=[part])
error = ""
except Exception as e:
error = f"; then {type(e).__name__}: {str(e).strip().splitlines()[0][:80]}"
print(f"{name}: partitioner saw {part.seen}{error}")
On main:
aminmax, check_op_support given: partitioner saw ['aten.amax.default', 'aten.amin.default']
sort.stable, check_op_support=None: partitioner saw None; then SpecViolationError: Operator torch._ops.aten.sort.stable is not in Core ATen opset ...
These two changes fix both cases locally:
- if native_schema.aliased_return_names() != [None]:
+ if any(name is not None for name in native_schema.aliased_return_names()):
for op in curr_ops_no_decomp:
- if table.pop(op, None) is not None:
+ if (
+ table.pop(op, None) is not None
+ or torch.Tag.core not in op.tags
+ ):
ops_needing_preservation.append(op)
With them, the partitioner sees aten.aminmax.default and aten.sort.stable. The repro then stops at "was not decomposed or delegated", which is expected because it delegates nothing. With the second change and aten.sort.stable registered in the MLX sort handler, torch.sort(x, stable=True) is fully delegated to MLX and matches eager, including the order of equal values.
Environment: main at ec5937f865 (exir/program/_program.py is identical to the tree I ran), Apple M2 Ultra, macOS 27.2, Python 3.13, PyTorch 2.14.0.
Found while reviewing #25364, and verified with help from Claude Code.
cc @JacobSzwejbka @angelayi
- 主要言語
- Python
- スター
- 5.2k
- フォーク
- 1.3k
- 平均マージ
- 1日 14時間
- マージ済み PR(30日)
- 678
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytorch/executorch のほかの issue
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_norm対応中かも @psiddh が 14 日前に担当しました。 オープンbug module: qnn partner: qualcomm
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
pytorch/executorch#24434 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
enhancement triaged
難易度 2/5 半日 初心者へのやさしさ 68/100
pytorch/executorch#21640 ·
メンテナーはふだん 1 日以内に返信
-
[MLX] Any empty output fails at runtime with "write_output: arr.data<void>() is null after wait()"対応中かも @galiliya が今日担当しました。 オープンgood first issue module: mlx
pytorch/executorch#25606 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Reminder to update MLX pin to release tag対応中かも @mergennachin が今日担当しました。 オープン
pytorch/executorch#25602 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[MLX] repeat_interleave without `dim` does not flatten the input and fails at runtime対応中かも @vineetha00 が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
pytorch/executorch#25523 ·
メンテナーはふだん 1 日以内に返信
pytorch/executorch の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[Maintainer] task area:visualizer
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
RailtownAI/railtracks#1824 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
apache/datafusion#27688 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
heasarc/heasarc-tutorials#317 ·
-
bug good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
mloda-ai/mloda-registry#1664 ·
メンテナーはふだん 1 日以内に返信