Live data from Hacker News

Keras Core: Keras for TensorFlow, Jax, and PyTorch

keras.io

31–40 of 73 posts

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

#31
post #27

Keras and PyTorch! I thought I'd never see the day! Glad to see the two communities bury the hatchet.

I don’t get it - why would you want Keras if you already use Pytorch?

Because sometimes you don’t want to write your own training loops, you just want a working method to train a model.

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

#32
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.

Keras has a cleaner API compared to base PyTorch, especially if you want to use the Sequential construction as demoed in the post.

How so? You can use torch.nn.Sequential pretty much equivalently?

https://pytorch.org/docs/stable/generated/torch.nn.Sequentia...

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

#33
post #32

Earlier quoted context omitted.

Keras has a cleaner API compared to base PyTorch, especially if you want to use the Sequential construction as demoed in the post.

How so? You can use torch.nn.Sequential pretty much equivalently? https://pytorch.org/docs/stable/generated/torch.nn.Sequentia...

Huh, didn't realize base PyTorch had an equivalent Sequential API.

The point about the better API overall still stands (notably including the actual training part, as base PyTorch requires you to implement your own loop)

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

#34
post #27

Keras and PyTorch! I thought I'd never see the day! Glad to see the two communities bury the hatchet.

I don’t get it - why would you want Keras if you already use Pytorch?

The same reason why you might want to use Keras if you use any of the other backends. They operate at different levels.

Keras is a higher-level API. It means that you can prototype architectures quickly and you don't have to write a training loop. It's also really easy to extend.

I currently use PyTorch Lightning to avoid having to write tonnes of boilerplate code, but I've been looking for a way to leave it for ages as I'm not a huge fan of the direction of the product. Keras seems like it might be the answer for me.

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

#35
post #27

Earlier quoted context omitted.

I don’t get it - why would you want Keras if you already use Pytorch?

Because sometimes you don’t want to write your own training loops, you just want a working method to train a model.

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

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

#36
post #27

Earlier quoted context omitted.

I don’t get it - why would you want Keras if you already use Pytorch?

The same reason why you might want to use Keras if you use any of the other backends. They operate at different levels. Keras is a higher-level API. It means that you can prototype architectures quickly and you don't have to write a training loop. It's also really easy to extend. I currently use PyTorch Lightning to avoid having to write tonnes of boilerplate code, but I've been looking for a way to leave it for ages…

What’s so hard about writing a training loop?

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

#39

I worked on the project, happy to answer any questions!

Hi, first off thank you for your contributions, and this goes to the entire team. Keras is a wonderful tool and this was definitely the right move to do. No other package nails the “progressive disclosure” philosophy like Keras. This caught my eye: > “Right now, we use tf.nest (a Python data structure processing utility) extensively across the codebase, which requires the TensorFlow package. In the near future, we in…

At this time, there are no backend-agnostic APIs to implement training steps/training loops, because each backend handles training very differently so no shared abstraction can exist (expecially for JAX). So when customizing fit() you have to use backend-native APIs.

If you want to make a model with a custom train_step that is cross-backend, you can do something like:

  def train_step(self, *args, *kwargs):
    if keras.config.backend() == "tensorflow":
      return self._tf_train_step(*args, *kwargs)
    elif ...
BTW it looks the previous account is being rate-limited to less than 1 post / hour (maybe even locked for the day) so I will be very slow to answer questions.

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

#40
post #36

Earlier quoted context omitted.

The same reason why you might want to use Keras if you use any of the other backends. They operate at different levels. Keras is a higher-level API. It means that you can prototype architectures quickly and you don't have to write a training loop. It's also really easy to extend. I currently use PyTorch Lightning to avoid having to write tonnes of boilerplate code, but I've been looking for a way to leave it for ages…

What’s so hard about writing a training loop?

It's extremely easy to get wrong in subtle ways.
Post reply on HN