keras-team/keras

๐Ÿš€ Contributing to Keras ๐Ÿš€

fchollet opened this issue ยท 51 comments

Keras 3 is a high-velocity open-source project. We welcome contributions! Here's what you can do:

Take up one of these items:

Here are some features that we'd love to see implemented by the Keras community:

  • Add cuDNN support for PyTorch RNNs by implementing keras/backend/torch/rnn.py:cudnn_lstm and cudnn_gru.
  • Add support for ONNX in model.export() and ExportArchive. On the TF and JAX side, we can transit via SavedModel. On the torch side, we can do a native export.
  • Implement tool for saved Keras model file inspection, diff, and patching. It could:
    • Take a fname.keras file and display the manifest of its contents (including weights file structure)
    • Take a fname.weights.h5 and display the manifest of its content.
    • Diff two weights files, highlighting what's in one and not in the other.
    • Patch a file, by replacing a given weight with a different value provided by the user.
  • Add all models from keras.applications to keras_cv.models, e.g. Xception, ConvNeXt, etc.
  • Update KerasCV models to make sure they also work in channels_first mode.
  • Add a new Flash Attention op, as keras.ops.nn.flash_attention. See #19418

Check out TODOs

There are various TODOs in the codebase. You can do a quick search (e.g. grep "TODO" keras/ -r) and see if anything looks interesting to you. Make sure to ask in this thread before starting work on any item!

Bring new pretrained model implementations to KerasCV and KerasNLP

The Keras ecosystem packages KerasCV and KerasNLP are looking for contributors!

If you'd like to port a pretrained model implementation to the Keras ecosystem, these packages are great projects to join.

Convert an example from keras.io to Keras 3

keras.io/examples offers many great tutorials, but many of them are still based on Keras 2. We'd like to bring over in the shiny new world of multi-framework ML.

There are two stages of conversion:

  1. Converting a Keras 2 example so that it can run on Keras 3 with the TF backend.
  2. Converting a Keras 2 example so that it can run on Keras 3 with any backend.

If you see an example marked as "v2" on keras.io/examples, you can open a PR on keras-team/keras-io to convert it to Keras 3. Keep in mind:

  • Start by only including the Python file in the PR, not the md and ipynb files, because you may have to regenerate those after review comments come in.
  • To convert the code, you can refer to the Keras 3 migration guide.

Add new examples to keras.io

Have a great ML project you'd like to use to teach others about ML? You can add a new tutorial on keras.io/examples! Just follow the instructions at keras-team/keras-io.

Increase test coverage

Keras doesn't have 100% code coverage in unit tests just yet. You can try to run a code coverage tool like codecov and see if there are any unit tests you could add to improve Keras.

Taking up the Moving Dataset utils task as a priority! Should I make a draft PR?

Taking up the Moving Dataset utils task as a priority! Should I make a draft PR?

No need for a draft -- you can just send the PR when you have something you want a review on. Thank you!

@fchollet regarding dataset utils, since all three frameworks tensorflow , torch and jax have their own data-loading modules or have specific classes to provide this utilities, but currently it is relying on tf.keras can only accept either tf.Dataset or regular python structures as of now, so dropping it means that we either support similar logic for individual framework or we accept generic structures + framework specific data-holder and convert it to a unified keras data-holder and then perform similar operations.

since in first option we import framework specific modules and built on top but these will stay in keras.backend but in option two we we don't need to touch keras.backend' we only made changes to keras.utils`. Can you please let me know your thoughts on this. ๐Ÿ˜Š

@suvadityamuk can please also share your thoughts in which direction you are choosing. ๐Ÿ˜Š

@asingh9530

I'm currently looking into trying to move the tf.keras-specific data utils from the original keras-team/keras space to this space, with all implementations intact. The only thing I'm adding is support to handle torch.utils.data.Dataset along with it, since that's a major focus.

@suvadityamuk Thanks for responding, since this will be a big change let's track it in a new issue with specific changes needed to be done since even in keras the utils are for tf.Dataset let's say Iterators, batched etc. How about I'll add you there and work on this.

Hello,
I am rather new w.r.t contributions, so I may ask a rather silly question : are publicly exported functions those decorated with @keras_core_export ?

so I may ask a rather silly question : are publicly exported functions those decorated with @keras_core_export

Yes, that's right. The public API is programmatically generated using those decorators.

Can someone help me with keras_core/layers/layer.py:439: # TODO: handle layout.What does it mean to handle the layout?

Can someone help me with keras_core/layers/layer.py:439: # TODO: handle layout.What does it mean to handle the layout?

This was referring to the implementation of a future distribution API -- but this has been handled since. Nothing to do here.

Hi,

I am willing to take a shot at the solve operation implementation, still setting up a development environment. One clarification question. What is the error value for a matrix input that is singular (i.e., no inverse matrix exists), not full rank, or not square? To be sure, I look forward to contributing as a hobby and will circle back when I have something satisfactory for review.

Thanks,
bf

Hello @fchollet,

I wanted to reach out and update you on the progress I've made with the ERF function. I've made significant changes to the code and have already uploaded them to my forked repository. I'm confident that these updates will improve the function's performance, but please take a look and let me know if there's anything else you'd like me to do.

1.) Changes to keras-core/ops/math.py
https://github.com/sqali/keras-core/blob/6485433201e8a935f462aca191bc37dd7cf00c30/keras_core/ops/math.py#L934-L966

2.) Changes to keras-core/ops/math_test.py
https://github.com/sqali/keras-core/blob/6485433201e8a935f462aca191bc37dd7cf00c30/keras_core/ops/math_test.py#L840-L868

3.) Changes to keras-core/backend/tensorflow/math.py
https://github.com/sqali/keras-core/blob/6485433201e8a935f462aca191bc37dd7cf00c30/keras_core/backend/tensorflow/math.py#L244-L245

I am willing to take a shot at the solve operation implementation, still setting up a development environment. One clarification question. What is the error value for a matrix input that is singular (i.e., no inverse matrix exists), not full rank, or not square? To be sure, I look forward to contributing as a hobby and will circle back when I have something satisfactory for review.

solve exists in all 3 backends, so most likely we just want to wrap it. You can check what the error is for a singular matrix for each backend. We should raise a similar error.

I wanted to reach out and update you on the progress I've made with the ERF function. I've made significant changes to the code and have already uploaded them to my forked repository. I'm confident that these updates will improve the function's performance, but please take a look and let me know if there's anything else you'd like me to do.

It will also need to be implemented for the JAX, torch, and numpy backends. Can you open a PR? We can carry on on the PR.

Sure, I will do that. Thanks.

@fchollet , I am interested in contributing to Keras Core. I went through the description above and interested to work on this item "Convert an example from keras.io to Keras Core". Could you please guide me on the steps to follow . Do I need to raise a new pull request.
Thank you

@fchollet I can take up erf implementation, any specific condition you want in the implementation if not I will follow implementation guideline of rest of operations.

I can take up the scan op/operation in jax

Hi @asingh9530 ,

I have already opened a PR for erf and working on it. Thanks.

Hi people,

I think I took care of most of the necessary changes. Still struggling on how to run a unit test locally with respect to my forked branch. Happy to open a PR if this is helpful. In addition, please advise on how to run a test, import a built whl binary into a Jupyter notebook, and next steps for agnostic solve.

Thanks,
bf

@fchollet I'm working on the keras_core/saving/saving_lib.py. TODO: if h5 filepath is remote, create the file in a temporary directory then upload it. Should I use the requests library to posts the file on the required remote filepath ?

I'm working on the keras_core/saving/saving_lib.py. TODO: if h5 filepath is remote, create the file in a temporary directory then upload it. Should I use the requests library to posts the file on the required remote filepath ?

Please only use Python stdlib utilities for this. Thanks!

I am interested in contributing to Keras Core. I went through the description above and interested to work on this item "Convert an example from keras.io to Keras Core". Could you please guide me on the steps to follow . Do I need to raise a new pull request.

Here's the full context and the process to follow: #18468

I can take up the scan op/operation in jax

Sure, sounds good! It will need to be implemented in all 4 backends though.

I think I took care of most of the necessary changes. Still struggling on how to run a unit test locally with respect to my forked branch. Happy to open a PR if this is helpful. In addition, please advise on how to run a test, import a built whl binary into a Jupyter notebook, and next steps for agnostic solve.

It will need much more extensive unit testing. You can run unit tests locally via pytest.

I'm working on the keras_core/saving/saving_lib.py. TODO: if h5 filepath is remote, create the file in a temporary directory then upload it. Should I use the requests library to posts the file on the required remote filepath ?

Please only use Python stdlib utilities for this. Thanks!

thanks, last question what can be a good example for remote file path.

thanks, last question what can be a good example for remote file path.

Something like gcs://...

I am interested in contributing to Keras Core. I went through the description above and interested to work on this item "Convert an example from keras.io to Keras Core". Could you please guide me on the steps to follow . Do I need to raise a new pull request.

Here's the full context and the process to follow: #18468

Thank you. I will check the link and start working

Thanks @fchollet! Debugging more unit tests now, I commented the latest errors I have been seeing in the math._test.py file here. Any ideas to get a more deterministic response from tensorflow are much appreciated.

I could port some of the listed examples from tf.keras to Keras Core. Out of the outstanding examples, are there any, in particular, you would first like to see ported to Keras Core?

@fchollet what to do if some framework do not have the feature or it is work in progress( like scan and pytorch pytorch/pytorch#50688)?

@fchollet ,I was trying to port this example of mixup augmentation https://keras.io/examples/vision/mixup/, while defining Hyperparameters in keras-core, what should we replace this line with AUTO = tf.data.AUTOTUNE? Could you please help clarify the same.

@fchollet I am interested in solving the todo,
keras/metrics/accuracy_metrics_test.py: # TODO: Check save and restore config

can you give me more detail of how it should be done.

Hi, @fchollet ,

For my first commit to Keras, I picked a simple one, addressing two small TODO items in reduction_metrics_test.py.

Here's the PR: #18812

I believe what the comment "# TODO: Check save and restore config" meant is that an object (Sum or Mean) must be re-constructed from config, and be tested.

Please let me know if I misunderstood the requirements, or otherwise made any mistakes.

Thank you! I'm very excited about working on this very important library.

Hi, @fchollet ,

For my first commit to Keras, I picked the TODO in discretization_test.py.

Here's the PR: #18882

Thank you!

Is anyone working on JAX CTC? If not, I can take it up

I will take the ops.correlate if nobody is working on it.

@fchollet I could take dice loss if nobody else is working on it. @vulkomilev did you start with ops.correlate?

@fchollet can you or someone add me as a contributor? I need to make a push to the remote branch for the dice loss.

@fchollet I have the first version of the DiceLoss in the tf backend. I need to be made a contributor to make a push to the remote branch so that the code review can take place.

@fchollet any updates for the DiceLoss? I have the TF implementation ready.

@fchollet I could take dice loss if nobody else is working on it. @vulkomilev did you start with ops.correlate?

yes I did

@vulkomilev Thanks for the answer. Are you a contributor? How do you do the push to the branch? I have this dice loss done, but cannot push since I am not a contributor.

Please Can I have a french version !?

@fchollet Hi, I think I invented something interesting. I implemented it in pytorch and I opened an issue there.
pytorch/pytorch#122680

@vulkomilev How do you do the push to the branch?

you make a MR and waiting for approval

@vulkomilev I cannot push. I don't have the rights.

@vulkomilev I cannot push. I don't have the rights.

sorry I meant pull request

Hello @fchollet,
Can I make the tool for saved Keras model file inspection, diff, and patching or is there someone already working on it?
Thanks in advance!

I will get the "Add a new Flash Attention op" task

@fchollet for every back-end I must introduce the implementation mentioned in the ticket right ?

@sampathweb @fran6co - I have seen last comments on file 'keras/src/layers/preprocessing/string_lookup_test.py' . I have grep'ed for 'TODO' and list this file . I am new for Keras contrib and setup Keras in local successfully. Would any one give me insight on this file and changes needed for 'TODO' sections .