Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Keras 3.0 (keras.io)
224 points by bratao on Nov 28, 2023 | hide | past | favorite | 75 comments


This looks really cool, and it's good to see Keras come full circle back to being an ergonomic interface with support for multiple frameworks. I remember being pretty disappointed when pluggable back ends went away. I appreciate that in the NLP module there is the most humane and concise LORA implementation I'm aware of. The ability to embed Keras components into models using other frameworks is pretty key.

Question: What's the model export story? If I want to export for CoreML or use the new PyTorch model compilation is there a straight forward way to do that?


Thanks! Hope you'll find the new Keras useful!

So far the export story focuses on SavedModel and the services that consume that format, e.g. TFLite, TFjs and TFServing. You can just do `model.export(path)`, and you also have access to the `ExportArchive` class for fine-grained configuration.

We have not tried CoreML export yet.

PyTorch `.compile()` works with Keras models. It may not necessarily result in a speedup however.


Francois from the Keras team here -- happy to answer questions!


You're my favorite Python developer. Very intuitive API design.


Any chance a keras.linalg suite of ops is in the works?

Cross-platform differences between the behavior of tf.linalg and torch.linalg have cost me a lot of time over the years.


We don't have a separate `ops.linalg` package, but we do include `numpy.linalg` ops as part of `keras.ops`. For now only 2 ops are supported: `qr` and `solve`. We're open to adding any `numpy.linalg` op that turns out to be useful (or you could open a PR for any op you need).


Hey Francois, congrats to you and the team on the launch! I've generally chosen Pytorch over Tensorflow for my day to day, but now that Keras is framework agnostic I'm excited to revisit it.

One thing I'm wondering about is if it's possible (or necessary?) to use Keras in concert with Pytorch Lightning. In some ways, Lightning evolved to be "Keras for Pytorch," so what is the path forward in a world where both exist as options for Pytorch users—do they interoperate or are they competitors/alternatives to each other?


Both Keras models/layers (with the PyTorch backend) and Lightning Modules are PyTorch Modules, so they should be able to interoperate with each other in a PyTorch workflow. We have not tried this with Lightning, but we've had a good experience with custom PyTorch Modules.

More broadly, it's feasible to use Keras components with any framework built on PyTorch or JAX in the sense that it's always possible to write "adapter layers" that wrap a Keras layer and make it usable by another framework, or the other way around. We have folks doing this to use Flax components (from JAX) as Keras layers, and inversely, to use Keras layers as Flax Modules.


Hi Francois, will there be breaking changes between 2.0 & 3.0 API


All breaking changes are listed here: https://github.com/keras-team/keras/issues/18467

You can use this migration guide to identify and fix each of these issues (and further, making your code run on JAX or PyTorch): https://keras.io/guides/migrating_to_keras_3/


What is Keras 3.0 (not) ideal for? Why not use pyTorch or Flax?


How much focus was there in the direction of TFLite?

Were any improvements made?


We made sure that TFLite workflows would run smoothly with Keras 3 models. We did not come up with any TFLite related improvements. The focus was on the multi-backend architecture, distribution, and training performance.


Thanks for info.

I hugely rely on TFLite for a bunch of hobby projects.


Congrats on the release!


I did not expect anything interesting, but this is actually cool.

> A full implementation of the NumPy API. Not something "NumPy-like" — just literally the NumPy API, with the same functions and the same arguments.

I suppose it's like https://cupy.dev/


If you like that you'll love this https://pytorch.org/blog/compiling-numpy-code/


Competition is always good. That said, Keras is a tough sell. I think the ML framework market, particularly for gen AI is moving either away from abstraction to lower level frameworks (ggml or custom, etc) or consolidating around HF. It would be cool to see Keras emerge as a meaningful HF transformers competitor, but I'm not sure what it would take to get there. As it is, I don't see a big incentive to use it, or for people getting started to learn it (especially to the exclusion of the underlying frameworks) which is too bad.


I disagree because the majority of data science roles focus on optimizing production processes or customer acquisition/retention. In practical terms, while we often reference tools like OpenAI, the real-world application revolves around machine learning-based data analytics and unstructured business intelligence. Keras emerges as a valuable tool for businesses due to its combination of machine learning capabilities beaing easy,allow data experimentation, for the business knowledge. In this context, the emphasis on machine learning isn't as pronounced as it is in companies dedicated solely to ML, such as OpenAI or Google ML


> consolidating around HF

What is HF? Is it HF as in RLHF?



Thanks!


I have used both Keras and pytorch Lightning. They have a lot of similarities and I'm fine with both. That said the abstraction does not really cover the input processing part: ie. pytorch dataloader or tf.data part


I'm not in the field but as a techie this attempt to be a universal solvent, to play well with everyone, looks extremely smart & extremely sharp. This is a highly compelling sell for me, and greatly boosts the chance that when I do start to dabble, I'll look at Keras.


See also https://github.com/unifyai/ivy which I have not tried but seems along the lines of what you are describing, working with all the major frameworks


