-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add guide for writing a custom kernel #2226
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
base: master
Are you sure you want to change the base?
Conversation
Walks users through how to define a custom kernel using Pallas (only works with the JAX backend).
Summary of ChangesHello @jeffcarp, 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 adds a comprehensive guide to the documentation, detailing the process of creating and integrating high-performance custom kernels for Keras models targeting TPUs and GPUs. The guide focuses on using the Pallas library with the JAX backend, illustrating how to achieve significant performance gains through techniques like operator fusion and memory tiling, and also covers the necessary steps to make these custom kernels trainable. 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. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds a comprehensive guide on creating custom TPU/GPU kernels in Keras using Pallas. The guide is well-structured, starting with a simple example and moving to a more complex, real-world use case of a fused matmul-ReLU operation, including benchmarking and enabling training. My review focuses on improving the clarity and correctness of the examples and explanations. I've suggested corrections to a misleading explanation about memory tiling, pointed out an incorrect shape in one of the training examples, and recommended cleaning up the import statements for better code organization. Overall, this is a valuable addition to the documentation.
5f38452 to
b0f732a
Compare
| benchmark(standard_layer, input_data, "Standard Keras (Matmul + ReLU)") | ||
| benchmark(pallas_layer, input_data, "Pallas Fused (Matmul + ReLU)") | ||
|
|
||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. The outputs are missing in your rendered colab. They should appear in blocks like this: https://github.com/keras-team/keras-io/blob/master/examples/keras_rs/md/sequential_retrieval.md?plain=1#L311
(they are correctly appearing in the ipynb file though)
Walks users through how to define a custom kernel using Pallas (only works with the JAX backend).