[Bugfix] Reject contradictory custom-op directives (#49134)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user