From c27deb5dd610118bc4885b24187a43d1ddb8c222 Mon Sep 17 00:00:00 2001 From: Baris Demir Date: Thu, 29 Oct 2026 00:05:01 +0000 Subject: [PATCH 1/2] FACTO: Fix unary op domain constraints Limit generated domains for unary ops with restricted real\ninputs.\n\nConstrain acos and asin to [-1, 1], acosh to [1, inf),\natanh to (-1, 1), sqrt to [0, inf), rsqrt and log ops\nto (0, inf), and log1p to (-1, inf). This keeps FACTO\nfrom generating invalid real-valued cases that show up\nas AoT and export noise. --- facto/specdb/db.py | 86 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 11 deletions(-) diff --git a/facto/specdb/db.py b/facto/specdb/db.py index 93a45cd..80fc89b 100644 --- a/facto/specdb/db.py +++ b/facto/specdb/db.py @@ -6,9 +6,10 @@ import math +import torch + import facto.specdb.function as fn import facto.utils.dtypes as dt -import torch from facto.inputgen.argument.type import ArgType from facto.inputgen.specs.model import ( ConstraintProducer as cp, @@ -705,7 +706,14 @@ Spec( op="acos.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Ge(lambda deps, dtype, struct: -1.0), + cp.Value.Le(lambda deps, dtype, struct: 1.0), + ], + ), ], outspec=[ OutArg(ArgType.Tensor), @@ -714,7 +722,13 @@ Spec( op="acosh.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Ge(lambda deps, dtype, struct: 1.0), + ], + ), ], outspec=[ OutArg(ArgType.Tensor), @@ -1175,7 +1189,14 @@ Spec( op="asin.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Ge(lambda deps, dtype, struct: -1.0), + cp.Value.Le(lambda deps, dtype, struct: 1.0), + ], + ), ], outspec=[ OutArg(ArgType.Tensor), @@ -1231,7 +1252,14 @@ Spec( op="atanh.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Gt(lambda deps, dtype, struct: -1.0), + cp.Value.Lt(lambda deps, dtype, struct: 1.0), + ], + ), ], outspec=[ OutArg(ArgType.Tensor), @@ -2795,7 +2823,13 @@ Spec( op="log.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Gt(lambda deps, dtype, struct: 0.0), + ], + ), ], outspec=[ OutArg( @@ -2810,7 +2844,13 @@ Spec( op="log10.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Gt(lambda deps, dtype, struct: 0.0), + ], + ), ], outspec=[ OutArg( @@ -2825,7 +2865,13 @@ Spec( op="log1p.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Gt(lambda deps, dtype, struct: -1.0), + ], + ), ], outspec=[ OutArg( @@ -2840,7 +2886,13 @@ Spec( op="log2.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Gt(lambda deps, dtype, struct: 0.0), + ], + ), ], outspec=[ OutArg( @@ -4453,7 +4505,13 @@ Spec( op="rsqrt.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Gt(lambda deps, dtype, struct: 0.0), + ], + ), ], outspec=[OutArg(ArgType.Tensor)], ), @@ -5029,7 +5087,13 @@ Spec( op="sqrt.default", # (Tensor self) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + constraints=[ + cp.Value.Ge(lambda deps, dtype, struct: 0.0), + ], + ), ], outspec=[OutArg(ArgType.Tensor)], ), From 385348ffd9c27125eccd2d01b776f7815039b4a0 Mon Sep 17 00:00:00 2001 From: Baris Demir Date: Thu, 29 Oct 2026 01:24:42 +0000 Subject: [PATCH 2/2] FACTO: Add logit and divisor constraints Constrain logit inputs to [0, 1] when eps is None and\nrequire non-zero divisors for div.Tensor_mode with\nrounding_mode, floor_divide.default, and\nremainder.Tensor.\n\nThis reduces invalid generated cases that show up as\nbackend noise in Arm FACTO runs. --- facto/specdb/db.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/facto/specdb/db.py b/facto/specdb/db.py index 80fc89b..677a93e 100644 --- a/facto/specdb/db.py +++ b/facto/specdb/db.py @@ -2097,10 +2097,9 @@ cp.Value.Ne( lambda deps, dtype, struct: ( 0 - if (deps[0].numel() > 0 and math.prod(struct) > 0) + if deps[0].numel() > 0 + and math.prod(struct) > 0 and deps[1] is not None - and torch.promote_types(deps[0].dtype, dtype) - not in dt._floating else None ) ), @@ -2376,10 +2375,7 @@ cp.Value.Ne( lambda deps, dtype, struct: ( 0 - if (deps[0].numel() > 0 and math.prod(struct) > 0) - and torch.promote_types(deps[0].dtype, dtype) - not in dt._floating - else None + if deps[0].numel() > 0 and math.prod(struct) > 0 else None ) ), ], @@ -2965,7 +2961,19 @@ Spec( op="logit.default", # (Tensor self, float? eps=None) -> Tensor inspec=[ - InPosArg(ArgType.Tensor, name="self"), + InPosArg( + ArgType.Tensor, + name="self", + deps=[1], + constraints=[ + cp.Value.Ge( + lambda deps, dtype, struct: 0.0 if deps[0] is None else None + ), + cp.Value.Le( + lambda deps, dtype, struct: 1.0 if deps[0] is None else None + ), + ], + ), InPosArg(ArgType.FloatOpt, name="eps"), ], outspec=[ @@ -4188,10 +4196,7 @@ cp.Value.Ne( lambda deps, dtype, struct: ( 0 - if (deps[0].numel() > 0 and math.prod(struct) > 0) - and torch.promote_types(deps[0].dtype, dtype) - not in dt._floating - else None + if deps[0].numel() > 0 and math.prod(struct) > 0 else None ) ), ],