You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
Checking the validity of parameters is crucial many operators, especially in distribution related Ops. (see references for the implementations of torch and tensorflow)
I implement an operator called npx.constraint_check, which takes a boolean tensor and an error message as input and then checks if all the elements are true, if not, raises exception with given message. It will return a scalar tensor array(True) if none of the elements is false.
However, this Op fails in symbolic mode, as the output of this Op is neither returned to users nor used as the input for other Ops, causing the engine to completely ignore the check Op. In short, exception is not raised.
Description
Checking the validity of parameters is crucial many operators, especially in distribution related Ops. (see references for the implementations of torch and tensorflow)
I implement an operator called
npx.constraint_check
, which takes a boolean tensor and an error message as input and then checks if all the elements are true, if not, raises exception with given message. It will return a scalar tensorarray(True)
if none of the elements is false.However, this Op fails in symbolic mode, as the output of this Op is neither returned to users nor used as the input for other Ops, causing the engine to completely ignore the check Op. In short, exception is not raised.
@leezu provides a workaround like this:
This approach works well, exception got thrown out as expected.
However, this method is not convenient when the
constraint_check
is buried in function called inside the hybrid_forward, e.g:In such case, it becomes quite difficult to manually turn the
flag
tensor into a return value.Another solution could be the
cond
op in control flow, which unfortunately, seems to be out of maintenance.I believe, the simplest way is to have some kinds of mechanism that force MXNet to evaluate a particular OP.
I'm open to other solutions . (It would be great to implement this feature using only the existing infrastructure)
References
The text was updated successfully, but these errors were encountered: