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

Use grad context for hashing the generated stablehlo program #1604

Merged
merged 4 commits into from
Apr 8, 2025

Conversation

erick-xanadu
Copy link
Contributor

@erick-xanadu erick-xanadu commented Apr 2, 2025

Context: After PR #1562, a single function could have multiple JAXPR representations based on whether it was under a grad context or not. This made the previous hash based on the function id create possible conflicts. To address this, we hashed on the jaxpr string representation. (We cannot hash on the jax object itself since they are unique).

The JAXPR string representation can be very long and hashing over long strings can take a long time.

Description of the Change: Instead of hashing the string representation, add a simple key to denote whether it is inside a grad context or not.

Benefits: Reduced compilation time.

Possible Drawbacks: The cache key is getting more complicated. Maybe the drawbacks outweight the benefits now?

Related GitHub Issues:

[sc-88454]

@erick-xanadu erick-xanadu requested review from mehrdad2m and dime10 April 2, 2025 23:42
Copy link
Contributor

github-actions bot commented Apr 2, 2025

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@erick-xanadu
Copy link
Contributor Author

erick-xanadu commented Apr 2, 2025

I think the proposed solution in the current PR is a bit insufficient. It depends on what influences the contextual decomposition, but it is a good starting point. We can discuss more about this tomorrow :) Like argnums or something similar.

Copy link

codecov bot commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (v0.11.0-rc@efe2fa3). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff              @@
##             v0.11.0-rc    #1604   +/-   ##
=============================================
  Coverage              ?   96.61%           
=============================================
  Files                 ?       80           
  Lines                 ?     8615           
  Branches              ?      837           
=============================================
  Hits                  ?     8323           
  Misses                ?      238           
  Partials              ?       54           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mehrdad2m
Copy link
Contributor

Hi @erick-xanadu, do you think this PR can be merged for the release or it need more work?

@erick-xanadu
Copy link
Contributor Author

@mehrdad2m I think it can be merged. (I improved on the hashing after my comment). One issue is testing. I tested it by running it against the benchmark and noticing the regression no longer being there. But I don't think it is possible to write a unit test for it.

@erick-xanadu
Copy link
Contributor Author

@mehrdad2m in the release

@erick-xanadu erick-xanadu added this to the v0.11.0 milestone Apr 7, 2025
@mehrdad2m mehrdad2m changed the base branch from main to v0.11.0-rc April 7, 2025 17:41
@paul0403
Copy link
Member

paul0403 commented Apr 8, 2025

Makes sense to me!

@erick-xanadu erick-xanadu force-pushed the eochoa/2025-04-02/do-not-hash-long-strings branch from 8a79821 to 9028dac Compare April 8, 2025 18:18
@erick-xanadu erick-xanadu merged commit 23b7ee2 into v0.11.0-rc Apr 8, 2025
40 checks passed
@erick-xanadu erick-xanadu deleted the eochoa/2025-04-02/do-not-hash-long-strings branch April 8, 2025 18:32
mehrdad2m pushed a commit that referenced this pull request Apr 9, 2025
**Context:** After PR #1562, a single function could have multiple JAXPR
representations based on whether it was under a grad context or not.
This made the previous hash based on the function id create possible
conflicts. To address this, we hashed on the jaxpr string
representation. (We cannot hash on the jax object itself since they are
unique).

The JAXPR string representation can be very long and hashing over long
strings can take a long time.

**Description of the Change:** Instead of hashing the string
representation, add a simple key to denote whether it is inside a grad
context or not.

**Benefits:** Reduced compilation time.

**Possible Drawbacks:** The cache key is getting more complicated. Maybe
the drawbacks outweight the benefits now?

**Related GitHub Issues:**

[sc-88454]
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.

3 participants