It also reads a bit like an official promotion for JAX (well-deserved btw) by mentioning its advantages separately and putting it first in the list of main frameworks.


It's an open secret that TensorFlow is a deprecated framework internally at Google, and present/future model development should be done on JAX. Since Keras is a Google-owned product, it makes sense.


ML Noob here. Went though the tutorial[0] and the readability of the API is impressive. Like composing a whole model layer by layer.

Stupid question - can this also be used for composing transformer based LLMs?

[0]. https://keras.io/getting_started/intro_to_keras_for_engineer...


Yes, Keras can be used to build LLMs. In fact this is one of the main use cases.

There are some tutorials about how to do it "from scratch", like this: https://keras.io/examples/nlp/neural_machine_translation_wit...

Otherwise, if you want to reuse an existing LLM (or just see how a large one would be implemented in practice) you can check out the models from KerasNLP. For instance, this is BERT, basically just a stack of TransformerEncoders. https://github.com/keras-team/keras-nlp/blob/master/keras_nl...


I'm really excited about this! I know the Keras team has been hard at work and it's cool to see the 3.0 release as sort of a reborn framework. One thing I'm particularly stoked about is the ability to load models from other frameworks but then work with TF and Keras based exports for productionization, especially on e.g. edge. I think there's a lot of goodness beyond just being able to pick and run a pre-existing backend. Thanks for all the hard work!


Awesome! I'm a big fan of Keras and this is an exciting update.


I have only had positive experiences while using Keras in the past, but have not used it in a few years.


Love this.

Am wondering how well this will work on Windows.

Likewise for the pretrained models on my personal laptop (i7, 32GB RAM, RTX 2060 6GB).


Keras is meant for training, not inference.


I understand. I would like to train smaller proof-of-concept models on my laptop, which could build upon large pre-trained models though. Thanks.


I'm a bit of a novice in the space, if keras isn't for inference, what's the intended workflow?

Train with keras and then?


You can absolutely serve with Keras if your inference server is in Python. For instance, if you're looking for a basic solution, you can just set up a Flask app that calls `predict()` on a Keras model.

If you're looking for a high-performance solution that is entirely Python-free, then you can simply export your Keras model as a TF SavedModel and serve it via TFServing. TFServing is C++ based and works on both CPU and GPU.


Then there's standard formats like ONNX and inference on any platform or language or hardware that you prefer


How does it compare to Mojo?


Mojo is a programming language, this is a library for Python that provides an abstraction over three Python-specific ML frameworks. Apples and oranges.

You could use Keras inside of Mojo since Mojo is Python-compatible/embeds a Python interpreter.


"Keras 3 is a full rewrite of Keras" and "It's also a battle-tested framework"

In case of a full rewrite how can we talk about battle-tested? I can understand the API is, but not the implementation.


This means that the API, the abstractions, the workflows are battle-tested.

The codebase itself went through 2 months of private beta and 5 months of public beta. It is already used in production by several companies. It's not as battle tested as older frameworks, but it's fairly reliable.


I've been out of the ML game for a little while now (2+ years) but previously was under the impression everyone loved Keras. This thread says otherwise.

The only mentioned alternative so far is `ggml`, which I have heard mentions of but am not familiar with. What are other alternatives & their corresponding pros and cons? Now, I am familiar with:

- Tensorflow (complex API right?)

- Keras (simple API?)


Depends what kind of ML. If you were just spinning up models to shove data through, sure. If you wanted to craft a model to your particular needs, you will have a much better time with Torch, even 5 years ago when online tutorials were filled with TF/Keras.

I think Keras more or less died when the TF 2.0 transition was botched so badly. Many moved to Torch and never looked back.

FWIW I actually prefer JAX but my work is atypical compared to the usual "predict churn" or whatever application.


Keras started out great but grew clumsily, making custom use-cases cumbersome and error prone and also became inextricably linked with TensorFlow (which was a big headache compared with PyTorch).

It seems like this rewrite cleans up the meandering mess of Keras's middle period, or at least I'd be willing to give it a try.


It's been a few years since I did Keras dev full time, but debugging was a nightmare. PyTorch- as long as you don't compile and you run on CPU, it's pretty much like debugging standard code. Debugging CUDA is harder.

Edit: Seems like `run_eagerly` solves a lot of the pain of debugging Keras code.


Huggingface I would consider a high level framework, that uses pytorch as a backend (they may now be using rust/candle as well?)

Mojo is another ML specific python dialect.

I think most people including me associate Keras with being very simple and high level, which isn't really correct now based on the article.

ggml is somewhat specialized, I was giving it as an example of the kind of framework I think we'll see more of, that is specialized, dependency free, written in a compiled language and directly optimized for speed. As use cases consolidate around specific architecture like LLMs, a faster and simpler low lever framework becomes preferable to a swiss army knife with abstraction upon abstraction like pytorch.


