Skip to content

Conversation

SwarnimShekhar
Copy link

@SwarnimShekhar SwarnimShekhar commented Mar 5, 2025

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

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1269.org.readthedocs.build/en/1269/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant