Better HN
topnewbestaskshowjobs
Log inSign up

LightMachine

2,083 karma · joined Sep 27, 2015 (11y ago) · 346 submissions

Submissions

comment 3y ago · link · parent

Well, it should be a viable alternative to GHC once we implement full lambdas, but without them, it should be seen as a separate language, just like Rust.

The complete subset of lambda terms that HVM can soundly evaluate hasn't been identified yet. It is known that HVM can, at least, soundly evaluate all terms typeable on Elementary Affine Logic (EAL), but, while that is a huge set, it isn't comprehensive, as HVM can evaluate many terms outside of EAL, including recursive terms such as the Y-Combinator.

comment 3y ago · link · parent

I think this kind of sentence makes such a huge disservice for the HVM. Rust closures also doesn't support the full λ-calculus! HVM supports way more λ-terms than Rust does. That said, we're working on full λ-calculus support, so this shouldn't be a problem soon.

comment 3y ago · link · parent

Very well written and beautiful article.

comment 3y ago · link · parent

I feel like no less than 10 years if the singularity doesn't kick in before that. Hardware and energy isn't progressing as fast as we'd like, and that is the main bottleneck. As in, imagine a world where we actually had the same computing power required to train (not run) GPT-4 in 1s in a phone? That kind of world is way beyond AGI and the cure of cancer IMO. Which is great, because it gives us a very objective goal to achieve these things. Sadly, I don't think we're nowhere near that. What was even the total energy consumption of GPT-4 training? Very hard to imagine computers will get that much better anytime soon. IIRC we have some kind of data that the a smartphone today has the power of the best supercomputer... of 30 years ago, right? Don't remember the source, sadly.

comment 3y ago · link · parent

I agree with most of your points, we should definitely rewrite and tone down the README. The FAQ was written a few months after, due to that kind of negative reception. To address your points, note that by "superseding" the Turing Machine, I do not mean they can compute uncomputable functions! The meaning is that, while both are equivalent in terms of *computability*, Interaction Nets have improved *computational* characteristics, such as strong confluence and concurrency. This is a very technical aspect that is addressed on the paper I linked. Regarding not buying the claim of no GC needed, this is interesting, since this is a well stablished result: HVM is entirely linear, so it can avoid global GCs for the same reason as Rust. The difference is that HVM is more inherently high level, since its support for lambda is way more first-class than Rust's closures, which are comparably slow and almost guarantee borrow-checker hell.

comment 3y ago · link · parent

Inpla is a very interesting project that is more elegant than HVM in several regards (as it doesn't need to worry about functional programming!) and should be more known. I've added a link to it from the HVM's repo a few months ago.

comment 3y ago · link · parent

Eventually, definitely, but less likely for this round.

comment 3y ago · link · parent

I love WASM - who doesn't? Maintaining a WASM target was included on HOC's current fundraise, and is essential to our JIT plans. I don't know much about typed assembly, but I guess it would enable optimizations that aren't possible without types, as well as increased safety - although I wonder if that's relevant, if the source language is already typed?

In general though, I think we should move away from procedural instructions towards "interactional" instructions. HVM's AST can be seen as an assembly language with high-level instructions like LAM-APP (lambda application) and FUN-CTR (pattern-matching), and that's possible precisely because beta reduction is O(1) on interaction nets. A hardware with HVM's interactional instructions could make let us break out of the Von Neumann bottleneck and make processors much faster. Here is a table of HVM's core instructions:

    .-----------------------------------------------------.
    | Opcode    | Effect                          | Cost  |
    |-----------|---------------------------------|-------|
    | APP-LAM   | applies a lambda                | 2     |
    | APP-SUP   | applies a superposition         | 4     |
    | OP2-NUM   | operates on a number            | 2     |
    | OP2-SUP   | operates on a superposition     | 4     |
    | FUN-CTR   | pattern-matches a constructor   | 2 + M |
    | FUN-SUP   | pattern-matches a superposition | 2 + A |
    | DUP-LAM   | clones a lambda                 | 4     |
    | DUP-NUM   | clones a number                 | 2     |
    | DUP-CTR   | clones a constructor            | 2 + A |
    | DUP-SUP-0 | clones a superposition          | 4     |
    | DUP-SUP-1 | undoes a superposition          | 2     |
    | DUP-ERA   | clones an erasure               | 2     |
    |-----------------------------------------------------|
I think BlueSpec is impressive and a good direction in the (arguably messy) hardware language domain. It is likely that we'll consider using it in our research and projects.

comment 3y ago · link · parent

Yes! But first we want to implement some essential features, like full lambda support and some high priority optimizations. Once HVM is ready to support production software, we'll provide docs on how to best use it as a general compilation target. This will be announced in our Discord server: http://discord.higherorderco.com/

comment 3y ago · link · parent

Absal is just an early implementation and experiment. It is written in JS and not meant to be a production-ready runtime and general purpose compilation target. HVM has that goal. That said, Absal is a great repo to study and learn the theory.

comment 3y ago · link · parent

TBH, I'm somewhat of a Bitcoin maximalist too, which is kinda ironic since I hold no BTC; I guess the lack of expressivity of the network counters the big appreciation I have for its stable monetary policy and true decentralization. That's why, on HOC, I only accepted external funding under the conditions that Kindelia may not have a pre-mine - and am very glad to have found VCs that share this vision. (Kindelia is one of our internal projects, and is essentially Bitcoin with HVM-based contracts.)

To address your questions:

Yes, we have plans for GPU backends. In fact, I have even written a working prototype some time ago! It reduces λ-terms on the GPU using the same rules as HVM, with all the locks and atomics in place, and it seems to achieve a near ideal speedup, even with thousands of nVidia cores:

https://gist.github.com/VictorTaelin/e924d92119eab8b1f57719a...

That said, it is still just a single-file prototype. Sadly, we couldn't include a GPU backend on this funding round, but it is definitely something we'll be investing in a future, specially if we manage to grow as a company. Imagine writing pure Haskell functions and they run in thousands of GPU cores with no efforts? Pure functional shaders, physics engines...

Regarding PyTorch, I don't think HVM would be more efficient than it for ML, because PyTorch is already maximally optimized to use GPUs to their limit. HVM should be seen as a way to run high level programs in a massively parallel fashion without needing to write low level CUDA code yourself, but it won't outperform manually optimized CUDA on GPUs. That said, I do believe interaction net based processors would greatly outperform GPUs by breaking the Von Neumann bottleneck and unifying memory and computation in billions of nano-interaction-cores. I do believe such architecture could one day empower AI and make our LLMs and RNNs much faster.

comment 3y ago · link · parent

No, I mean that users should choose whether they use lazy cloning or immutable references when sharing arguments, just like you have the choice for several pointer types in Rust. I don't think compilers should make that decision, since I like to have full control over my program's runtime costs. When compiling a language like Haskell to HVM, we can just use references by default, and lazy cloning could be opt-in (using some newtype or similar).

comment 3y ago · link · parent

Predictability is one of the most exciting aspects of HVM, to me. That's because everything is linear, so time and space costs are completely measurable, in a way that resembles C, but even more profoundly. For example, in the following GitHub issue:

https://github.com/HigherOrderCO/HVM/issues/167

I discuss how HVM is able to perform deforesting, one of the core techniques that made GHC so fast, "for free" at runtime, without being explicitly hardcoded. That is great, but the point I'd like to make is how I show that: by measuring the 'rewrite count' of a program with HVM's '-c' flag. It shows you how many rewrites a program evaluation took. Since each rewrite is a constant time operation, this gives us a very precise metric of the complexity of a program.

On the issue above, I implemented two versions of the same function, and measured their rewrite counts. Here are the tables:

    Fn V1

    N | rewrites
    - | --------
    0 | 402
    1 | 802
    2 | 1202
    3 | 1602
    4 | 2002
    5 | 2402
    6 | 2802
    7 | 3202
    8 | 3602
    9 | 4002

    Fn V2

    N | rewrites
    - | --------
    0 | 1403
    1 | 1408
    2 | 1413
    3 | 1418
    4 | 1423
    5 | 1428
    6 | 1433
    7 | 1438
    8 | 1443
    9 | 1448
From these numbers, we can tell V2 scales better than V1, without doing any benchmark. Not only that, but we're able to write explicit formulas for the runtime cost of each version:

    TimeComplexity(FnV1(N)) = 402 + 400*N rewrites
    TimeComplexity(FnV2(N)) = 1403 + 5*N rewrites
Which means both are O(N), but V2 has a 80x smaller linear coefficient. This precision extends to memory and space too. This is why we're so excited to build Kindelia to apply HVM to the context of blockchain VMs, as this granular measurability isn't available on GHC, which is why Cardano can't use the Haskell compiler, and must resort to an interpreter, greatly affecting its throughput. Of course, this is just one of many the applications of the HVM.

comment 3y ago · link · parent

I'm working on improving my communication :(

comment 3y ago · link · parent

Of course! Let me write a complete overview on the subject. Consider the following program:

    (Foo a b) = (If a (F b) (G b))
It is easy to note that Foo makes an unnecessary clone of the 'b' variable, since it is used in different branches. This could be avoided by adding a lambda, as follows:

    (Foo a b) = ((If a λb(F b) λb(G b)) b)
That is what I mean when I said that, in most instances, cloning can be avoided by adding strategic lambdas. Now, in some cases, such as issue #60, this won't be possible. Issue #60 isolates a situation where lazy cloning is necessarily quadratic. Here it is:

    (Gen 0)             = Nil
    (Gen n)             = (Cons n (Gen (- n 1)))
    (Sum Nil)           = 0
    (Sum (Cons x xs))   = (+ x (Sum xs))
    (Tails Nil)         = (Cons Nil Nil)
    (Tails (Cons x xs)) = (Cons xs (Tails xs))
    (Heads Nil)         = Nil
    (Heads (Cons x xs)) = (Cons (Head x) (Heads xs))
    (Head Nil)          = 0
    (Head (Cons x xs))  = x
    Main                = (Sum (Heads (Tails (Gen 1000))))
What this program does: first, it converts a list like [1,2,3,4,5] into a list of where each element stores its tail: [[2,3,4,5],[3,4,5],[4,5],[5]]. Then, it takes the head of each element, resulting in [2,3,4,5]. Notice it is a very inefficient, roundabout implementation of 'tail', which happens to be quadratic on HVM, and linear on GHC. In this specific case, this could be fixed by just writing Tail as usual:

    (Tail (Cons x xs)) = xs
It is worth pointing out that this is the case in all examples where HVM is sub-optimal! That is, there is always an alternative algorithm that avoids unnecessary cloning. That said, of course, in more complex programs, it will be impossible to identify sub-optimal situations and fix automatically (unless supercompilers become practical). As such, it is important for HVM to be able to handle these programs without quadratic slowdowns. To understand how that could be accomplished, let's first note that the culprit of the quadratic slowdown is the way HVM handles a non-linear variable. On the line below:

    (Tails (Cons x xs)) = (Cons xs (Tails xs))
HVM's default behavior is to assume that, by writing `xs` twice, you meant to do a lazy clone. In other words, the program above is compiled as:

    (Tails (Cons x xs)) =
      let [xs_a, xs_b] = xs.lazy_clone()
      (Cons xs_a (Tails xs_b))
In order to work, lazy cloning adds a "fan node" to the program's graph, which uses space. That means that, if you perform a lazy clone and immediately discard it, you'll be left with a "useless clone node" that still occupies memory. On the program shown on issue #60, we're essentially constructing an entire Tail and immediately dropping it with a call to Head, and we do that recursively, so, after enough calls, we have, in memory, the equivalent of:

    let [_, xs0] = xs.lazy_clone()
        [_, xs1] = xs0.lazy_clone()
        [_, xs2] = xs1.lazy_clone()
        [_, xs3] = xs2.lazy_clone()
        ...
        [_, xs{N}] = xs{N-1}.lazy_clone()
    in xsN
Notice how this expression takes a list, clones it several times, discards all the clones, and then immediately returns the original list. These accumulating useless let-expressions (i.e., cloning nodes) are the source of the quadratic slowdown. So, how do we fix it? The solution proposed on TOIFPL book is to add safe pointers, which would allow us to remove redundant clone nodes when safe. But there is a simpler approach: just do NOT make a lazy clone there, to begin with! While lazy cloning is great for things like higher order lambda compositions, in some cases, a good-old pass-by-reference would do a better job. In a future version of the HVM, we could have something like:

    (Tails (Cons x &xs)) = (Cons xs (Tails xs))
Where `&` would mean "pass by immutable reference", skipping lazy cloning entirely, and making this program linear, as it should.

In short, the culprit for the quadratic slowdown is merely the fact that HVM automatically inserts a ".lazy_clone()" whenever you use a variable more than once, but there is no inherent incompatibility between interaction nets and good-old pass-by-reference, so HVM will have different pointer types that allow a programmer to implement functions like Tails that behave like they would on GHC, without any associated slowdown.

comment 3y ago · link · parent

Yes, starting next week or so! We'll be looking for engineers that have skills relevant to our projects, including compilers, low-level assembly optimization, functional programming, type theory, parallel computing, and so on. Right now, we're quite busy with incorporation and bureaucracy, but you should see job postings in our to-be-released landing page (higherorderco.com) soon. Meanwhile, I answer DMs on Twitter (@VictorTaelin) and Discord (VictorTaelin#2253).

comment 3y ago · link · parent

Victor here, thanks for the kind words. Regarding issue #60;

Short answer: this is true, but isn't a fundamental limitation and will be addressed in the future.

Long answer: this was quite a surprise to me back then, as it defies my understanding of "optimal", and was quite disappointing, but I learned a lot since. My current take is that, yes, some terms are quadratic on HVM while they are linear on the GHC, but that isn't due to some "catastrophic incompatibility", but just an inherent limitation of sharing-by-lazy-duplication. That said, as a practical runtime, HVM is not restricted to have only one way to share data. Rust, for example, has several ways: `&`, `&mut`, `Box`, `Rc`, `Arc`, `Cell`, `RefCell`, `Mutex`, `RwLock`, `* const T`, `*mut T`. We will add alternative pointer types to address this issue. That said, first we want to get the pure version completely polished, before moving into these optimizations. Meanwhile, it is worth noting that it is easy to fix these quadratic functions by adding strategic lambdas to avoid unnecessary cloning. This will make them linear again, so a functional language compiling to HVM properly wouldn't have any case where it underperforms GHC asymptotically (and would have several cases where it outperforms it!).

comment 3y ago · link · parent

Author here! Thanks for posting :) Just want to make a brief note here that we raised a 4.5m seed round to found a tech startup, the Higher Order Company, to work on the HVM. Our goal is to improve the runtime, the Kind language, and eventually build our own hardware. There are already several cool ideas on the pipeline, so expect exciting news and massive improvements soon!

comment 3y ago · link · parent

Well I can't disagree more. I feel like that's the best value I get for $20 among everything I pay, by at least 3 orders of magnitude. This thing does so much for me, I can't live without it anymore. When it is down I just log in on playground and pay for the API. It got to this point...

comment 3y ago · link · parent

I really wanted an online Pokémon-like experience that didn't require having a console and that didn't suck

comment 3y ago · link · parent

Even if that was the case, it'd still be massively useful because it would allow code to be transposed between languages idiomatically. For example, certain things like game engines were only implemented in very messy C++ code. If GPT understands how these libraries work, could it recreate all these game engines as cleaned up, elegant Haskell code?

comment 3y ago · link · parent

I sort of agree, but it still amazes me that it can get the code is correct, even though I asked for a highly specific style (i.e., use of recursion, representing "None" as null, the format of the JSON, making local functions, etc.). So, even thought it has never seen that exact implementation, it still assembles a working function that just works. If it was just mixing up different code it recalled from memory, it would likely have a bunch of silly errors here and there that I'd have to fix manually, but no, it just works. That's what impressed me.

comment 3y ago · link · parent

It managed to write, in one shot, a working λ-calculus parser, using a very specific programming style I asked it in JavaScript, and then translated it all to Python, including sarcastic, rhyming GLaDOS comments.

https://twitter.com/VictorTaelin/status/1635726202231988225

It also seems to be extremely competent at writing Agda types and proofs. We need some tool that highly integrates it with entire codebases, allowing for major refactors to be requested as a prompt. That would be groundbreaking (understatement of the year), specially if coupled with a strongly typed language that prevents it from accidentally breaking things up.

comment 3y ago · link · parent

Can you post your attempts? Would love to see it

comment 3y ago · link · parent

Neither a human can solve the halting problem. There is no evidence the brain does anything that a computer can't do.

comment 3y ago · link · parent

𝓢𝓲𝓷𝓰𝓾𝓵𝓪𝓻𝓲𝓽𝔂 𝓲𝓼 𝓬𝓸𝓶𝓲𝓷𝓰

comment 3y ago · link · parent

No? Order of magnitude conveys the notion of something being 100x bigger, at minimum. A lot can mean much less than that.

208.

Higher Order Company(twitter.com ↗)

1 points · by LightMachine · 3y ago · discuss

1
678
12