News for hackers. Stuff that matters.
Re:Julia 1.7 Highlights by fault1 on Tuesday November 30, 2021 @10:10PM (#29400219)
I'm really excited about Julia 1.8 and diffractor: https://github.com/JuliaDiff/Diffractor.jl

Keno Fisher did a presentation in a discussion moderated by Simon Peyton Jones here: https://www.youtube.com/watch?v=mQnSRfseu0c

Also combined with enzyme which can differentiate through static paths at the llvm bitcode level: https://enzyme.mit.edu/

I wonder what this will enable at the frontier of what is computationally tractable in the combo of physics + ml.

Re:Julia 1.7 Highlights by plafl on Wednesday December 01, 2021 @01:23AM (#29401247)
Julia is the Haskell of numerical computing.

It seems like AD is a solved problem, which is not. I can personally think two instances in which I have hand rolled my own gradients: in the context of recommender systems (dense matrices are evil) and right now in the context of real time collision detection (memory allocations are evil).

One of the domains where I hope Julia will excel is precisely as you comment on physics + ml (I check frequently if MuJoCo source code is available at last).

Anyway, I encourage everyone with any background in scientific computing or DS to have a look at Julia. The ecosystem is nowhere near Python yet, but the language is very good and the tooling is getting better. The performance Julia provides without interfacing C/C++ or Fortran is not just a convenience, it has architectural consequences. It's not about of coding faster, it's about coding "further".

Re:Julia 1.7 Highlights by vletal on Wednesday December 01, 2021 @04:17AM (#29402127)
> The performance Julia provides without interfacing C/C++ or Fortran is not just a convenience, it has architectural consequences.

These statements set the expectations really high. Yet they omit the ugly truth of increasingly slow compilation times, pure compilation caching, JIT which might affect overall performance due to type instability.

Yeah, like Haskell has a nice Quick-sort example prominently displayed at the front page, Julia is sleek for scientific computing, yet it can bite you really bad as soon as you start wrapping the developed model into a real world REST app.

Do not get me wrong, I see some of the benefits of Julia. On the other hand, I do not think this uncritical hype about "coding 'further'" does good for the language.

Re:Julia 1.7 Highlights by DNF2 on Wednesday December 01, 2021 @05:59AM (#29402626)
Compilation times are still an issue, but what do you mean with 'increasingly slow' compilation times? As far as I know and can tell, compilation times have been getting faster not slower, and by a significant amount.
Re:Julia 1.7 Highlights by ChrisRackauckas on Wednesday December 01, 2021 @06:09AM (#29402664)
Let's even put raw numbers to it. DifferentialEquations.jl usage has seen compile times drop from 22 seconds to 3 seconds over the last few months.

https://github.com/SciML/DifferentialEquations.jl/issues/786

Re:Julia 1.7 Highlights by vletal on Wednesday December 01, 2021 @03:22PM (#29408676)
Yeah, I should not have used "increasingly", yet what you are pointing out is an example of an improvement in a single module, not the language compiler & llvm. It does not actually prove the original comment wrong.
Re:Julia 1.7 Highlights by ChrisRackauckas on Wednesday December 01, 2021 @06:51PM (#29410686)
Almost all of the improvements came from changes to Julia's Base that improved compilation times and changes to tooling which suggest trivial changes to improve compilation times. In v1.5 or so this would've been a heroic feat. In v1.7 this is something any undergrad could do in a weekend to any module. So yes that proves that things have changed quite a bit.
Re:Julia 1.7 Highlights by gugagore on Wednesday December 01, 2021 @04:51PM (#29409590)
It's not due to effort that is specific to a single module. It reflects an improvement in the community's understanding of what patterns causes slow compile times and also tooling that helps improve compile times by reducing method invalidations.

There may well have also been improvements in the Julia compiler.

Re:Julia 1.7 Highlights by klowrey on Wednesday December 01, 2021 @12:10PM (#29406235)
I manage the MuJoCo.jl wrapper, and having the source code wont (naively) help with AD. Internally, there's a number of iterative algorithms that you wouldn't want to automatically differentiate, and if analytical derivatives were apparent they would be in there (the MuJoCo creator was my advisor). As it stands, finite differencing is the best way to extract derivative/gradient information from the underlying physics model of MuJoCo, and is the suggested method.

We had a paper that included MuJoCo (with custom defined adjoints) within Julia's DiffEq framework to learn continuous control policies (https://arxiv.org/abs/2012.06684) which revealed a whole host of other issues, namely that gradients are not all that helpful when your optimization landscape is insanely non-linear. But that's a different problem.

Open to chatting about; Julia is definitely the tool for this kind of work.

Re:Julia 1.7 Highlights by ChrisRackauckas on Wednesday December 01, 2021 @01:13PM (#29407108)
> namely that gradients are not all that helpful when your optimization landscape is insanely non-linear

Did you try multiple shooting? https://diffeqflux.sciml.ai/dev/examples/multiple_shooting/

I want to restructure the docs because I have come to think that any non-trivial fitting problem requires multiple shooting in order to be stable. Otherwise the loss becomes dominated by "loss values calculated beyond where the simulation has already fallen off". So I'd like to dig into some of the non-fitting examples and see if this or some other tricks are the right answer.

Re:Julia 1.7 Highlights by plafl on Wednesday December 01, 2021 @03:30PM (#29408759)
I'm not thinking just about AD. I would love lots and lots of little simulation modules instead of monolithic solutions.

Now some uninteresting story: the reason to have a look at MuJoCo is personal: I studied Mechanics I, II and Analytical Mechanics at college and thought non-continuos mechanics a solved problem. When doing my masters thesis about helicopter simulation I needed at some point to model ground contact and I thought "easy, just add a damped spring". I feel that thesis was nice for an undergrad overall but that part as you can imagine was a complete and utter piece of crap. And now at my forties I want to have vengeance.

Re:Julia 1.7 Highlights by porker on Wednesday December 01, 2021 @02:25AM (#29401545)
> Julia is the Haskell of numerical computing.

Is that a compliment or an insult? When Haskell is involved I can never tell.

Re:Julia 1.7 Highlights by plafl on Wednesday December 01, 2021 @02:34AM (#29401596)
Me neither, and yet I maintain my opinion.
Re:Julia 1.7 Highlights by vanderZwan on Wednesday December 01, 2021 @04:00AM (#29402047)
That's because Haskell is like the programming language equivalent of The Gig That Changed The World[0], although I guess Algol60 also has a strong claim to that title.

Let me explain by quoting these paragraphs Roger Ebert's review[1] of 24h party people:

> As the film opens, Wilson is attending the first, legendary Sex Pistols concert in Manchester, England. (...) Wilson is transfixed by the Pistols as they sing "Anarchy in the U.K." and sneer at British tradition. He tells the camera that everyone in the audience will leave the room transformed and inspired, and then the camera pans to show a total of 42 people, two or three of them half-heartedly dancing in the aisles.

Sounds like the average language designer entranced and inspired by their first time grokking Haskell.

> Wilson features the Pistols and other bands on his Manchester TV show. Because of a ban by London TV, his show becomes the only venue for punk rock. Turns out he was right about the Pistols. They let loose something that changed rock music. And they did it in the only way that Wilson could respect, by thoroughly screwing up everything they did, and ending in bankruptcy and failure, followed by Sid Vicious' spectacular murder-suicide flameout. The Sex Pistols became successful because they failed; if they had succeeded, they would have sold out, or become diluted or commercial. I saw Johnny Rotten a few years ago at Sundance, still failing, and it made me feel proud of him.

I could rephrase that last sentence at "I checked out a contalk by Simon Peyton Jones from a few years ago, still avoiding success at all costs[2], and it made me feel proud of him" and it would be absolutely true.

And no, I also did not expect to find a parallel between Haskell and punk music, but there you go.

[0] https://openculture.com/2015/06/the-sex-pistols-1976-manches...

[1] https://www.rogerebert.com/reviews/24-hour-party-people-2002

[2] https://www.youtube.com/watch?v=re96UgMk6GQ&t=1372s

Re:Julia 1.7 Highlights by sireat on Wednesday December 01, 2021 @09:11AM (#29403724)
I wonder what language would be considered post-punk?

Scala (experimenting with various styles) comes to mind.

How about proto punk? Something like ML?

Re:Julia 1.7 Highlights by Gatsky on Wednesday December 01, 2021 @05:17AM (#29402402)
This is the best HN comment I have seen for quite some time.
Re:Julia 1.7 Highlights by vanderZwan on Wednesday December 01, 2021 @08:49AM (#29403582)
If you watch the linked SPJ video, I timestamped it at the moment where he explains what he means with "avoiding success at all costs", but also: if you watch a bit longer he shares the story of a GHC compiler bug where if you compiled a module on windows, and in a different directory than the current directory, and it contained a type error... it would tell you there was a type error, and then delete the source file.

And instead of people going berserk over this, all he got was some friendly emails from people who just wanted to inform him they bumped into this problem, but it's fine, they had a workaround. Because Haskell people in those days were used to Breaking changes with a capital B.

I think that's at least a little bit punk

Re:Julia 1.7 Highlights by plafl on Wednesday December 01, 2021 @10:19AM (#29404474)
> it would tell you there was a type error, and then delete the source file

Which makes all the sense because Haskell is about avoiding bugs at compile time

Re:Julia 1.7 Highlights by gostsamo on Wednesday December 01, 2021 @01:40AM (#29401329)
I think I have a good news for you. Deep mind acquired and open sourced the project a few months ago.

https://github.com/deepmind/mujoco

Re:Julia 1.7 Highlights by plafl on Wednesday December 01, 2021 @02:33AM (#29401591)
I know, I know, but the source code is not yet available. The github repo is a placeholder for now
Re:Julia 1.7 Highlights by pjmlp on Wednesday December 01, 2021 @02:16AM (#29401498)
I thought Julia is the Dylan of numerical computing. :)
Re:Julia 1.7 Highlights by ChrisRackauckas on Wednesday December 01, 2021 @06:08AM (#29402658)
>One of the domains where I hope Julia will excel is precisely as you comment on physics + ml (I check frequently if MuJoCo source code is available at last).

Somebody already did a comparison of DifferentialEquations.jl's standard usage against MuJoCo and DiffTaichi and showed that it outperformed them by about 5x-10x.

https://arxiv.org/abs/2012.06684 https://homes.cs.washington.edu/~thickstn/ctpg-project-page/...

That's all showing the raw iteration count to show that it algorithmically is faster, but the time per iteration is also fast for many reasons showcased in the SciMLBenchmarks routinely outperforming C and Fortran solvers (https://github.com/SciML/SciMLBenchmarks.jl). So it's excelling pretty well, and things like the automated discovery of black hole dynamics are all done using the universal differential equation framework enabled by the SciML tools (see https://arxiv.org/abs/2102.12695 for that application).

What we are missing however is that, right now these simulations are all writing raw differential equations so we do need a better set of modeling tools. That said, MuJoCo and DiffTaichi are not great physical modeling environments for building real systems, instead we would point to Simulink and Modelica as what are really useful for building real-world systems. So it would be cool if there was a modeling language in Julia which extends that universe and directly does optimal code generation for the Julia solvers... and that's what ModelingToolkit.jl is (https://github.com/SciML/ModelingToolkit.jl). That project is still pretty new, but there's already enough to show some large-scale models outperforming Dymola on examples that require symbolic tearing and index reduction, which is far more than what physical simulation environments used for non-scientific purposes (MuJoCo and DiffTaichi) are able to do. See the workshop for details (https://www.youtube.com/watch?v=HEVOgSLBzWA). And that's just the top level details, there's a whole Julia Computing product called JuliaSim (https://juliacomputing.com/products/juliasim/) which is then being built on these pieces to do things like automatically generate ML-accelerated components and add model building GUIs.

That said, MuJoCo and DiffTaichi have much better visualizations and animations than MTK. Our focus so far has been on the core routines, making them fast, scalable, stable, and extensive. You'll need to wait for the near future (or build something with Makie) if you want the pretty pictures of the robot to happen automatically. That said, Julia's Makie visualization system has already been shown to be sufficiently powerful for this kind of application (https://nextjournal.com/sdanisch/taking-your-robot-for-a-wal...), so we're excited to see where that will go in the future.

Re:Julia 1.7 Highlights by ssivark on Wednesday December 01, 2021 @01:45AM (#29401350)
MuJoCo was purchased by Deepmind and open-sourced, a few weeks ago: https://deepmind.com/blog/announcements/mujoco
Re:Julia 1.7 Highlights by a-dub on Wednesday December 01, 2021 @12:35AM (#29401034)
this talk and the referenced pair talk by matt bauman were really excellent.

basically the big takeaway that i walked away with was that they defined a sort of pseudoclosure in the guts of the language before the compiler which relaxes some of the behaviors of a closure (ie what gets captured) which then enables the creation of larger optimizable regions for the compiler in the context of doing autodiff.

the demo by matt bauman where they do autodiff on a function that prompts for and has the user type in the name of another julia mathematical function was really impressive!

Re:Julia 1.7 Highlights by KenoFischer on Wednesday December 01, 2021 @01:00AM (#29401141)
> basically the big takeaway that i walked away with was that they defined a sort of pseudoclosure in the guts of the language before the compiler which relaxes some of the behaviors of a closure (ie what gets captured) which then enables the creation of larger optimizable regions for the compiler in the context of doing autodiff.

Yes! That's essentially correct.

Re:Julia 1.7 Highlights by 22c on Tuesday November 30, 2021 @10:20PM (#29400280)
If anyone else is wondering what the AD stands for in "Next Generation AD" it's "algorithmic differentiation".
Re:Julia 1.7 Highlights by suchow on Tuesday November 30, 2021 @10:23PM (#29400293)
Also known as automatic differentiation or autodiff.
Re:Julia 1.7 Highlights by savant_penguin on Tuesday November 30, 2021 @11:23PM (#29400646)
What's special about this compared to other ADs?

Reading the front page it seems to focus on efficient higher order derivatives, is that it?

Re:Julia 1.7 Highlights by KenoFischer on Wednesday December 01, 2021 @12:43AM (#29401071)
Diffractor solves a couple of issues that are inter-related. I'm gonna contrast with Zygote which is the current "standard" AD in Julia and the most fancy one we have (though there are a couple other AD packages that are useful in certain situations that Zygote is bad at - Diffractor will cover some of these but not all).

Essentially, what Zygote does is insert itself into the compiler pipeline at the lowered code stage to perform the AD transform. That is it operates on the form of Julia code before we perform any type analysis, devirtualization or optimizations. Essentially, you can think of Zygote as a lisp-style macro applied automatically/dynamically to every function being called starting at a particular entry point. This works pretty well, but has a couple limitations.

The first is that it has absolutely no semantic information available (since it operates on non-inferred code), so it can't use that for optimizations or things like data layout planning, which are important optimizations for a production-grade AD system. Essentially, it's not allowed to know that the `+` symbol it sees is actually the `Base.+` function that does addition, so must make the most pessimistic assumptions. This issue doesn't actually show up that much in machine learning use cases, but it's a big issue when you need to AD scalar code (which happens frequently in various differentiable programming contexts).

The next issue with running at this stage is that a lot of existing julia code is written with some mental model of the capabilities of type inference and the optimizer. For example, destructuring code like `a, b = f(x)`, people don't think about at all, but semantically that allocates several tuples and then indexes into them to take them apart. By running the AD transform, you basically double (at least), the complexity of every operation, so in a number of cases patterns that used to completely optimize away are now terribly slow, because they are no longer optimized (and then AD transformed on top of that).

A related issue is that because you cannot interleave optimization with the AD transform, if you want to perform nested (i.e. higher order) differentiation, you're gonna get exponential code generation, which you then have to hope the optimizer will cut down again for you, which it often can't all the way, but even if it could, generating exponential code in the first place is bad, because you're gonna wait an exponential amount of time for the compiler to be done with it (and super-exponential in practice, because the compiler is not linear in the size of the input problem), so Zygote is basically unusable for anything beyond second order (and even at second order is a struggle).

Lastly, there is also a technical issue, which is that code that operates on lowered IR isn't technically allowed to build any closures, but the AD transform has to do that in order to put the code for the backwards pass somewhere. Zygote gets around this by taking advantage of the fact that the AD transform is pure, so it basically runs everything twice (once to generate the forward pass, once to generate the backwards pass when execution gets to it) and it knows that things match up because the input code is the same. That mostly works, but this dependency isn't visible to the runtime system, so you can get into issues where code is updated in between the forwards and the backwards pass, which breaks Zygote in all sorts of ways.

Anyway, Diffractor is designed to fix all of this by "simply" moving the AD transform stage from lowered IR to post-inference (where the optimizer sits). The issue is that Julia the language, currently doesn't really allow semantic transformations post inference (after all optimizers are supposed to make things faster, but not change the outcome of things) and in particular, running optimizers is always optional and the language may choose not to do it. So to get there, we need to do a couple of things:

1. We need to have some sort of wedge into the semantics of the language that allows for optimization-time changes that are semantic. For this, I added `OpaqueClosures`, which are essentially like regular closures, except that they do not have semantics as to their capture lists or the code that they run. Now, this may be confusing to people from some functional languages where all closures have such semantics (you can see SPJ ask this question in the linked discussion we had - didn't think about it ahead of time, because I'm so used to our semantics, so my answer was a bit muddled), but essentially in Julia, the contents of closures is semantically visible and optimizations over closure boundaries are mostly prohibited, because ordinary closures do not close over the world age (i.e. if you have `f = x->sin(x)` and then say `sin(x) = 9999`, then the next execution of `f` will return 9999). So opaque closure basically change this and say "nothing in the system is allowed to look at the code they contain, or the capture list, and also we capture the world age". More importantly though, we now have a datastructure (the capture list of an opaque closure) that is allowed to be changed by the optimizer, so we drive basically drive a truck through that.

2. We need the actual mechanism to move the transform to inference time. This isn't super hard, but we haven't quite finished this yet, and it's something I'm hoping to get to over the next couple of months. It's somewhat intertwined with making the compiler in general more accessible to packages outside the core language. There's about 8-10 different packages that want to do compiler-y things on Julia IR and we really need to figure out a good solution to make that generally possible. But as always, designing core language APIs is a bit tricky, because you're gonna be stuck with them for a while.

There's also some other nice bits and pieces in Diffractor. The big one is that I did a fair bit of theoretical exploration at the top of this project to really understand higher order AD. When I first took differential geometry (10 years ago now), I used to joke with my classmates that I had no idea what a second derivative was, because all the textbooks basically just say "look, the tangent bundle of a smooth manifold is a smooth manifold" and never actually really go into higher order derivatives at all. Anyway, I really sat down to work all that out and in the course of that I came across a way to do higher order derivatives more efficiently (under suitable assumptions of what the compiler does) than just nesting the first order transform. In retrospect, it seems pretty obvious, but I can honestly say that I didn't think about that until I worked out the theory. In the course of it, I also managed to make very precise the notion that reverse-mode AD and pullbacks of cotangent vectors are the same thing. This connection was pretty well known in the oral tradition, but I never really saw a convincing writeup of it (and my result extends to higher orders of course).

Other than that, it directly uses ChainRules.jl as its AD rule system, where Zygote used to keep its own rules (Zygote and ChainRules developed concurrently, and Zygote was later adapted to look in both places, but its a bit of a mess) and it also has a unified forward mode that (in theory, once it's robust enough), subsumes both ForwardDiff.jl and TaylorSeries.jl.

In theory, this should all make for a pretty good AD system, but there's a fair bit of work still to be done to make it robust (though all the pieces except the julia-level mechanism for actually moving the AD pass are done and tested) and as always, time is very limited :).

Re:Julia 1.7 Highlights by adgjlsfhk1 on Wednesday December 01, 2021 @12:54AM (#29401120)
This is a great writeup. Any chance it can end up in a blog post?
Re:Julia 1.7 Highlights by KenoFischer on Wednesday December 01, 2021 @12:58AM (#29401133)
Maaayybee ... Writing a blog post always seems like a time commitment, and I really should be doing other things ;). Somehow sequeezing in a big HN comment while I'm waiting for my builds to go through doesn't feel like the same, but I'm probably just deluding myself ;).
Re:Julia 1.7 Highlights by TTPrograms on Wednesday December 01, 2021 @01:28AM (#29401268)
I've been investigating Julia AD recently - really hoping for arbitrary code diff, but nothing really works right now.

How broad will Diffractor's support of the language be? E.g. will it support mutation / exceptions / recursion?

Re:Julia 1.7 Highlights by KenoFischer on Wednesday December 01, 2021 @01:39AM (#29401322)
Mutation is tricky, because basically the only way to do it sanely is to copy all data into the residual, but since most arrays aren't actually mutated, that's extremely wasteful. I've been hoping to address this by changing mutability in the language more generally (e.g. https://github.com/JuliaLang/julia/pull/42465) to make immutable arrays the default at which point there wouldn't be a penalty anymore. I've had request to do the mutable copying optionally, but it's a bit tricky, because it needs rule system integration and the rule system currently doesn't reason about mutation.

As for exceptions and recursion, shouldn't be a problem, just needs to be implemented.

Re:Julia 1.7 Highlights by TTPrograms on Wednesday December 01, 2021 @11:53AM (#29405936)
Thanks for the reply!
Re:Julia 1.7 Highlights by huitzitziltzin on Wednesday December 01, 2021 @07:36AM (#29403093)
As a julia user of five-ish years one of my favorite things that you guys do is write really in depth blog posts which I can read ten times and try to puzzle out.

I am sure they take a huge amount of work but my appetite for them has never been satisfied!

Re:Julia 1.7 Highlights by adgjlsfhk1 on Tuesday November 30, 2021 @11:29PM (#29400680)
The basic answer is it (similar to enzyme) is hooked into a compiler so it can optimize before and after AD. This is important because the typical approach can lead to code that is much harder for the compiler to optimize.
Re:Julia 1.7 Highlights by whimsicalism on Tuesday November 30, 2021 @11:37PM (#29400720)
It would be awesome to get library/macro support for something like this in Rust.. it's llvm so theoretically should be able to hook in?

I've always thought that AD needs something akin to a "compile" step.

Re:Julia 1.7 Highlights by nestorD on Wednesday December 01, 2021 @05:53AM (#29402585)
The Enzyme team has been doing something like that (AD at the LLVM step making it available to all LLVM languages) with Rust:

- https://internals.rust-lang.org/t/automatic-differentiation-...

- https://github.com/rust-ml/oxide-enzyme