From 652a6253c10ed45339cd0a242012fcd18e2786dd Mon Sep 17 00:00:00 2001 From: Zonglin Peng Date: Fri, 31 Oct 2025 11:11:49 -0700 Subject: [PATCH 1/5] [Jarvis][Nightly] address zero division in jarvis-nightly-operators-test-aten-div-out-mode https://docs.google.com/spreadsheets/d/12DsKcvPcGgxnZ8shgn6j8PmoOQUfy5GgUg974g1iO18/edit?gid=0#gid=0 Differential Revision: [D85364551](https://our.internmc.facebook.com/intern/diff/D85364551/) [ghstack-poisoned] --- backends/cadence/utils/facto_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backends/cadence/utils/facto_util.py b/backends/cadence/utils/facto_util.py index e49cf412c19..518018c6d98 100644 --- a/backends/cadence/utils/facto_util.py +++ b/backends/cadence/utils/facto_util.py @@ -373,6 +373,7 @@ def random_size_constraint(deps: object, r: int, d: int) -> int: cp.Dtype.In(lambda deps: [torch.int64, torch.int32, torch.float32]), cp.Value.Ge(lambda deps, dtype, struct: -(2**4)), cp.Value.Le(lambda deps, dtype, struct: 2**4), + cp.Value.Ne(lambda deps, dtype, struct: 0), # Prevent division by zero cp.Rank.Ge(lambda deps: 1), cp.Rank.Eq(lambda deps: deps[0].dim()), cp.Size.Eq(lambda deps, r, d: fn.safe_size(deps[0], d)), From 770cf3d915f68c0ce9f1acbd45198624ee9304c0 Mon Sep 17 00:00:00 2001 From: Zonglin Peng Date: Fri, 31 Oct 2025 11:11:53 -0700 Subject: [PATCH 2/5] [Jarvis][Nightly] address error in jarvis-nightly-operators-test-aten-leaky-relu-out https://docs.google.com/spreadsheets/d/12DsKcvPcGgxnZ8shgn6j8PmoOQUfy5GgUg974g1iO18/edit?gid=0#gid=0 Differential Revision: [D85364558](https://our.internmc.facebook.com/intern/diff/D85364558/) [ghstack-poisoned] --- backends/cadence/utils/facto_util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backends/cadence/utils/facto_util.py b/backends/cadence/utils/facto_util.py index 518018c6d98..e8d48007516 100644 --- a/backends/cadence/utils/facto_util.py +++ b/backends/cadence/utils/facto_util.py @@ -390,6 +390,12 @@ def random_size_constraint(deps: object, r: int, d: int) -> int: cp.Value.Le(lambda deps, dtype, struct: 2**2), cp.Size.Le(lambda deps, r, d: 2**3), ] + case "leaky_relu.default": + tensor_constraints.extend( + [ + cp.Dtype.In(lambda deps: [torch.float32]), + ] + ) case "_softmax.default": tensor_constraints.extend( [ @@ -442,6 +448,14 @@ def facto_testcase_gen( # noqa: C901 spec.inspec[index].constraints.extend( [cp.Value.Ge(lambda deps, _: deps[1])] ) + elif in_spec.name == "negative_slope" and op_name == "leaky_relu.default": + # For leaky_relu, negative_slope should be in typical range (0, 1] + spec.inspec[index].constraints.extend( + [ + cp.Value.Gt(lambda deps, dtype: 0), + cp.Value.Le(lambda deps, dtype: 1.0), + ] + ) else: spec.inspec[index].constraints.extend( [ From 961a1873ad88d886964627583a70bc1899e7489c Mon Sep 17 00:00:00 2001 From: Zonglin Peng Date: Fri, 31 Oct 2025 11:11:57 -0700 Subject: [PATCH 3/5] [Jarvis][Nightly] address zero division jarvis-nightly-operators-test-aten-div-out https://docs.google.com/spreadsheets/d/12DsKcvPcGgxnZ8shgn6j8PmoOQUfy5GgUg974g1iO18/edit?gid=0#gid=0 Differential Revision: [D85364549](https://our.internmc.facebook.com/intern/diff/D85364549/) [ghstack-poisoned] --- backends/cadence/utils/facto_util.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/backends/cadence/utils/facto_util.py b/backends/cadence/utils/facto_util.py index e8d48007516..39cf0474fba 100644 --- a/backends/cadence/utils/facto_util.py +++ b/backends/cadence/utils/facto_util.py @@ -344,14 +344,23 @@ def random_size_constraint(deps: object, r: int, d: int) -> int: ] ) case "div.Tensor": - tensor_constraints.extend( - [ - cp.Value.Ne(lambda deps, dtype, struct: 0), - cp.Value.Le(lambda deps, dtype, struct: 2**3), - cp.Size.Le(lambda deps, r, d: 2**3), - cp.Rank.Le(lambda deps: 2**2), - ] - ) + if index == 1: # Only apply zero-prevention to divisor + tensor_constraints.extend( + [ + cp.Value.Ne(lambda deps, dtype, struct: 0), # Prevent division by zero + cp.Value.Le(lambda deps, dtype, struct: 2**3), + cp.Size.Le(lambda deps, r, d: 2**3), + cp.Rank.Le(lambda deps: 2**2), + ] + ) + else: + tensor_constraints.extend( + [ + cp.Value.Le(lambda deps, dtype, struct: 2**3), + cp.Size.Le(lambda deps, r, d: 2**3), + cp.Rank.Le(lambda deps: 2**2), + ] + ) case "pow.Tensor_Scalar": tensor_constraints.extend( [ From e977f0fb666f18589702564665d3c8c21d42aa6a Mon Sep 17 00:00:00 2001 From: Zonglin Peng Date: Sat, 1 Nov 2025 07:44:49 -0700 Subject: [PATCH 4/5] Update base for Update on "[Jarvis][Nightly] address error jarvis-nightly-operators-test-aten-permute-copy-out" https://docs.google.com/spreadsheets/d/12DsKcvPcGgxnZ8shgn6j8PmoOQUfy5GgUg974g1iO18/edit?gid=0#gid=0 Differential Revision: [D85364547](https://our.internmc.facebook.com/intern/diff/D85364547/) [ghstack-poisoned] --- backends/cadence/utils/facto_util.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backends/cadence/utils/facto_util.py b/backends/cadence/utils/facto_util.py index 39cf0474fba..4dbc76e0e47 100644 --- a/backends/cadence/utils/facto_util.py +++ b/backends/cadence/utils/facto_util.py @@ -347,7 +347,9 @@ def random_size_constraint(deps: object, r: int, d: int) -> int: if index == 1: # Only apply zero-prevention to divisor tensor_constraints.extend( [ - cp.Value.Ne(lambda deps, dtype, struct: 0), # Prevent division by zero + cp.Value.Ne( + lambda deps, dtype, struct: 0 + ), # Prevent division by zero cp.Value.Le(lambda deps, dtype, struct: 2**3), cp.Size.Le(lambda deps, r, d: 2**3), cp.Rank.Le(lambda deps: 2**2), @@ -382,7 +384,9 @@ def random_size_constraint(deps: object, r: int, d: int) -> int: cp.Dtype.In(lambda deps: [torch.int64, torch.int32, torch.float32]), cp.Value.Ge(lambda deps, dtype, struct: -(2**4)), cp.Value.Le(lambda deps, dtype, struct: 2**4), - cp.Value.Ne(lambda deps, dtype, struct: 0), # Prevent division by zero + cp.Value.Ne( + lambda deps, dtype, struct: 0 + ), # Prevent division by zero cp.Rank.Ge(lambda deps: 1), cp.Rank.Eq(lambda deps: deps[0].dim()), cp.Size.Eq(lambda deps, r, d: fn.safe_size(deps[0], d)), From dff8a59351dd974ebfa0d6778bee9d5f976696ad Mon Sep 17 00:00:00 2001 From: JP <46308822+zonglinpeng@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:43:01 -0800 Subject: [PATCH 5/5] [Jarvis][Nightly] address error jarvis-nightly-operators-test-aten-permute-copy-out Differential Revision: D85364547 Pull Request resolved: https://github.com/pytorch/executorch/pull/15497 --- backends/cadence/utils/facto_util.py | 60 +++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/backends/cadence/utils/facto_util.py b/backends/cadence/utils/facto_util.py index 4dbc76e0e47..fab7a28e760 100644 --- a/backends/cadence/utils/facto_util.py +++ b/backends/cadence/utils/facto_util.py @@ -15,6 +15,7 @@ import torch from facto.inputgen.argtuple.gen import ArgumentTupleGenerator from facto.inputgen.specs.model import ConstraintProducer as cp +from facto.inputgen.utils.random_manager import seeded_random_manager as rm from facto.inputgen.variable.type import ScalarDtype from facto.specdb.db import SpecDictDB @@ -26,6 +27,33 @@ _shape_cache: dict[str, list[int]] = {} +def _positive_valid_dim_list(tensor: torch.Tensor, length: int) -> set[tuple[int, ...]]: + """ + Generate valid permutations using only positive dimension indices. + This is required for Cadence/Xtensa kernels that don't support negative indexing. + + Args: + tensor: Input tensor to generate permutations for + length: Number of dimensions in the permutation (must equal tensor.dim()) + + Returns: + Set of valid permutation tuples containing only positive indices [0, rank-1] + """ + if length > tensor.dim(): + return set() + + n = tensor.dim() + pool = list(range(n)) + + # Generate multiple valid permutations (only positive indices) + permutations: set[tuple[int, ...]] = set() + for _ in range(3): # Generate 3 different permutations for diversity + perm = tuple(rm.get_random().sample(pool, length)) + permutations.add(perm) + + return permutations + + def apply_tensor_contraints(op_name: str, index: int) -> list[object]: # Constraint to limit tensor size to < 4000 bytes with fully randomized shapes import random @@ -493,12 +521,32 @@ def facto_testcase_gen( # noqa: C901 apply_tensor_contraints(op_name, index) ) elif in_spec.type.is_dim_list(): - spec.inspec[index].constraints.extend( - [ - cp.Length.Ge(lambda deps: 1), - cp.Optional.Eq(lambda deps: False), - ] - ) + # Special handling for permute_copy.default to ensure valid permutation + if op_name == "permute_copy.default": + spec.inspec[index].constraints.extend( + [ + cp.Length.Ge(lambda deps: 1), + cp.Length.Eq( + lambda deps: deps[0].dim() + ), # Must be a complete permutation + cp.Optional.Eq(lambda deps: False), + # Generate valid permutations using only positive indices + # Cadence/Xtensa hardware kernels do not support negative dimension indices + cp.Value.Gen( + lambda deps, length: ( + _positive_valid_dim_list(deps[0], length), + fn.invalid_dim_list(deps[0], length), + ) + ), + ] + ) + else: + spec.inspec[index].constraints.extend( + [ + cp.Length.Ge(lambda deps: 1), + cp.Optional.Eq(lambda deps: False), + ] + ) elif in_spec.type.is_bool(): spec.inspec[index].constraints.extend( [