Live data from Hacker News

Keras Core: Keras for TensorFlow, Jax, and PyTorch

keras.io

51–60 of 73 posts

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#51
post #50

Earlier quoted context omitted.

nothing is. but to write a basic training loop with proper logging etc. from scratch every time you want to train a basic neural net classifier seems inefficient to me. There should be a framework for it where you can just plug in your model and your data and it trains it in a supervised fashion. That's what fast.ai or keras are doing.

You only need to write a training loop function once. Then you can just pass to it a model, dataloader, etc, just like you would if you used a training loop written by someone else in Keras. The only difference is it would be hidden from you behind layers of wrappers and abstraction, making it harder to modify and debug.

It sounds like you've found something that works best for you, and that the large Keras user base has found something that works best for them.

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#52
As someone who has dealt with countless breaking changes in keras and wasted days of my life attempting to upgrade, no thank you.

My pytorch code from years ago still works with no issues, my old keras code would break all the time even in minor releases.

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#54
post #50

Earlier quoted context omitted.

You only need to write a training loop function once. Then you can just pass to it a model, dataloader, etc, just like you would if you used a training loop written by someone else in Keras. The only difference is it would be hidden from you behind layers of wrappers and abstraction, making it harder to modify and debug.

It sounds like you've found something that works best for you, and that the large Keras user base has found something that works best for them.

The large Keras userbase exists largely because Tensorflow sucked.

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#55

Earlier quoted context omitted.

There are a lot of libraries for that. For example Pytorch Lightning, Accelerate are very mature

Sure, and Keras is another, very mature library which allows you to do this...

Keras + Pytorch is not mature.

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#56
post #11

Earlier quoted context omitted.

Yes I understand why they do the move (they want to attract pytorch user). What's the benefit for the user instead of directly using pytorch for example ? I see we can maybe use tpu by switching to jax etc... PS: sorry I'm a bit salty by my user experience of Keras.

Pytorch is an animal by itself when you try to put it into production. They have started addressing it with torch 2.0 but it still has lengths to go. With this you can switch to TFserve if you have usual architecture.

You can just use Triton which is basically TFserve for Tensorflow, Pytorch, Onnx and more.

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#58
Can someone ELI5 the relationship between Keras and TensorFlow/Jax/PyTorch/etc? I kinda get the idea the Keras is the "frontend" and TF/Jax/PyTorch are the "backend" but I'm looking to solidify my understanding of the relationship. It might help to also comment on the key differences between TF/Jax/PyTorch/etc. Thank you.

Re: Keras Core: Keras for TensorFlow, Jax, and PyTorch

#60
post #2

From the announcement: "We're excited to share with you a new library called Keras Core, a preview version of the future of Keras. In Fall 2023, this library will become Keras 3.0. Keras Core is a full rewrite of the Keras codebase that rebases it on top of a modular backend architecture. It makes it possible to run Keras workflows on top of arbitrary frameworks — starting with TensorFlow, JAX, and PyTorch." Excited…

That looks very interesting.

I actually have developed (and am developing) sth very similar, what we call the RETURNN frontend, a new frontend + new backends for our RETURNN framework. The new frontend is supporting very similar Python code to define models as you see in PyTorch or Keras, i.e. a core Tensor class, a base Module class you can derive, a Parameter class, and then a core functional API to perform all the computations. That supports multiple backends, currently mostly TensorFlow (graph-based) and PyTorch, but JAX was something I also planned. Some details here: https://github.com/rwth-i6/returnn/issues/1120

(Note that we went a bit further ahead and made named dimensions a core principle of the framework.)

(Example beam search implementation: https://github.com/rwth-i6/i6_experiments/blob/14b66c4dc74c0...)

One difficulty I found was how design the API in a way that works well both for eager-mode frameworks (PyTorch, TF eager-mode) and graph-based frameworks (TF graph-mode, JAX). That mostly involves everything where there is some state, or sth code which should not just execute in the inner training loop but e.g. for initialization only, or after each epoch, or whatever. So for example:

- Parameter initialization.

- Anything involving buffers, e.g. batch normalization.

- Other custom training loops? Or e.g. an outer loop and an inner loop (e.g. like GAN training)?

- How to implement sth like weight normalization? In PyTorch, the module.param is renamed, and then there is a pre-forward hook, which on-the-fly calculates module.param for each call for forward. So, just following the same logic for both eager-mode and graph-mode?

- How to deal with control flow context, accessing values outside the loop which came from inside, etc. Those things are naturally possible eager-mode, where you would get the most recent value, and where there is no real control flow context.

- Device logic: Have device defined explicitly for each tensor (like PyTorch), or automatically eagerly move tensors to the GPU (like TensorFlow)? Moving from one device to another (or CPU) is automatic or must be explicit?

- How to you allow easy interop, e.g. mixing torch.nn.Module and Keras layers?

I see that you have keras_core.callbacks.LambdaCallback which is maybe similar, but can you effectively update the logic of the module in there?

Post reply on HN