Skip to content

Commit 806d4cc

Browse files
author
Zonglin Peng
committed
Update base for Update on "jarvis-nightly-operators-test-aten-clamp-out"
Differential Revision: [D85364552](https://our.internmc.facebook.com/intern/diff/D85364552/) [ghstack-poisoned]
1 parent 7003c5b commit 806d4cc

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

backends/cadence/utils/facto_util.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ def _positive_valid_dim_list(tensor: torch.Tensor, length: int) -> set[tuple[int
3131
"""
3232
Generate valid permutations using only positive dimension indices.
3333
This is required for Cadence/Xtensa kernels that don't support negative indexing.
34-
34+
3535
Args:
3636
tensor: Input tensor to generate permutations for
3737
length: Number of dimensions in the permutation (must equal tensor.dim())
38-
38+
3939
Returns:
4040
Set of valid permutation tuples containing only positive indices [0, rank-1]
4141
"""
4242
if length > tensor.dim():
4343
return set()
44-
44+
4545
n = tensor.dim()
4646
pool = list(range(n))
47-
47+
4848
# Generate multiple valid permutations (only positive indices)
4949
permutations: set[tuple[int, ...]] = set()
5050
for _ in range(3): # Generate 3 different permutations for diversity
5151
perm = tuple(rm.get_random().sample(pool, length))
5252
permutations.add(perm)
53-
53+
5454
return permutations
5555

5656

@@ -202,7 +202,9 @@ def random_size_constraint(deps: object, r: int, d: int) -> int:
202202
cp.Value.Le(lambda deps, dtype, struct: 2**4),
203203
cp.Rank.Ge(lambda deps: 1),
204204
cp.Size.Ge(lambda deps, r, d: 1),
205-
cp.Size.In(lambda deps, r, d: fn.broadcast_with(deps[0].shape, r, d)),
205+
cp.Size.In(
206+
lambda deps, r, d: fn.broadcast_with(deps[0].shape, r, d)
207+
),
206208
max_size_constraint,
207209
]
208210
else: # input tensor(b)
@@ -213,7 +215,11 @@ def random_size_constraint(deps: object, r: int, d: int) -> int:
213215
cp.Value.Le(lambda deps, dtype, struct: 2**4),
214216
cp.Rank.Ge(lambda deps: 1),
215217
cp.Size.Ge(lambda deps, r, d: 1),
216-
cp.Size.In(lambda deps, r, d: fn.broadcast_with(fn.broadcasted_shape(deps[0].shape, deps[1].shape), r, d)),
218+
cp.Size.In(
219+
lambda deps, r, d: fn.broadcast_with(
220+
fn.broadcasted_shape(deps[0].shape, deps[1].shape), r, d
221+
)
222+
),
217223
max_size_constraint,
218224
]
219225
case "embedding.default":
@@ -362,7 +368,9 @@ def random_size_constraint(deps: object, r: int, d: int) -> int:
362368
if index == 1: # Only apply zero-prevention to divisor
363369
tensor_constraints.extend(
364370
[
365-
cp.Value.Ne(lambda deps, dtype, struct: 0), # Prevent division by zero
371+
cp.Value.Ne(
372+
lambda deps, dtype, struct: 0
373+
), # Prevent division by zero
366374
cp.Value.Le(lambda deps, dtype, struct: 2**3),
367375
cp.Size.Le(lambda deps, r, d: 2**3),
368376
cp.Rank.Le(lambda deps: 2**2),
@@ -397,7 +405,9 @@ def random_size_constraint(deps: object, r: int, d: int) -> int:
397405
cp.Dtype.In(lambda deps: [torch.int64, torch.int32, torch.float32]),
398406
cp.Value.Ge(lambda deps, dtype, struct: -(2**4)),
399407
cp.Value.Le(lambda deps, dtype, struct: 2**4),
400-
cp.Value.Ne(lambda deps, dtype, struct: 0), # Prevent division by zero
408+
cp.Value.Ne(
409+
lambda deps, dtype, struct: 0
410+
), # Prevent division by zero
401411
cp.Rank.Ge(lambda deps: 1),
402412
cp.Rank.Eq(lambda deps: deps[0].dim()),
403413
cp.Size.Eq(lambda deps, r, d: fn.safe_size(deps[0], d)),
@@ -515,7 +525,9 @@ def facto_testcase_gen( # noqa: C901
515525
spec.inspec[index].constraints.extend(
516526
[
517527
cp.Length.Ge(lambda deps: 1),
518-
cp.Length.Eq(lambda deps: deps[0].dim()), # Must be a complete permutation
528+
cp.Length.Eq(
529+
lambda deps: deps[0].dim()
530+
), # Must be a complete permutation
519531
cp.Optional.Eq(lambda deps: False),
520532
# Generate valid permutations using only positive indices
521533
# Cadence/Xtensa hardware kernels do not support negative dimension indices

0 commit comments

Comments
 (0)