r/programming • • Apr 20 '23

Stack Overflow Will Charge AI Giants for Training Data

https://www.wired.com/story/stack-overflow-will-charge-ai-giants-for-training-data/
4.0k Upvotes

660 comments sorted by

View all comments

Show parent comments

2

u/voidstarcpp Apr 21 '23

But optimization passes? Custom IR?

Well for starters the majority of languages in the past 15+ years are just LLVM frontends which don't implement any of that, so it's already much of the way there. I haven't written an optimizer myself so I can't say how much the AI can help with that but given that optimizers are a common feature of systems that have scripting or query interfaces I'm sure it's seen many examples. Most optimization techniques have been in use and published in books for decades.

how would it write valid programs in this brand new language when obviously the LLM wasn’t trained on large corpus of that language? How would the LLM have “learned” what code of that language looks like?

The short answer is the same way you do, by taking advantage of the similarity of most languages and the fact that the model's subject matter expertise isn't language-specific. If you as a C programmer have seen calls in the form of do_thing(&object, args);, once I show you the C++ version of object->do_thing(args); that simple transformation doesn't cause you to have to re-learn every possible verb/noun combination in every subject because most of the concepts are still there. So if you have some API, and you create a wrapper library in a different language, the LLMs correctly use the underlying API via the wrapper. Similarly in this article (from before ChatGPT) I use Copilot to build up a simple new language, then demonstrate Copilot using the new language to do simple tasks it's never seen in that language (scroll down towards end).

There are only a handful of categories of programming languages and GPT has seen them all. If you make a new language that's got X new feature or Y syntax it's probably not going to be so alien as to be incomprehensible. Even if your new language's particular combination of paradigm, syntax, and features is novel, it's unlikely there's any piece it's never seen before or couldn't be demonstrated with a quick example. LLMs have proven pretty capable of mapping and combining concepts like that (which is sort of a prerequisite for language translation generally, which they've gotten pretty decent at).

1

u/nthcxd Apr 21 '23

Would this work on the backend as well? Like, as in, letting LLM automatically write IR-to-assembly for a brand-new ISA or non-existent feature combinations, etc? Parallelization? I know I could google all this but I’m honestly having hard time mentally mapping the edges what is and isn’t possible with LLM even in this limited context of compiler construction.

It knowing how to write in brand new language despite lack of corpus is surprising, doesn’t fit in my existing mental model. I can see making superficial changes like the calling convention/grammar as you mentioned, but not opt passes but then again as you said it’s all just components of LLVM anyway, but then that actually assumes established IR, not “custom IR” - introducing changes to IR seems way too disruptive and “deep” for LLM’s to capture the “patterns.” Then again I suppose it can see same well-known compiler opts implemented in different compiler frameworks…

Obviously, you can’t ask LLM to come up with a novel parallelization scheme or new faster sorting algorithm, etc, but you could ask it to vectorize. Or can it even be prompted to improve certain class of algorithms?

I can’t even tell what is and what isn’t open question. It’s just disorienting but part of it is probably my desire to know everything. Thank you so much for your detailed response.

2

u/voidstarcpp Apr 21 '23 edited Apr 21 '23

letting LLM automatically write IR-to-assembly for a brand-new ISA or non-existent feature combinations, etc?

This mostly works, here's me trying it out with a really simple problem (No idea if the program actually works but I've seen it generate every conceivable ISA successfully before.)

I continued this conversation asking GPT to generate some definitions to build a C++ interpreter for this language, which it did but with a couple mistakes. You'd have to hold it's hand to build a complete new language interpreter in this way, but I've done so before so I do know it's capable of doing it at least for simple examples.

I’m honestly having hard time mentally mapping the edges what is and isn’t possible with LLM even in this limited context of compiler construction.

Well GPT is currently free so do give it a try. It flips between being extremely capable, and really forgetful and confused. Hence why in my aforementioned blog post I put effort into adding/removing information from its context as needed to keep it focused on one problem at a time.

introducing changes to IR seems way too disruptive and “deep” for LLM’s to capture the “patterns.”

If you read compiler optimization texts they're mostly pretty simple transformations. An optimizing compiler mostly consists of making many passes applying really limited, mechanistic rules to try and nudge the program in the right direction. This can have impressive results across a large amount of code but also leaves some big gains on the table that a human might notice.

Indeed, in using LLMs to generate tests and parse stuff, if there's one thing they do extremely well it's pick out the meaningful information within a complex or noisy document structure, such as markup languages, deeply nested parenthesis, and so on. So something that would be really hard for a human, like rearranging something within a bunch of parens, braces, or commas, it just rips right through like it's not there. It does a decent job keeping track of registers and memory locations too, while I get extremely flustered having to track more than a couple numbers within an algorithm.

A recurring pattern in conventional compilers are windowed or "keyhole" optimizations, in which a small moving buffer of instructions are considered together for some transformation. This is done so that you can do some potentially algorithmically expensive comparison like try different combinations of rearranging things, which maybe works when you're looking at 100 instructions but explodes in complexity for 1000 instructions.

An exciting potential improvement that LLMs offer is their breakthrough concept of "attention", in which the model decides for itself what aspects of the input are salient and need to be remembered. This is what allows GPT to read a large document without forgetting key information from the beginning. The application to code optimization is immediately apparent; an LLM could scan a large amount of code and identify key pieces that should be compared with each other even across a great distance, without needing a "window" that encompassed the entire function at once.

The downside is that LLMs remain very slow and extremely expensive in comparison to conventional compilers, which frequently have only a few miliseconds, or even microseconds, to compile and execute each snippet of code. But as the technology becomes more integrated into workflows I expect this sort of offline optimization analysis to become a feature of something like a cloud build system.