Implement fallback for unimplemented Numba RandomVariables (#1245)
Description
This PR updates the perform method in pytensor/tensor/random/op.py to gracefully handle unimplemented Numba RandomVariables by falling back to object mode. The changes include:
Fallback Mechanism: When a RandomVariable is not implemented in Numba, the code now falls back instead of raising a low-level error.
Improved Size Validation: A helper function _get_value (using get_underlying_scalar_constant_value) is introduced to evaluate symbolic constants in the size parameter. The validation now uses broadcasting rules (via zip_longest) to check that the provided size is compatible with the expected batch dimensions. If not, a ValueError is raised with the message: "Size length is incompatible with batched dimensions."
Known Issues: Two tests—test_RandomVariable_bcast_specify_shape and parts of test_RandomVariable_bcast—still fail due to output shape inference (e.g., the first dimension remains None instead of being concrete). This appears to be a separate type inference issue and is not directly related to the fallback mechanism. I plan to address this in a subsequent PR.
Related Issue
- [ ] Closes #
- [ ] Related to #
Checklist
- [ ] Checked that the pre-commit linting/style checks pass
- [ ] Included tests that prove the fix is effective or that the new feature works
- [ ] Added necessary documentation (docstrings and/or example notebooks)
- [ ] If you are a pro: each commit corresponds to a relevant logical change
Type of change
- [ ] New feature / enhancement
- [ ] Bug fix
- [ ] Documentation
- [ ] Maintenance
- [ ] Other (please specify):
📚 Documentation preview 📚: https://pytensor--1269.org.readthedocs.build/en/1269/