beanmachine icon indicating copy to clipboard operation
beanmachine copied to clipboard

Support numpy arrays as constant operands to stochastic operators

Open ericlippert opened this issue 1 year ago • 2 comments

Summary: The compiler crashed when given a numpy array as a "constant" operand to a stochastic operator; we now detect this situation and automatically convert the value to a tensor before building a graph node.

While I was at it, I also fixed a couple of long-standing related problems:

  • The error message when using an unsupported operand type in a stochastic operator was terrible; I've fixed that so it is somewhat more clear, though it still could be better. (We could for instance say where the error occurred in the original source code.)

  • When a constant is tensor-valued, we now make a copy of the tensor in the accumulated graph. We hope that models will not mutate tensors in-place, but by making a copy we at least protect ourselves against this scenario.

I have not yet considered the scenario where a numpy array is used as an argument to a random variable; that is likely broken in a similar way. I'll follow up on that in a later diff.

Reviewed By: gafter

Differential Revision: D38089671

ericlippert avatar Jul 26 '22 23:07 ericlippert

This pull request was exported from Phabricator. Differential Revision: D38089671

facebook-github-bot avatar Jul 26 '22 23:07 facebook-github-bot

Hi @ericlippert!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Dec 01 '22 08:12 facebook-github-bot