14 ms·
Why Do ML on the Erlang VM?
- geysersam 3y agoI'm curious, anyone have an anecdote where using Python for data processing or machine learning became a performance problem? My experience is that Python has so many high quality packages to deal with cpu intensive tasks that unless you absolutely cannot use them, for some reason, performance is rarely a problem. But I'd like to be informed about the exceptions.
- c0balt 3y agoAt least for data processing pure python can quickly become a problem when handling somewhat large, dozens of GB, files. I've encountered this a few times and tge way to go is usually to either, if viable, port to a different language or only port the hot parts to a relevant library or Cython/Rust with pyo3.
- layoric 3y agoOut of interest, did you find this was a problem that using optimised numpy still didn’t perform good enough? (depending on what you call pure python, yes I agree python loops etc are extremely slow)
- c0balt 3y agoI didn't find any problems with numpy based processing in practice. The issue more often is that users choose Python for ease of writing and the std lib and don't consider numpy for these cases. The performance considerarions usually only come up later.
- efxhoy 3y agoI wrote simulation software at a research department previously. 99.8% of the problems were perfect for numpy/pandas and learning a compiled language wasn’t worth it for the 0.2%. If I was to work the same problems again I’d do it in two years when polars has all the good stuff from pandas and I’d learn enough rust to drop down to it for the custom stuff.
- jebarker 3y agoI've hit problems a couple of times with compute intensive data loading tasks in Pytorch. One involved custom data augmentations on spatial graphs. I couldn't find any python libraries that offered performant implementations of the functions needed and ended up writing custom C++ extensions to call from python. The other involved running video encoders and decoders inside the dataloader. The problem was more Pytorch specific than python per se, but the way Pytorch handles multiprocessing and CUDA streams made efficient parallelism very difficult. It would have been much easier in C++. I've also needed to ditch python for ML inference in production when extremely low latency was required.
- nemothekid 3y agoI rarely see performance problems that are show stoppers, especially in the cloud, where you can always just buy a bigger node. Usually if something is going to be rewritten C++/Rust/$performant_lang it's that high velocity iteration on the codebase has mostly stopped and we could save 50-60% in infrastructure costs by running it on nodes with less resources. Then naturally you start to factor in the engineering manhours for the rewrite vs the potential savings.
- electroly 3y agoNot a single one of our data scientists knows how to use multiprocessing. Their jobs are all 1 CPU core, hundreds of gigabytes of RAM. The EC2 instances they run on end up wasting tons of cores, even with high-memory instances. This isn't necessarily Python's fault, but rather because Python has a lot of users who are not computer programmers. One thing we can blame Python for is that the data scientists can't ever loop over their data with a regular loop. Simply impossible; it's too slow and would immediately wreck performance. They're more Pandas programmers than they are Python programmers; everything has to be done with Pandas operations for performance to be acceptable. This limits our (the computer programmers) ability to help out, because the languages we use are not slow like that, so we may give suggestions from our world that simply can't be used in Python because it's too slow. "Can't you just loop over the data and do XYZ?" Nope, they can't. We still use Python because it's all the data scientists know, and it's easier/cheaper to just write a bigger check to AWS than to hire people with both data science and computer programming backgrounds.
- ssivark 3y agoI've run into some pretty straight-forward problems (eg: modeling physical systems, with linear algebra and some other basic math) where avoiding python for loops meant allocating memory up front for massive numpy, and then doing multiple separate vectorized operations on them rather than fusing all of them into a single for loop. Required several hundred GB of RAM and took a few hours IIRC. This was of course still better than Python for loops... /facepalm I wrote the same thing in Julia in about the same number of lines of code -- avoiding the sins above -- and I could run it on my laptop in a few seconds.
- geysersam 3y agoFor stuff like that I think Numba really shines. But yes I get the issue. Julia is great, but sometimes a bit less user friendly than Python, it's quite easy to shoot oneself in the foot performance wise using Julia.
- ssivark 3y agoI hate the fact that if I choose Numba, then I can’t easily compose with other tools like autodiff, etc. Maybe Jax improves the situation in some aspects. Generally though… While Python might have many distinct popular/well-developed tools, they tend to compose very badly. IME, it feels relatively painful if you’re trying to do something new which hasn’t been solved and wrapped for you. As for Julia footguns, it has been relatively trivial IME to get substantial improvements compared to Python. Whether that is the best one can do, I dunno.
- impulser_ 3y agoThere is a good talk about switching from Python to Elixir for a ML stack from ElixirCon 2022. https://www.youtube.com/watch?v=Y2Nr4dNu6hI https://www.youtube.com/watch?v=Y2Nr4dNu6hI
- paddw 3y agoPeople will go through any number of hoops to not give, "I like the feel of the language more", as a reason for using it. Clearly, the main reason you would consider using Elixir for this is just that. There may be benefits to Elixir as a language, but there is no way they are going to overcome the ecosystem deficiencies to make it worth while in any unbiased cost benefit calculation. Just say you want to work in Elixir! It's okay to have a preference on the tools you use, even if it's for aesthetic or experiential reasons.
- giraffe_lady 3y agoI think BEAM languages are kind of one of the few exceptions to this argument. Its tradeoffs and runtime semantics really are just very different from other mainstream languages. Other languages & communities are adapting to modern trends towards high concurrency, distributed systems, horizontal scaling, tight fault detection & recovery with varying degrees of struggle and success. Meanwhile in erlang these have been priority concerns for decades and they have highly sophisticated refined solutions to them built directly into the system. Not that this article makes a good argument for the benefit of any of those things for ML. But at least generally while I am a pretty strong believer of "eh language doesn't really matter" erlang-based languages I do entertain a possible exception for.
- rramadass 3y agoAgreed, You might find Handbook of Neuroevolution Through Erlang by Gene Sher interesting.
- fzeindl 3y ago> I think BEAM languages are kind of one of the few exceptions to this argument. Its tradeoffs and runtime semantics really are just very different from other mainstream languages. Agree wholeheartedly. Elixir/BEAM/Erlang are a league of their own.
- drowsspa 3y agoNever really played with the Erlang VM other than a little more than the Hello World in Elixir, but when I'm in the debugging hell of Apache Spark I really wish it wasn't based on the JVM.
- rch 3y agoI don't think Elixir/Nx needs to check boxes in an exhaustive point by point comparison with Python to emerge as a viable platform for ML work. It's a solid option, and that's enough for me to invest some time exploring.
- RcouF1uZ4gsC 3y agoIf you want to experiment and tune ML, I think Python is great. Once you actually want other people to use it, C++ is the best. The user experience of trying to set up one of the Python libraries for LLama vs llama.cpp is night and day.
- xgdgsc 3y ago"It is ridiculous how easily I can swing together a Phoenix web app and add some ML smarts to it. " I'd rather optimize the current julia web app stack a bit and use with existing julia ML libraries.
- c7b 3y agoGreat post. I'd be interested in a similar comparison when it comes to distributed computing/concurrency/fault tolerance/scaling/observability of Erlang/Elixir/Beam vs eg Rust or Go.
- manicennui 3y agoI was hoping this was about the programming language ML on BEAM.
- weatherlight 3y agoI thought this was a call for Standard ML or something a rather on the Erlang VM. (I really enjoyed this article though!) As far as I know theres a few implementations of ML like languages on the Erlang VM https://github.com/llaisdy/beam_languages https://github.com/llaisdy/beam_languages caramel and alpaca are worth checking out. Gleam doesn't look like a ML lang but has a lot of the same semantics of a ML lang
- nologic01 3y ago"Adding ML to X" is a powerful way to probe what X is really made of and maybe even give direction to efforts to improve X. That is because "ML" is a proxy for an entire domain (data science) that has both very distinct requirements and patterns developed over decades and is now evolving very fast as it broke out of the whitecoat lab and (for good or bad) into our lives. The ascent of python is as the article noted "accidental" but that doesnt mean it is suboptimal given all the requirements of the domain and the available alternatives (here and now). Its natural to focus on an exceptional attribute (like concurrency) to motivate even having the discussion but this addresses only one of three critical requirements if you decide to do everything within one langauge. 1) Ability to experiment interactively (REPL and friends), expressivity, human oriented language design etc 2) Ability to build production scale models (training or estimation phase) utilizing heterogeneous and fiddly compute 3) Ability to deploy to diverse devices and footprint / latency requirements both natively and as part of a web application. NB: Its only here that the intrinsic qualities of erlang might put it above the rest Historically there was never an ecosystem than could do all that optimally within just one language. Some of the requirements are arguably even incompatible. The current preferred solution is not "python" but python/c++ which does some of that well (1, 2) and 3 only passably. The only declared single language contender is julia but its very far from being a complete ecosystem in the above sense. Another emerging possibility is mojo, as a superset of python. But that is not even available yet. Back to the erlang/elixir combo. Its not even clear to me if it can address all of the above in a passable way. But on the other hand ML is really shaking the game and what is mayne more imprortant is the vitality and resourcefulness of different communities to develop in the direction of the new rewuirement. We have not seen the end of ecosystem evolution.
- josevalim 3y agoHello, creator of Elixir here (and co-creator of Nx). I like your breakdown of the requirements in three abilities. I think Elixir provides all three of them (with a caveat) and I will refer to two videos for those who want to learn more: * This video shows how you can use Livebook (open-source computational notebook environment) to explore pre-trained neural networks (from Hugging Face), learn how they work, and then deploy them as part of a Phoenix web application: https://news.livebook.dev/announcing-bumblebee-gpt2-stable-diffusion-and-more-in-elixir-3Op73O https://news.livebook.dev/announcing-bumblebee-gpt2-stable-d... * This video shows how to scale a neural network serving, first to run it concurrently, and then have it run distributed over multiple CPUs and GPUs: https://news.livebook.dev/distributed2-machine-learning-notebooks-with-elixir-and-livebook---launch-week-1---day-2-1aIlaw https://news.livebook.dev/distributed2-machine-learning-note... The caveat is about your second ability. The production scale models are, at the end of the day running native/cuda code, using the same backends as Python (Google XLA and LibTorch). What we do is that we compile your Elixir code into a graph which is then compiled to the CPU/GPU just-in time (in an approach similar to JAX). You can find more information here: https://github.com/elixir-nx/#why-elixir https://github.com/elixir-nx/#why-elixir
- lunatuna 3y agoThis is like a game ad that doesn’t show you the actual game play. For all the arguments made the code wasn’t shown.
- moomoo11 3y agoI wish I could not use python and other languages with def whatever. Can’t be the only one to dislike these languages. I don’t even care about languages that much, but I avoid AI stuff because I just can’t stand the python or elixir ecosystems. So much crap is required to get something basic working, although it’s less annoying with elixir. Oh well
- polvalente 3y agoCould elaborate on this? I'm genuinely curious about what annoys you regarding Elixir specifically.
- moomoo11 3y agoJust the syntax really. I work primarily with Go TS Dart. I just never liked the ruby/py syntax with def and lack of type safety. I just stick to Go for all my backend needs. It does everything elixir is capable of and provides more than just raw IO handling without blowing up memory or struggling with computations. Never got into ruby either the syntax just makes me lose interest.
- polvalente 3y agoMakes sense! I on the other hand prefer more "human-like" syntax like Python and elixir provide, though I really dislike Python being so sensitive to whitespace (especially tabs vs spaces sensitivity)
- klrart 3y agoI don't know Elixir, but Python's syntax is excessively pedantic and boring. Functional programming is hardly supported (no real lambdas, currying is a gigantic hack, "match" is a statement and not an expression, ...). So you are not the only one. Python is just good in tying CUDA libraries together while suffering through Python's syntax.
- _odey 3y agoMany years ago I was studying deep learning using this resource: * http://neuralnetworksanddeeplearning.com/ http://neuralnetworksanddeeplearning.com/ I decided to try to implement everything from scratch in Elixir (after initially doing all the math with pen and paper on a trivial example to get the feel of it). Obviously pure elixir was extremely slow, so I started creating NIFs to pass over matrix multiplication to OpenBLAS. Then I was thinking more and more of what things I can pass to C code and just have Elixir as a "frontend" for it. My enthusiasm died down when I realised I was simply implementing things in C with the pretext of "doing elixir", a nice learning experience but I could see I was not doing the things that initially got me pumped up. Don't get me wrong, I loved the discovery part of it, reading research and trying to understand so I can implement the different new (at the time) deep learning techniques, like convolutions, LSTM, and the different nuances of it. I think it gave me a better understanding of how things work and why it works. But it deviated from the initial scope and I lost interest once the learning phase was over and I knew I could simply use tensorflow or pytoorch as I did not actually need the advantages BEAM offers for this type of workload. Code is still available here: * https://gitlab.com/sdwolfz/experimental/-/tree/master/exlearn https://gitlab.com/sdwolfz/experimental/-/tree/master/exlear...
- pjmlp 3y agoThat pretty much describes my Tcl experience in the first Internet wave, to the point I only care for languages with good JIT/AOT tooling in the box, leaving the rest for scripting activities.
- AlchemistCamp 3y agoAs of OTP25, released last year, Erlang has JIT.
- pjmlp 3y agoTrue, but without trying to move goalposts, the JIT still lacks the numerics support for machine learning.
- eggy 3y agoI bought and I was working through the book, "The Handbook of Neuroevolution Through Erlang", 2013 Edition, several years ago, and then I tried to do the exercises in LFE (Lisp Flavoured Erlang). I am more a Lisper than a Rubyist, however, I do like Elixir. Gene Sher author of the book makes a great case for Erlang and ANNs and the book even has a preface by Joe Armstrong. I played with LUSH (Lisp Universal SHell) by Yann LeCun and others[1]. I wish they would have continued with Lisp too instead of moving to Python. Personally, I am now more an APL/J fan and the language being array based suits matrix math for ANNs very well. There are some nice papers that showcase this. I'd like to see advances in APL for ML. I am currently playing with April (Array Programming Re-Imagined in Lisp)[2] to scratch this itch. It gives you the general programming of Lisp to do the regular programming and APL to do the number crunching and matrix magic in terse code. I get how array languages such as APL suit ML, and distributed languages such as those which run on the BEAM (I am now looking at Gleam, an ML-like language that runs on the BEAM. I prefer the syntax to Elixir's the same way I tried LFE first) and seem to fit ML. Python's angle is that it utilizes C/Fortran libs like LAPACK and BLAS and hooks to do what it does in ML, and Elixir's Nx is similar in that sense to get the performance in number crunching that the BEAM languages are horrible at. You can use Zig now to write NIFs for Erlang/Elixir so maybe this is how Elixir moves in the direction of Python's approach to speeding up the number crunching for ML along with Nx. I prefer to try and use a more suitable language rather than try to make it work like Python/Numba/Numpy/Pandas and Elixir/Nx do. Funny thing is that Pandas by Wes McKinney was inspired by the J programming language. So I think you may not be with the crowd in my approach, but there is some harder-to-reach fruit in this approach that is more rewarding to me, and sometimes for others. [1] https://lush.sourceforge.net/ https://lush.sourceforge.net/ [2] https://github.com/phantomics/april https://github.com/phantomics/april
- JonChesterfield 3y agoMachine learning, not metalanguage. Disappointing. Yes, downvotes. ML used to mean the language which would be a worthwhile thing to render on the Erlang VM.