Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Use custom lowering rules #1152

Conversation

erick-xanadu
Copy link
Contributor

@erick-xanadu erick-xanadu commented Sep 24, 2024

Context: Using mlir.register_lowering will modify the global variable _lowerings or platform_specific_lowerings. To avoid this, JAX provides the LoweringParameters structure to pass custom lowering rules. When lowering rules are passed using LoweringParameters, these global variables will not be rewritten.

Description of the Change: Use LoweringParameters instead of register_lowering

Benefits: Avoid rewriting global data structures from JAX.

Possible Drawbacks: None.

Related GitHub Issues:

@erick-xanadu erick-xanadu force-pushed the eochoa/2024-09-24/use-custom-lowering-rules-instead-of-modifying-mlir branch from 2dff6d1 to 584c15d Compare September 24, 2024 14:57
@erick-xanadu erick-xanadu marked this pull request as draft September 24, 2024 15:12
@erick-xanadu erick-xanadu marked this pull request as ready for review September 24, 2024 18:22
Copy link
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Thanks for improving the code base.

There is an additional registration we perform for types, not sure if those have an equivalent or not.

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
frontend/catalyst/jax_primitives.py Show resolved Hide resolved
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.86%. Comparing base (4524773) to head (4f023fc).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1152      +/-   ##
==========================================
- Coverage   97.87%   97.86%   -0.01%     
==========================================
  Files          76       76              
  Lines       10850    10810      -40     
  Branches     1283     1281       -2     
==========================================
- Hits        10619    10579      -40     
  Misses        179      179              
  Partials       52       52              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Co-authored-by: David Ittah <dime10@users.noreply.github.com>
@erick-xanadu
Copy link
Contributor Author

There is an additional registration we perform for types, not sure if those have an equivalent or not.

Not yet, but I'll create an issue in JAX and maybe it will get some traction?

frontend/catalyst/jax_primitives.py Show resolved Hide resolved
frontend/catalyst/jax_extras/lowering.py Outdated Show resolved Hide resolved
erick-xanadu and others added 2 commits September 25, 2024 09:38
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
@erick-xanadu erick-xanadu merged commit fe5e6ae into main Sep 25, 2024
43 checks passed
@erick-xanadu erick-xanadu deleted the eochoa/2024-09-24/use-custom-lowering-rules-instead-of-modifying-mlir branch September 25, 2024 14:04
@erick-xanadu erick-xanadu restored the eochoa/2024-09-24/use-custom-lowering-rules-instead-of-modifying-mlir branch September 25, 2024 20:13
rauletorresc pushed a commit that referenced this pull request Oct 10, 2024
**Context:** Using
[`mlir.register_lowering`](https://github.com/jax-ml/jax/blob/ae86ef16c7a03409cb444da3d477b2adb8134e6f/jax/_src/interpreters/mlir.py#L814-L825)
[will modify the global variable `_lowerings` or
`platform_specific_lowerings`](https://github.com/jax-ml/jax/blob/ae86ef16c7a03409cb444da3d477b2adb8134e6f/jax/_src/interpreters/mlir.py#L810-L812).
To avoid this, JAX provides the[
`LoweringParameters`](https://github.com/jax-ml/jax/blob/ae86ef16c7a03409cb444da3d477b2adb8134e6f/jax/_src/interpreters/mlir.py#L630-L649)
structure to pass custom lowering rules. When lowering rules are passed
using [`LoweringParameters`, these global variables will not be
rewritten.](https://github.com/jax-ml/jax/blob/ae86ef16c7a03409cb444da3d477b2adb8134e6f/jax/_src/interpreters/mlir.py#L1745-L1751)

**Description of the Change:** Use LoweringParameters instead of
register_lowering

**Benefits:** Avoid rewriting global data structures from JAX.

**Possible Drawbacks:** None.

**Related GitHub Issues:**

---------

Co-authored-by: David Ittah <dime10@users.noreply.github.com>
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.

2 participants