[Bugfix] Reject contradictory custom-op directives (#49134)

Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
Taneem Ibrahim
2026-07-26 08:42:14 -04:00
committed by GitHub
parent 5559679229
commit 0da6e7f3d6
3 changed files with 59 additions and 11 deletions
+9 -2
View File
@@ -284,7 +284,11 @@ class CustomOp(nn.Module):
enabled = f"+{cls.name}" in custom_ops
disabled = f"-{cls.name}" in custom_ops
assert not (enabled and disabled), f"Cannot enable and disable {cls.name}"
if enabled and disabled:
raise ValueError(
"custom_ops cannot both enable and disable the same operation: "
f"{cls.name}. Remove either the '+' or '-' directive"
)
return (CustomOp.default_on() or enabled) and not disabled
@@ -299,7 +303,10 @@ class CustomOp(nn.Module):
compilation_config = get_cached_compilation_config()
count_none = compilation_config.custom_ops.count("none")
count_all = compilation_config.custom_ops.count("all")
assert count_none + count_all == 1
if count_none + count_all != 1:
raise ValueError(
"custom_ops must contain exactly one base mode: 'all' or 'none'"
)
return not count_none > 0 or count_all > 0