My guess; perspective from a noob who's been using TF (Which I think absorbed Keras's API??) and OpenVINO: The Data Science/Python crew prefer PyTorch, and it's become self-perpetuating by WOM. So, people new are being recommended to use Torch, and it spreads that way.


What's the go-to ML framework nowadays?

One day, I set off to create an ML project in Tensorflow; but I soon realized that getting the data in ready would be a huge challenge and also a massive value-add. It's been three years and I'm still working on the data!


Pytorch itself, or abstractions built on top such as Huggingface


Would you use Keras 3.0 for anything?


Well... some 4 years ago I got a non trivial time series forecasting tool into production, built on Keras. The experience was pretty good, there was nothing that annoyed me too much.

However, as the comments here show, the mindshare and community momentum seems to have shifted totally to Torch.

Especially considering that it's transformers everywhere, right now, and there's just so much premade stuff built on top of pytorch, I'd probably stick with that. At least out of pragmatism such as the ease of hiring people with torch experience.

The transparent Numpy experience seems nice, keras was the first thing I ever built real NNs with, all said it's never been bad to me but... to conclude, no.


According to PyPI downloads and user surveys (like the yearly StackOverflow survey) the two main frameworks are TensorFlow and PyTorch for Deep Learning, and Scikit-Learn for classical ML.

See: https://survey.stackoverflow.co/2023/#technology

* TensorFlow: 9.53% usage among all devs

* Scikit Learn: 9.43%

* PyTorch: 8.75%


Every time some survey pops up, TF somehow looks still relevant while I know noone who uses it or even considers using it unless they are new to DL field. How much of TF here is v2.0?:)


We use exclusively PyTorch at work both for CV and NLP tasks and this is the standard nowadays. Keras was cool 5 years ago (last time I checked it) but it somewhat quickly faded due to TF.


Seems like they missed the boat and the whole world has moved on. Maybe if this came out 2 years ago it would be more relevant.


What is relevant now?


PyTorch has the nicest debugging experience. JAX is supposed to be powerful too, but I'm skeptical of its static graph which is what made TensorFlow such a chore. I'm whishful about Mojo, in theory it sounds great.


On the contrary, that's why I find Keras 3 interesting (although I don't see myself switching anytime soon). It supports both PyTorch and JAX, and Keras Core models/layers can be used interchangeably with PyTorch modules: https://twitter.com/fchollet/status/1697020631752298982


I use keras for CV but for DL at work, we started moving towards pytorch and closely following modular.


[flagged]


I've only experienced him polite and responsive. That said, maintaining Keras must have been an unhealthy amount of work for one person, and I think OSS developers in that situation deserve the benefit of doubt that being brusque or ignoring issues is not a character flaw, but a defense mechanism to keep their sanity.


Why do you say that?


[flagged]


Yeah, that never happened. We process dozens of bug reports and feature requests every week, and we listen to them.


[flagged]


Can you please stop posting unsubstantive comments about this? You've done it repeatedly over many months. It's excessive and off topic.

Much better would be to find something you're genuinely curious about and contribute to that topic instead.

If you wouldn't mind reviewing https://news.ycombinator.com/newsguidelines.html and taking the intended spirit of the site more to heart, we'd be grateful.


We disagree. I was in the throws of a life threatening illness and working on Keras in the very early days was an outlet for me. During that time the main author accused me publicly of trying to sabotage the project; a comment completely out of left field.


That can all be true, of course, and the feelings understandable, but still the comments are off-topic and repetitive.


[flagged]


To clarify, I have never attacked PyTorch, on Twitter or otherwise.

What happened is that I was a target of online harassment campaign from 2017 to January 2021 (when it stopped abruptly), which originated from a PyTorch developer and took the form of frequent anonymous emails (or messages on social networks) with insults and threats. The thread you link to below is me complaining about the harassment campaign and calling for civility.

Some frameworks fans can be extremely toxic, e.g. creating anonymous accounts on HN for the purpose of bashing one framework or one person.


Are you referring to Chollet? He does come off as arrogant at times.

I had some hopes when Keras dropped the other backends and just became part of TensorFlow 2.0, for which I had high hopes too, but I think it just made it worse. I've lost all interest, and getting increasingly disillusioned by TensorFlow for each day.


based on the tweet you provided as evidence I find your comment more of a "malicious attack" actually


Do you have a link?


[flagged]


I wouldn't describe that as "maliciously attacked PyTorch"


Sure, yet that's one tweet and his tone is pretty telling if you ask me. Disregard if you don't believe, I'm not making it up


I encourage you to reread the Twitter posts in question, your post here, and evaluate, as if you were a disinterested third party, if it still makes sense.


Based on the evidence you provided the only malicious attack is your own.


[flagged]


> PyTorch fanboys

> But the PyTorch community is something special

The context and request for civility makes sense and makes it look less like and attack in context. Implying that it's some characteristic of pytorch users is a bit more damning. Trolls are out there, I don't think it's using a particular deep learning framework that makes them more trollish, implying otherwise isn't constructive.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: