News for hackers. Stuff that matters.
Re:State of Machine Learning in Julia by faisal_ksa on Wednesday January 12, 2022 @03:46AM (#29903894)
I'm really rooting for Julia to improve its ML ecosystem. Julia is a JIT-compiled language that has the potential to become the all-encompassing solution for AI/ML/Data Science. I think their motto was "Walk like Python, Run like C." This could help to implement all their libraries in Julia instead of what is happening in Python (e.g., PyTorch is written in C++). I want to be clear; Python will be the go-to language for AI/ML for the foreseeable future. And It's a great language, but Julia is a breath of fresh air.
Re:State of Machine Learning in Julia by hiptobecubic on Wednesday January 12, 2022 @09:10AM (#29906488)
Why is it a problem that python calls out to other languages as needed? It's not like it's obvious while you're using the library and the result can be, in fact, very fast.

The main benefit I can think of is that Julia could theoretically do whole-program optimization, but it doesn't and it doesn't model side effects so even if it wanted to it would be quite limited.

Re:State of Machine Learning in Julia by socialdemocrat on Wednesday January 12, 2022 @09:33AM (#29906745)
It matters to package developers. If you can develop packages in Julia rather than in C++ you can move much faster. Also in Julia users of a package can much more easily contribute. A Python programmer cannot easily jump in an fix or add things to a package mostly written in C++.

Also writing packages in C++ creates a fair amount of friction. Combining packages becomes easier. The ML world in Julia allows a lot more code sharing while in Python PyTorch and TensorFlow are large monoliths. E.g. different ML packages in Julia can use the same library of activation functions. Each ML library is not a completely different island of functionality.

Re:State of Machine Learning in Julia by amkkma on Wednesday January 12, 2022 @09:12AM (#29906514)
There are innumerable benefits that the compiler gets from being able to see into functions. Codegen, AD, fusion, inlining, user defined arrays and element types being first class etc
Re:State of Machine Learning in Julia by sundarurfriend on Wednesday January 12, 2022 @09:56AM (#29907111)
One benefit from the user's side that I've experienced is that, when debugging, I can go as far into the call stack as I want or need, using the same tools I use to inspect my own Julia code and read things in the same language throughout - no jarring context switch. This helps significantly with building a complete mental model of what you're debugging, and with ruling out a whole class of potential issues at or beyond the language border.
Re:State of Machine Learning in Julia by snicker7 on Wednesday January 12, 2022 @09:51AM (#29907032)
There a lot of cases in scientific computing where using "glue code" of any sort can kill performance. You miss compile-time optimizations that can perform whole-program analysis.

As a result, despite Julia being very FFI-friendly, the Julia community is trying to move towards a "pure Julia" ecosystem. Sometimes this attitude makes sense (Julia-native BLAS), other times not (Julia has no HTTP/2 packages).

Re:State of Machine Learning in Julia by WanderPanda on Wednesday January 12, 2022 @12:33PM (#29910038)
If it is all one language you can have very nice code-sharing. Imagine a function that takes some matrices and does some operation on them. If you now want to execute this function on a GPU you can just swapt the matrix type to GPU matrices and as long as you implement kernels for all the operators the function uses the function can be executed on the GPU without any modification. This modularity removes the requirement for each package that wants to use GPUs to recreate and ship their own numpy-like implementation (like Tensorflow, PyTorch etc.).
Re:State of Machine Learning in Julia by ska on Wednesday January 12, 2022 @02:46PM (#29911864)
> Why is it a problem that python calls out to other languages as needed?

There is not problem if a) someone has written that code in the other language already and b) it works correctly.

But it's harder to build, modify and debug these things, generally. Glue code is useful, but it definitely has a cost.

Re:State of Machine Learning in Julia by xaxaxb on Wednesday January 12, 2022 @08:24AM (#29906017)
Add me to the club. I'm rooting for Julia for ML as well.
Re:State of Machine Learning in Julia by enriquto on Wednesday January 12, 2022 @04:18AM (#29904096)
> I think their motto was "Walk like Python, Run like C."

I was also seduced by the concept of "octave, but with fast loops". This is really all that was needed. But I'm a bit disenchanted by the "advanced" additional features of Julia that add (unnecessary, in my view) complexity to the language. All that multiple-dispatch stuff, all those arbitrary types. I would love a compilation option that forced everything to be of the same type (a multi-dimensional array of numbers), and then it could really run like C, including compilation time.

Re:State of Machine Learning in Julia by jstx1 on Wednesday January 12, 2022 @04:27AM (#29904163)
Multiple dispatch is the main feature that makes everything else possible, not some additional feature that spoils things.
Re:State of Machine Learning in Julia by enriquto on Wednesday January 12, 2022 @04:45AM (#29904269)
I disagree with the word "everything" in your sentence. If all you want to do is numeric computations, you just want a sort of "modern fortran" that compiles and runs fast. No need for multiple dispatch here. Julia almost is this language, if it wasn't for the multiple dispatch thing whose only effect is to slow the compilation (when all you have is the same numeric type).
Re:State of Machine Learning in Julia by jhgb on Wednesday January 12, 2022 @06:03AM (#29904795)
> you just want a sort of "modern fortran" that compiles and runs fast

Well...if you want Fortran, you know where to find it? Fortran still compiles and runs fast. Just use Fortran, then? It's a perfectly fine language.

> if it wasn't for the multiple dispatch thing whose only effect is to slow the compilation (when all you have is the same numeric type).

How does multiple dispatch in Julia slow things down when in Julia (unlike, say, in CLOS) it's basically restricted to generating monomorphic functions on demand? If "all you have is the same numeric type" then only one version of a polymorphic function will get generated and that's as fast as generating code, say, for an equivalent monomorphic function in C.

Re:State of Machine Learning in Julia by sharikous on Wednesday January 12, 2022 @06:19AM (#29904889)
Exactly. Fortran is fine and it has many advantages over Julia. It's not only the legacy code.

For one Julia needs an humongous runtime. I can see in the future a compiler from a Fortran number crunching routine to a webassembly SIMD-ready kernel. Julia in the browser is still a failure and not for a lack of effort. Fortran is much simpler to do.

I tried to work in Julia and it has a whole lot of hidden annoying things, undocumented nuances, etc...

I find myself wishing for a language between bare-bones Fortran and big-but-buggy Julia but I know it won't happen since the community is too small

Re:State of Machine Learning in Julia by jhgb on Wednesday January 12, 2022 @06:28AM (#29904957)
> For one Julia needs an humongous runtime.

To be fair, Julia needs that runtime precisely to generate compiled versions of polymorphic functions at run time, so as not to cause a combinatorial explosion of n-ary functions. Also, for interactivity, which includes adding new functions at run time. These are problems that Fortran isn't even trying to solve, so it's not quite fair to complain that Fortran doesn't require a runtime that solves them. But of course there seems to be a market for a way to generate a static binary for a Julia program under a closed world assumption that wouldn't require embedding a complete JIT compiler into the process.

Re:State of Machine Learning in Julia by amkkma on Wednesday January 12, 2022 @09:00AM (#29906358)
Ask and you shall receive:https://github.com/JuliaLang/julia/pull/41936

That giant runtime enables all sorts of features that are used by unparalleled julia packages.

Soon TM you'll be able to emit runtime free static binaries if you don't need the dynamism. In fact, that's what the GPU compiler does already

Re:State of Machine Learning in Julia by socialdemocrat on Wednesday January 12, 2022 @09:35AM (#29906777)
Huh? Multiple-dispatch is what makes the language really shine. I miss it in pretty much every other language I use. I am utterly puzzled by how you can see this killer feature as a downsides.

Single dispatch is an arbitrary restriction which should not exist. It only exists in most languages as a performance optimization because until Julia came along nobody could do multiple dispatch fast.

Re:State of Machine Learning in Julia by Someone on Wednesday January 12, 2022 @11:25AM (#29908774)
> until Julia came along nobody could do multiple dispatch fast

Is that correct/can you give a reference? Reading https://en.wikipedia.org/wiki/Multiple_dispatch#Use_in_pract..., julia uses it more in its standard library, but I don’t find indication that Julia is doing multiple dispatch better than, say, CLOS (https://en.wikipedia.org/wiki/Common_Lisp_Object_System) or Cecil (https://en.wikipedia.org/wiki/Cecil_(programming_language)).

Re:State of Machine Learning in Julia by fault1 on Wednesday January 12, 2022 @01:44PM (#29911113)
How about Dylan? :-)

I think one of the nice thing about Julia's "just ahead of time" monomorphization/devirtualization is that it allows a level of dynamism that also works on GPUs/TPUs. This post and linked paper help me understand a little bit of it: https://discourse.julialang.org/t/julia-inference-lattice-vs...

Is this level of dynamism required for conventional ML? Probably not. For physics-informed ML and probabilistic languages? Probably more likely.

Re:State of Machine Learning in Julia by adgjlsfhk1 on Wednesday January 12, 2022 @11:45AM (#29909170)
TLDR is Julia does a much better job than previous systems of de-virtualizing multiple dispatch. Most earlier systems (definitely CLOS, not sure about Cecil) allowed types of dispatch that were very hard to remove at compile time. When combined with Julia's willingness to generate lots of code, this means that most programs in Julia don't have significant amounts of dynamic dispatch which new.
Re:State of Machine Learning in Julia by Someone on Wednesday January 12, 2022 @12:00PM (#29909438)
So, where’s the long version? I can believe generating more code is cheaper now that we have gigabytes of memory, but does that make things faster, given that more code ≈ more cache misses?

Also, what types of dispatch does Jukai disallow that others allowed?

Just curious.

Re:State of Machine Learning in Julia by ChrisLomont on Wednesday January 12, 2022 @01:36PM (#29911025)
>given that more code ≈ more cache misses

More code isn't randomly jumped around in, so there are not necessarily (or in practice) more cache misses. Hot paths in Julia compile down better than in many other languages (including C/C++/FORTRAN, where aliasing is much more of a problem), specifically since multiple dispatch gets resolved as much as possible (and often completely) at compile time.

If anything, by making per type versions of things, there are less cache misses since things that are similar stay together, needing less instructions on hot paths to look up types and do other stuff that other systems do hit.

The proof is in the pudding - write (or find) some good code doing similarly complex things, and test them. Julia has C/FORTRAN speeds (and better) for a lot of important tasks, with the development flexibility of Python.

Re:State of Machine Learning in Julia by adgjlsfhk1 on Wednesday January 12, 2022 @12:45PM (#29910216)
CLOS has :before, :after, and :around qualifiers which Julia doesn't support, and CLOS supports multiple inheritance. Both of these make de virtualization much harder.

https://arxiv.org/pdf/1411.1607.pdf is a pretty good general resource for info about Julia's design decisions and has a section on multiple dispatch.

The reason that generating more code can be faster is that more code can actually result in fewer cache misses. Julia is so fast because it is really good at inlining, constant prop, and automatic vectorization. These optimizations all increase the amount of generated code, but remove conditionals that decrease code locality.

Re:State of Machine Learning in Julia by johnbcoughlin on Wednesday January 12, 2022 @12:16PM (#29909733)
Addressing the first point: It certainly does make it faster on the happy path. Instruction cache performance is not a major concern when you're running in a tight loop.
Re:State of Machine Learning in Julia by enriquto on Wednesday January 12, 2022 @10:32AM (#29907722)
> I am utterly puzzled by how you can see this killer feature as a downsides.

It depends on the usage that you make of the language. I don't use Julia as a general-purpose programming language, but only for doing numeric computations. For that usage, the multiple dispatch feature is not necessary (all my variables are matrices of the same numeric type), and indeed it has downsides. For example, the infamous "time to first plot" is so large in Julia precisely due to the need to support multiple dispatch. If this benchmark is becoming faster is only due to a huge and complex effort in optimization. I would prefer if this effort could be spent in improving support for sparse matrices, for example.

I acknowledge that "time to first plot" may be a useless benchmark for many, even for most, people. But you can also acknowledge that multiple dispatch is a useless feature for a few graybeards like me, for whom multiple dispatch is the main reason why Julia feels slow. Indeed, when you use Julia as an interpreted language (e.g., write a Julia script), execution is very slow due to the complexities introduced by multiple dispatch, that force essentially to recompile all libraries upon each execution of my tiny script.

Re:State of Machine Learning in Julia by adgjlsfhk1 on Wednesday January 12, 2022 @10:45AM (#29907958)
Multiple dispatch isn't useless for you. It's the reason the numerics are so good even when everything is the same type. Multiple dispatch makes it way easier to write generic code which means that all the libraries you use are about 10x easier to write.
Re:State of Machine Learning in Julia by ChrisRackauckas on Wednesday January 12, 2022 @11:18AM (#29908628)
Their point is that they're not trying to write generic code. In that case, Julia should act like an interactive Fortran, which would be nice, but then it needs to fix latency and binary building for the "this is pure Float64 and we know it" case. The only gain one really gets here is that type inference means you can write a bit simpler code, but that's not a huge win. That's a valid criticism that should hopefully be addressed soon, with https://github.com/JuliaLang/julia/pull/41936 being one of the biggest steps to getting there, along with the more precompilation stuff.
Re:State of Machine Learning in Julia by ted_dunning on Wednesday January 12, 2022 @08:38PM (#29915724)
Chris,

Not to second-guess you (you know far more about Julia than I) but my experience is that people who think that their code is completely uniformly typed still win massively from Julia.

It starts with "just dense matrices with Float64" and then, like the poster above, "but with some nice sparse matrix support" and then "oh and special handling for Vandermonde matrices", "oh and tridiagonals" and eventually "my matrices are hyper-<mumble>-<mumble>-symmetric and I can compute vector dot products really fast". At that point, they have been using multiple dispatch for months without knowing it.

In my own case it was "I don't need multiple dispatch" until it was "oh... it surely is nice that the H3 geo-hashes work transparently with LibGEOS even though the underlying C libraries don't work together."

The point is that Julia makes using things work together far better than anything else I have seen. It even makes completely asocial C libraries talk to each other.

Re:State of Machine Learning in Julia by enriquto on Thursday January 13, 2022 @08:28AM (#29920496)
Thanks for your answer! I'm the one who sees everything as "just float matrices". Do you have a simple example of a numeric algorithm where multiple dispatch really makes an difference? (as opposed to simply allowing to pass different types of numbers to your functions). I have trouble imagining that.

In octave/matlab I can already use the "sum" function over dense and sparse matrices, but you wouldn't say that the language is multiple dispatch. It doesn't seem like a big deal. More importantly, I want the "sum" function to have exactly the same meaning regardless of the data type.

I abhor the idea of hiding algorithms into types, on a very fundamental level. Allowing an algorithm to behave differently depending on the type of the input data seems totally wrong to me. The famous Stefan Karpinski talk at JuliaCon 2019 is one of the most horrifying videos I've ever seen. I still wake up at night trembling and with cold sweat when I dream about this talk.

Re:State of Machine Learning in Julia by adgjlsfhk1 on Thursday January 13, 2022 @11:27AM (#29922592)
>I want the "sum" function to have exactly the same meaning regardless of the data type.

You really don't. If you have a sparse matrix, you don't want to spend 99% of your time adding zeros.

In general, the advantage of multiple dispatch is it means you can automatically get optimal algorithms for a variety of type combinations. To show why this matters, look at matrix multiplication. If you have a high level function that multiplies matrices, you want to call the appropriate BLAS function (for dense inputs). That function will be one of SGEMM,SSYMM,STRMM,DGEMM,DSYMM,DTRMM,CGEMM,CSYMM,CTRMM,ZGEMM,ZSYMM, or ZTRMM depending on the type (and element type) of matrix (this is a simplified example, in the real world you also might want to diagonal, banded, CSR, CSC, block, or any of 20 or so different matrix types). Without multiple dispatch, you have to either write a bunch of if-else statements to choose the appropriate one, or you just convert everything to a dense (and probably double precision) matrix first. The first one is totally un-maintainable, and the second one will make your program an order of magnitude slower when you ignore structure inherent to your problem. With multiple dispatch, you just call * and it does all the hard stuff for you.

The proof that multiple dispatch is necessary is that most numerics libraries that aren't in Julia make ad-hoc and slow implementations of it internally. For example, here is Pytorch's implimentation https://pytorch.org/tutorials/advanced/dispatcher.html

Re:State of Machine Learning in Julia by enriquto on Thursday January 13, 2022 @12:40PM (#29923865)
Thanks, here you presented an example that actually makes sense to me.

In case of octave/matlab, of course computing the sum() of sparse matrices does not traverse all the zeros. But the result is the same as if it did, just much faster. There are also many types of sparse matrices, I wonder how does it work internally, it must have a similar mechanism. Probably, since it is interpreted in real time, each time that the "sum" function is called, it checks the type of the arguments and it calls the appropriate function.

> most numerics libraries that aren't in Julia make ad-hoc and slow implementations

The word "slow" has a relative meaning here... if you take into account the time of the first compilation. For example, calling an octave script that performs a matrix product is faster than the equivalent julia script.

Re:State of Machine Learning in Julia by adgjlsfhk1 on Thursday January 13, 2022 @03:12PM (#29926144)
>the result is the same as if it did This isn't quite true. Differently ordered operations can lead to different results due to floating point math, but in general, the point of multiple dispatch isn't to produce different results for different types. The example from Stefan's talk does this when contrasting with operator overloading because it's easier to show a difference in results than a difference in performance.

I don't know the specifics of how Matlab/Octave do this, but you're probably right about runtime checks.

It's true that compilation time will make Julia slower than Octave for a single multiplication, but if you are doing a bunch of them (especially if they are small), Julia can perform the computations with much lower overhead since it doesn't have to do type checks for stable programs. Also, Julia lets you define specialized matrix types which can be asymptotically faster than Octave for specific circumstances. A great example of this is BandedBlockBandedMatrix from https://github.com/JuliaMatrices/BlockBandedMatrices.jl which are extremely useful solving of PDEs quickly, but aren't implemented in any of the other languages because they have to write all their dispatch systems manually for each algorithm.

Re:State of Machine Learning in Julia by ChrisRackauckas on Thursday January 13, 2022 @08:52AM (#29920722)
Oh I definitely agree with you, and I think the OP's response to this post starts to go into the subjective ergonomic feels territory that is just, well okay everyone feel differently. But there is a technical point that precompiling and building binaries for the simple Float64 case is a bit harder than it should be compared to C or Fortran, so there is still a reason to grab Fortran every once in awhile. It's not unfixable, but it's something we should acknowledge that we can improve.
Re:State of Machine Learning in Julia by Tarrosion on Friday January 14, 2022 @10:40PM (#29943320)
Can you say more about making H3 and LibGEOS work together?
Re:State of Machine Learning in Julia by celrod on Wednesday January 12, 2022 @11:18AM (#29908610)
I don't think latency is multiple dispatch's fault. Certainly, compilation caching failures aren't.
Re:State of Machine Learning in Julia by adgjlsfhk1 on Wednesday January 12, 2022 @11:48AM (#29909227)
It kind of is. Multiple dispatch means that a static binary has to deal with most of the downsides of heavily templated C++ code (but much worse since everything is templated). Fixing this is highly non-trivial.
Re:State of Machine Learning in Julia by simonbyrne on Wednesday January 12, 2022 @11:57AM (#29909394)
If that's seriously what you're looking for, you should really consider Fortran. There is a reason it is still very widely used in scientific domains.