Add support for DistributedEmbedding for Ironwood and expose has_sparsecores.#183
Add support for DistributedEmbedding for Ironwood and expose has_sparsecores.#183hertschuh merged 1 commit intokeras-team:mainfrom
DistributedEmbedding for Ironwood and expose has_sparsecores.#183Conversation
Summary of ChangesHello @hertschuh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for Ironwood TPUs (identified as TPU7x) to DistributedEmbedding by updating the list of devices that have SparseCore. The change is straightforward, but it introduces code duplication across two files. My feedback suggests creating a single constant for the list of TPU device kinds to improve maintainability. I've also pointed out a potential inconsistency in the new device kind string "TPU7x" and asked for verification.
| device_kind = jax.devices()[0].device_kind | ||
| if device_kind in ["TPU v5", "TPU v6 lite"]: | ||
| if device_kind in ["TPU v5", "TPU v6 lite", "TPU7x"]: | ||
| return True | ||
| return False |
a7147e0 to
83f0017
Compare
DistributedEmbedding for Ironwood.DistributedEmbedding for Ironwood and expose has_sparsecores.
keras_rs/src/layers/embedding/jax/distributed_embedding_test.py
Outdated
Show resolved
Hide resolved
| if len(tpu_devices) > 0: | ||
| device_kind = tpu_devices[0].device_kind | ||
| if device_kind in ["TPU v5", "TPU v6 lite"]: | ||
| if device_kind in ["TPU v5", "TPU v5p", "TPU v6 lite", "TPU7x"]: |
There was a problem hiding this comment.
Here there might be a discrepancy between keras RS claiming the TPU has sparsecores vs the number of available sparsecores reported by jax_tpu_embedding. It might be worth having the try-except block here.
What we don't want is something like TPU7x being reported as having sparsecores, but then using an incorrect # SC per device.
There was a problem hiding this comment.
This list was copied from jax-tpu-embedding:
https://github.com/jax-ml/jax-tpu-embedding/blob/4d6a2e548c7f4a34c0755bc7185c6c0c765b173b/jax_tpu_embedding/sparsecore/utils/utils.py#L30
There was a problem hiding this comment.
Right, but it might get out-of-sync. Wouldn't it just be better to check the number of SCs per device, and if that returns 0 or throws an exception, then return False here?
There was a problem hiding this comment.
You wrote that code 😛
And I think the reason was that you wanted this to work even if jax-tpu-embedding is not installed. Then, if the users specified placement="auto" or placement="sparsecore" but jax-tpu-embedding is not installed, it gives you a different error message.
a848522 to
608dc2c
Compare
| return 1 | ||
| except ValueError: | ||
| # Default to one for non-sparsecore tests. | ||
| return 1 |
There was a problem hiding this comment.
Would it be better to raise the error, and just not test the non-sparsecore tests if there are no sparsecores?
There was a problem hiding this comment.
These test are also run on CPU. Do you know why?
I can just skip them if not on SparseCore.
There was a problem hiding this comment.
Oh, probably because we didn't have the CI configured to actually test on TPU, but wanted to check that the basic functionality works?
I leave it to you to decide how to handle this.
There was a problem hiding this comment.
They are now skipped when there are no sparsecores.
…parsecores`. - Use `num_sparsecores_per_device` from `jax-tpu-embedding` instead of having a duplicated hardcoded list of supported TPUs. - Added public class method `DistributedEmbedding.has_sparsecores`. - Added warning when running JAX on TPU with `jax-tpu-embedding` not installed. - Made error messages more specific and consistent with Keras errors.
num_sparsecores_per_devicefromjax-tpu-embeddinginstead of having a duplicated hardcoded list of supported TPUs.DistributedEmbedding.has_sparsecores.jax-tpu-embeddingnot installed.