to_edge_transform_and_lower ignores some ops_to_not_decompose requests: multi-output ops, and non-core ops without a decomposition
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 66/100
Piste de recherche
Les deux chemins de préservation se trouvent dans exir/program/_program.py : commencez à _remove_invalid_ops_for_not_decompose (~L1089) pour la vérification d’aliasing, puis lisez la branche check_op_support=None qui consulte la table de décomposition par défaut (~L1205). Exécutez d’abord le reproducer du corps de l’issue pour confirmer que aminmax est divisé et que sort.stable déclenche SpecViolationError, puis appliquez les deux correctifs et réexécutez-le afin que le partitionneur voie aten.aminmax.default et aten.sort.stable. Terminé signifie que les deux cas atteignent le partitionneur et que les tests de lowering exir existants passent toujours.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- Python
- Étoiles
- 5.2k
- Forks
- 1.3k
- Merge moyen
- 1 j 14 h
- PR mergées (30 j)
- 678
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de pytorch/executorch
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_normPeut-être pris @psiddh l’a pris il y a 14 jours. Ouvertebug module: qnn partner: qualcomm
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
pytorch/executorch#24434 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement triaged
Difficulté 2/5 Une demi-journée Accessibilité débutants 68/100
pytorch/executorch#21640 ·
Les mainteneurs répondent en général sous 1 jour
-
[MLX] Any empty output fails at runtime with "write_output: arr.data<void>() is null after wait()"Peut-être pris @galiliya l’a pris aujourd’hui. Ouvertegood first issue module: mlx
pytorch/executorch#25606 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Reminder to update MLX pin to release tagPeut-être pris @mergennachin l’a pris aujourd’hui. Ouverte
pytorch/executorch#25602 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
[MLX] repeat_interleave without `dim` does not flatten the input and fails at runtimePeut-être pris @vineetha00 l’a pris il y a 1 jour. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
pytorch/executorch#25523 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de pytorch/executorch
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
[Maintainer] task area:visualizer
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
RailtownAI/railtracks#1824 ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
apache/datafusion#27688 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
heasarc/heasarc-tutorials#317 ·
-
bug good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
mloda-ai/mloda-registry#1664 ·
Les mainteneurs répondent en général sous 1 jour