Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tracr/compiler/basis_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def compute_value_set(sop: rasp.SOp) -> Set[rasp.Value]:
res = errors.ignoring_arithmetic_errors(sop.f)(x)
if res is not None:
out.add(res)
if rasp.is_numerical(sop) and (not all(x >= 0 for x in out)):
raise ValueError(f"Map does not support negative outputs due to the ReLU activation\noutputs: {out}\nsop: {sop}")
return out
elif isinstance(sop, rasp.SequenceMap):
f_ignore_error = errors.ignoring_arithmetic_errors(sop.f)
Expand Down
12 changes: 12 additions & 0 deletions tracr/compiler/validating.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def evaluate(
)
)

elif isinstance(expr, rasp.Map):
if rasp.is_numerical(expr) and (not all(x >= 0 for x in out)):
self.unsupported_exprs.append(
TracrUnsupportedExpr(
expr=expr,
reason=(
"Map only supports positive outputs due to the ReLU activation"
f" got {set(out)}."
),
)
)

return out


Expand Down