Skip to content

Commit 30be5ff

Browse files
author
Zonglin Peng
committed
[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]
1 parent 961a187 commit 30be5ff

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

backends/cadence/utils/facto_util.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import torch
1616
from facto.inputgen.argtuple.gen import ArgumentTupleGenerator
1717
from facto.inputgen.specs.model import ConstraintProducer as cp
18+
from facto.inputgen.utils.random_manager import seeded_random_manager as rm
1819
from facto.inputgen.variable.type import ScalarDtype
1920
from facto.specdb.db import SpecDictDB
2021

@@ -26,6 +27,33 @@
2627
_shape_cache: dict[str, list[int]] = {}
2728

2829

30+
def _positive_valid_dim_list(tensor: torch.Tensor, length: int) -> set[tuple[int, ...]]:
31+
"""
32+
Generate valid permutations using only positive dimension indices.
33+
This is required for Cadence/Xtensa kernels that don't support negative indexing.
34+
35+
Args:
36+
tensor: Input tensor to generate permutations for
37+
length: Number of dimensions in the permutation (must equal tensor.dim())
38+
39+
Returns:
40+
Set of valid permutation tuples containing only positive indices [0, rank-1]
41+
"""
42+
if length > tensor.dim():
43+
return set()
44+
45+
n = tensor.dim()
46+
pool = list(range(n))
47+
48+
# Generate multiple valid permutations (only positive indices)
49+
permutations: set[tuple[int, ...]] = set()
50+
for _ in range(3): # Generate 3 different permutations for diversity
51+
perm = tuple(rm.get_random().sample(pool, length))
52+
permutations.add(perm)
53+
54+
return permutations
55+
56+
2957
def apply_tensor_contraints(op_name: str, index: int) -> list[object]:
3058
# Constraint to limit tensor size to < 4000 bytes with fully randomized shapes
3159
import random
@@ -489,12 +517,30 @@ def facto_testcase_gen( # noqa: C901
489517
apply_tensor_contraints(op_name, index)
490518
)
491519
elif in_spec.type.is_dim_list():
492-
spec.inspec[index].constraints.extend(
493-
[
494-
cp.Length.Ge(lambda deps: 1),
495-
cp.Optional.Eq(lambda deps: False),
496-
]
497-
)
520+
# Special handling for permute_copy.default to ensure valid permutation
521+
if op_name == "permute_copy.default":
522+
spec.inspec[index].constraints.extend(
523+
[
524+
cp.Length.Ge(lambda deps: 1),
525+
cp.Length.Eq(lambda deps: deps[0].dim()), # Must be a complete permutation
526+
cp.Optional.Eq(lambda deps: False),
527+
# Generate valid permutations using only positive indices
528+
# Cadence/Xtensa hardware kernels do not support negative dimension indices
529+
cp.Value.Gen(
530+
lambda deps, length: (
531+
_positive_valid_dim_list(deps[0], length),
532+
fn.invalid_dim_list(deps[0], length),
533+
)
534+
),
535+
]
536+
)
537+
else:
538+
spec.inspec[index].constraints.extend(
539+
[
540+
cp.Length.Ge(lambda deps: 1),
541+
cp.Optional.Eq(lambda deps: False),
542+
]
543+
)
498544
elif in_spec.type.is_bool():
499545
spec.inspec[index].constraints.extend(
500546
[

0 commit comments

Comments
 (0)