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

Autograph automatic conversion of in-place operator-based array updates #1143

Merged
merged 19 commits into from
Sep 20, 2024

Conversation

mehrdad2m
Copy link
Contributor

@mehrdad2m mehrdad2m commented Sep 19, 2024

Context:

#717 added support for converting in-place array updates (arr[i] = x) into the equivalent JAX traceable code (arr.at[i].set(x)). This PR extends that support to operator assignment array updates.

Description of the Change:

  • Add new Autograph converter to map AugAssign ast nodes assigning to a single index or a slice subscript to calls to update_item_with_op
  • Implement update_item_with_op method that map to the corresponding jax.numpy.ndarray.at equivalent methods for JAX arrays and the normal Python operator assignment otherwise
  • Overload transform_ast in CatalystTransformer to invoke the new converter

Benefits: We can use arr[i] += x instead of arr.at[i].add(x).

Possible Drawbacks: It would be cleaner to have the new converter live in the DiastaticMalt project.

Related GitHub Issues: #757

Based on the solution presented in this PR: #769
Note that this PR was originally implemented externally by #769. This PR aims to revisit that PR.

[sc-60318]

@mehrdad2m mehrdad2m marked this pull request as ready for review September 19, 2024 18:26
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.89%. Comparing base (5cf6bd4) to head (5e50872).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1143      +/-   ##
==========================================
+ Coverage   97.87%   97.89%   +0.01%     
==========================================
  Files          75       76       +1     
  Lines       10801    10858      +57     
  Branches     1268     1281      +13     
==========================================
+ Hits        10572    10629      +57     
  Misses        179      179              
  Partials       50       50              

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

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
frontend/catalyst/autograph/operator_update.py Outdated Show resolved Hide resolved
frontend/catalyst/jit.py Show resolved Hide resolved
1. simplified the ag_primitives to only have a update_item_with_op which dispatches to the correct arithmatic operation.
2. Added support for updating a slice using assignment operators
3. Reflected the changes to the documentation
4. Added a test for slice update
5. Improved existing tests to reduce the calls to qjit.
6. Addressed some minor review comments
doc/dev/autograph.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@rauletorresc rauletorresc left a comment

Choose a reason for hiding this comment

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

Apart from the code coverage warnings, LGTM

frontend/catalyst/jit.py Outdated Show resolved Hide resolved
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.

👍

doc/releases/changelog-dev.md Show resolved Hide resolved
@mehrdad2m mehrdad2m merged commit 621c027 into main Sep 20, 2024
43 checks passed
@mehrdad2m mehrdad2m deleted the ag-op-support-finalize branch September 20, 2024 16:27
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.

5 participants