HNHacker News
TopNewBestAskShowJobs

ahgamut

639 karma · joined January 3, 2020

I like programming with numbers.

I regularly use Python (numpy+, pytorch), C, some parts of C++, and now R. I would like to explore J further.

username at gmail dot com. I have the same username on Github.

submissionscomments
ahgamut··on Portable Django
https://github.com/ahgamut/cpython/tree/cosmo-djngo

Python 3.11.0rc1, Django 4.1.7. I think ingenieroariel also has a binary available on the website.

It's a proof-of-concept (because I wrote it just a few hours back), but it shows that we could have the latest version of Python+Django packaged in a single-file executable. Someone could definitely improve upon the build process (like it was done for Python3.6) and add more packages if they wanted.

ahgamut··on Portable Django
FWIW I imagine we could have added Django to `python.com` sometime last September, which is when I ported Python 3.11.0rc1 (with threads!) to Cosmopolitan Libc: https://github.com/ahgamut/cpython/tree/cosmo_py311

Making Django work on Py3.11 involved the following steps (see commit history for https://github.com/ahgamut/cpython/tree/cosmo_djngo):

- add django + deps to the Lib/ folder - add sqlite3 and zlib to the build system - run quick tests and small examples to check the build works

I expect there's a bunch of packages like django which can be ported similarly. If anyone's interested, this is a fun area to explore.

ahgamut··on Actually Portable Perl
ah, here we are: https://github.com/ahgamut/php-src/tree/cosmo_php81

(note it's an experimental port, I just put it together).

ahgamut··on Actually Portable Perl
Adding on to jart's answer -- I ported PHP 7.3 back in July 2021 (building on alganet's work), and got up to a simple "hello-world". Have never used PHP, so I didn't know what else could be done with it at the time.

However, the libc has grown a lot over the last year (Cosmo has a pthreads API now!) -- the updated libc enabled a quick experimental port of Python 3.11.0rc1 back in August (https://github.com/ahgamut/cpython/tree/cosmo_py311), so I would expect that a newer version of PHP can be ported similarly. Let's see....

ahgamut··on Show HN: Port of OpenAI's Whisper model in C/C++
I liked reading the different implementations of the low-level tensor ops (simple C/AVX/AVX2/WASM128bit/ARM-NEON) -- it will help me learn about how to use x86 ASM. Thank you for writing this! Do you have any other recommendations/examples on how numerical code can be optimized via SIMD routines?
ahgamut··on Debugging C with Cosmopolitan Libc
There are many wonderful tools that help understand what our code is doing (compiler explorer, gdb, valgrind, ftrace, perf record, strace, ASAN/UBSAN). I wrote this blog post because using the debugging tools with Cosmopolitan Libc helped me learn and improve at programming. If you have other resources that can help me understand more about how my code works, I am happy to learn.
ahgamut··on Debugging C with Cosmopolitan Libc
You run the executable as usual, and if it crashes, Cosmopolitan Libc's crash handler starts gdb for you with a nice TUI and all the information you need to work with. Probably you could set up a bunch of macros in your editor that do the same thing (and I do have something like that for godbolt compiler explorer), but for gdb at least it's pretty convenient to have it performed by the executable when running it across systems. You can start gdb by yourself too if you have a workflow setup like that :)
ahgamut··on Cppfront, Herb Sutter's proposal for a new C++ syntax
From TFA, the goal is to "explore whether there's a way we can evolve C++ itself to become 10x simpler, safer, and more toolable".

First let's look at "toolable":

My big issue with Modern C++ these days is not just that it's complex to write, but that it also takes a long time to compile, what with all the template/compiler magic going on in the background. Long compile times break concentration, which I don't like. C++2 is not going to improve compilation times, because it's going to be compiled to C++, and then undergo another compilation step. If I combine C++'s slow compile times, two compilers, and all the dumb bugs that I can create and have to debug+fix, I get ....... (pls wait compiling) ..........

Let's switch context and look at "simpler":

Yay functions look more like JS lambdas or whatever. Fine. Let's look for the pointer-y stuff. Like [1] -- in C or "normal" aka "pre-modern" "C++1" you'd have:

  int x = 42;
  int *p;
  p = &x;
  func(*p);
In the "simpler" "C++2" you have:

  x: int = 42;
  p: *int;
  p = x&;
  func(p*);
I sure hope the changed syntax helps with parsing complexity or whatever, because it's not any different for me. Seems like C++2 got jealous of Rust and wanted to remind everyone "hello fellow kids, C++ is also cool pls". Note that even Rust and Go follow the C-style "*p" pointer deref syntax instead of "p*". What happens if I combine "C++1" and "C++2" syntax in the same file? I'm not as smart as Herb Sutter -- Is "p**x" a pointer deref then a mul? Which variable is being dereferenced? Perhaps it is a double deref, or ...? So much for simpler. (also note I haven't talked about template magicks here)

What do we have left ... "safer"? sighs

Okay, C is unsafe. Yes, C++ has to carry that baggage. Yes, memory corruption is horrible. Yes, buffer overflow errors lost lots of money, and have caused lots of wailing and gnashing of teeth. Yes, Modern C++ alleviates some of that unsafety with templates and a smart compiler. Yes, Rust has a smarter compiler with better static analysis that helps write safer code. But all this statically analyzed safe code still has to provide C wrappers if it's a shared object, or use the C wrappers provided by whichever kernel it's running on. So somewhere underneath all this safety lurk the familiar monsters, and someone's going to reach for them in the name of performance (remember Actix?). What about all the other issues that you can have unrelated to buffer overflows (log4j)? Will C++2 protect me from my own foolishness? Perhaps that's why its so complicated -- all my C++2 code is safe, because I will write no C++2 code.

And another thing: why not just do the Raku or Kotlin thing and call it by a different name, and have it be a separate language compiling to C++? Why "C++2"? Calling it C++2 vs C++ makes me think of Python 3 vs Python 2, and oh man that is not a good connection to hint at when claiming full backwards compatibility. Python 3 also got quite complicated compared to Python 2, so that doesn't give me hope either.

Now that I think about it, shouldn't this be called C+=2?

TL;DR:

- C++2 is not going to be more toolable because ultimately you're still compiling template-heavy C++

- C++2 is not going to be more simpler because unusual pointer syntax, confusion when mixing C++1, template magicks still have to exist

- C++2 is not safer because you can/have to still write or interface with C/C++ and the footguns therein.

- C++2 should not be called C++2, pls let's find a Raku/Kotlin.

Let C++ be the complexity monster it is. That's the tradeoff we make when we have to write it. If safety is the issue, can't we just use a sandbox or something? Is C++2 really the better option?

[1]: https://github.com/hsutter/cppfront/blob/main/regression-tes...

ahgamut··on Rust is actually portable
Good catch! I updated the post to mention the six operating systems (Linux, Windows, MacOS, FreeBSD, NetBSD, OpenBSD).
ahgamut··on Python is Actually Portable
Nice idea! IIRC redbean has the `LaunchBrowser` function (https://redbean.dev/2.0.html#LaunchBrowser) to open the user's default browser, and the `cosmo` module in Python is exactly for providing Cosmopolitan Libc goodies via a Python API. You can probably copy some of the LaunchBrowser code into `third_party/python/Python/cosmomodule.c` and implement the feature you're looking for. Submit a PR :)
ahgamut··on Python is Actually Portable
Follow the Cosmopolitan Libc project (also consider supporting and/or contributing to it), these things are on track to happen soon :)

TLS will probably happen first -- Cosmopolitan already has mbedTLS for redbean, so a modified `_ssl.c` should get us most of the way there.

Recent Python versions ... what version is Python on right now? 3.10? (3.11 apparently) I picked 3.6 at the time because Cosmopolitan Libc did not have threads then (it does now, pthreads API is being filled as of this writing), and also because it wouldn't have too much churn. Perhaps after 3.11 gets stable I'll port it to use Cosmopolitan Libc.

ahgamut··on Python is Actually Portable
I got interested in APEs because I got lost in DLL hell a few times with PyInstaller lol. IMO PyInstaller is pretty cool, but a bit overkill sometimes. At present I find APE Python a perfect match for one big use case (a bunch of my thrown-together shell utilities I can take and use everywhere).

Like after I wrote this blog post, I wrote a small Python app using Flask/SQLite/D3.js, put everything in a single file, just copied it onto computers with Debian/Fedora/FreeBSD/Win10, and now I just access the info I need on those systems via the browser. Providing a browser GUI makes it easier for my colleagues as well, some of whom don't use terminals at all :)

For C extensions (where I've stubbed my toes quite a bit with PyInstaller), I think a nice goal with APE Python would be to have a website like Christoph Gohlke's (https://www.lfd.uci.edu/~gohlke/pythonlibs/), where you just select the packages you would like, and you download them compiled as a single-file executable you can use anywhere. This is an interesting problem, and there's been some work towards solving it, let's see if we can have an elegant solution.

ahgamut··on Python is Actually Portable
I wanted Python to work across at least Windows/Linux because I have a bunch of these tiny scripts that I keep running everywhere. (For example, I always use `python.com -m http.server` when I want to share files in the local network without SSH). Cosmopolitan Libc made it easy for me to run my scripts across Linux/Windows and more, and the running scripts can be accessed via a browser GUI, which makes it very convenient if someone not use to CLI has to monitor what is going on. Plus I can update my scripts any time by just adding them to the executable via a `zip` command.

Toys are still fun to play with :)

ahgamut··on Python is Actually Portable
Yup, this is one big reason why I wanted Python to be Actually Portable -- I have a bunch of tiny scripts that are slightly complex for sh (some of them were Windows CMD .BAT files lol) which I like to use everywhere. By building Python with Cosmopolitan Libc, I can take a single binary and my scripts with me! I just add my scripts into the APE ZIP store via `zip -r ./python.com ./.python/*.py` and it just works. I only have VMs now, but a while ago I had Debian 10/Fedora 35/Windows 10/FreeBSD 13 all on the same network, and it was super convenient to have the same script/executable work everywhere.
ahgamut··on Python is Actually Portable
Cosmopolitan Libc allows you to build programs that run on six operating systems (Linux, Mac, Windows, FreeBSD, NetBSD, OpenBSD). I ported Python 2.7.18 and 3.6.14 to build on Cosmopolitan Libc because I wanted to have the same Python executable and my scripts with me everywhere :) I've updated the blog post for context.

The flask demo is unnaturally slow because my old computer is slow (running python tests in the background). plus I was using `_dummy_thread` Python3.6's pure-python threads implementation.

ahgamut··on Python is Actually Portable
Request to change the title to "Python is Actually Portable", as the blog post describes what I did to port Python 2.7/3.6 to Cosmopolitan Libc.

Edit: thank you @dang! That was super fast!

ahgamut··on AlphaCode as a dog speaking mediocre English
> I would actually be more impressed if it understood enough about programs to be able to mimic higher-level structure without just memorizing text.

Agreed.

> Why do you think Python isn't good for comparing program structure?

From recent experience I prefer control flow analysis, or something that results in a graph structure. As you said, that's harder with dynamic languages. I also think some Python features (english-like syntax, f-strings, division converts int to float, whitespace indentation, loops vs generator expressions) make structural comparisons messy, but that may just be bias.

The ideal language would be one with minimal syntax, where we can target a decent range of programs, and obtain as much info as possible about program structure without actually running the program. I've come across LISP-without-macros in Dreamcoder (https://arxiv.org/abs/2006.08381), BF++ (https://arxiv.org/abs/2101.09571), and a couple of others which I can't remember right now. I think the APL family (APL/J/K) would interesting because fewer characters to generate, but each character has a lot of meaning.

Right now I'm looking at flow-based programming (FBP) for this: In FBP the control flow is explicit - the program code describes a directed acyclic graph (DAG), so comparing program structure becomes straightforward (subgraph isomorphism with some heuristics). I'm writing a toy FBP language that draws images (https://github.com/mayahq/flatland), with which I aim to test what these models understand.

ahgamut··on AlphaCode as a dog speaking mediocre English
> It does not seem to be copying from the training data in any meaningful way.

My point is, I would like to verify this claim with different metrics, because we probably have different interpretations of the word "meaningful".

AlphaCode measures similarity between programs via longest common substrings. That's better than nothing, but that would mean two programs that differ only in variable naming would not be considered similar. If two programs differed only in the names of the variables/functions, I would consider that copying.

I think there are better comparisons of structural similarity: compare the ASTs, or the bytecode/assembly code generated, the control flow graphs, or perform SSA and compare the blocks generated. Each of these might have weaknesses as well, but they won't be as obvious as variable renaming, and so we'd get a better idea of what AlphaCode is copying, and therefore a better idea of its full capabilities.

I expect AlphaCode performs well on Python because the training data is dominated by Python, but Python isn't ideal for comparing program structure. I wonder which programming language (given enough training data) would be best suited for language model generation and analysis.

ahgamut··on AlphaCode as a dog speaking mediocre English
> To evaluate CoPilot, we should ask questions that are unusual enough they can't be answered through regurgitation of the training corpus.

Exactly! It's great that Copilot can generate correct code for a given question, but we cannot gauge its full capability unless we try it on a range of different questions, especially ones that are not found in the training data.

I mentioned this in the other AlphaCode post: It would be nice to know how "unusual" a given question is. Maybe an exact replica exists in the training data, or a solution exists but in a different programming language, or a solution can be constructed by combining two samples from the training data.

Quantifying the "unusual-ness" of a question will make it easier to gauge the capability of models like AlphaCode. I wrote a simple metric that uses nearest neighbors (https://arxiv.org/abs/2109.12075). There are also other tools to do this: conformal predictors, which are used in classification methods, and the RETRO transformer (https://arxiv.org/pdf/2112.04426.pdf) has a calculation for the effect of "dataset leakage".

ahgamut··on Competitive Programming with AlphaCode
Thank you so much!
ahgamut··on Competitive Programming with AlphaCode
Could you provide some papers/link related to Inductive Logic Programming? I'd like to look at other techniques in this space.
ahgamut··on Competitive Programming with AlphaCode
The Turing Test (https://en.wikipedia.org/wiki/Turing_test) for artificial intelligence required the machine to convince a human questioner that it was a human. Since then, most AI methods rely on a human reference of performance to showcase their prowess. I don't find this appealing because:

1) It's an imprecise target: believers can always hype and skeptics can always downplay improvements. Humans can do lots of different things somewhat well at the same time, so a machine beating human-level performance in one field (like identifying digits) says little about other fields (like identifying code vulnerabilities).

2) ELO ratings, or similar metrics are measurements of skill, and can be brute-forced to some extent, equivalent to grinding up levels in a video game. Brute-forcing a solution is "bad", but how do we know a new method is "better/more elegant/more efficient"? For algorithms we have Big-O notation, so we know (brute force < bubble sort < quick sort), perhaps there is an analogue for machine learning.

I would like performance comparisons that focus on quantities unique to machines. I don't compare the addition of computer processors with reference to human addition, so why not treat machine intelligence similarly?

There are many interesting quantities with which we can compare ML models. Energy usage is a popular metric, but we can also compare the structure of the network, the code used, the hardware, the amount of training data, the amount of training time, and the similarity between training and test data. I think a combination of these would be useful to look at every time a new model arrives.

ahgamut··on Competitive Programming with AlphaCode
> How many human beings do you personally know who were able to solve a dynamic programming problem at first sight without ever having seen anything but greedy algorithms?

Zero, which is why if a trained network could do it, that would be "impressive" to me, given my personal biases.

>. If you could get a machine that takes in all of Github and can solve "any" DP problem you describe in natural language with a couple of examples, that is AI above and beyond what many humans can do, which is "awesome" no matter how you put it.

I agree with you that such a machine would be awesome, and AlphaCode is certainly a great step closer towards that ideal. However, I would like to have a number measures the "awesomeness" of the machine (not elo rating because that depends on a human reference), so I will have something as a benchmark to refer to when the next improvement arrives.

ahgamut··on Competitive Programming with AlphaCode
> They tested it on problems from recent contests. The implication being: the statements and solutions to these problems were not available when the Github training set was collected.

Yes, and I would like to know how similar the dataset(s) were. Suppose the models were trained only on greedy algorithms and then I provided a dynamic programming problem in the test set, (how) would the model solve it?

> And yet, many humans who participate in these contests are unable to do so (although I guess the issue here is that Github is not properly indexed and searchable for humans?).

Indeed, so we don't know what "difficult" means for <human+indexed Github>, and hence we cannot compare it to <model trained on Github>.

My point is, whenever I see a new achievement of deep learning, I have no frame of reference (apart from my personal biases) of how "trivial" or "awesome" it is. I would like to have a quantity that measures this - I call it generalization difficulty.

Otherwise the datasets and models just keep getting larger, and we have no idea of the full capability of these models.

ahgamut··on Competitive Programming with AlphaCode
I find almost every new advance in deep learning is accompanied by contrasting comments: it's either "AI will soon automate programming/<insert task here>", or "let me know when AI can actually do <some-difficult-task>". There are many views on this spectrum, but these two are sure to be present in every comment section.

IIUC, AlphaCode was trained on Github code to solve competitive programming challenges on Codeforces, some of which are "difficult for a human to do". Suppose AlphaCode was trained on Github code that contains the entire set of solutions on Codeforces, is it actually doing anything "difficult"? I don't believe it would be difficult for a human to solve problems on Codeforces when given access to the entirety of Github (indexed and efficiently searchable).

The general question I have been trying to understand is this: is the ML model doing something that we can quantify as "difficult to do (given this particular training set)"? I would like to compute a number that measures how difficult it is for a model to do task X given a large training set Y. If the X is part of the training set, the difficulty should be zero. If X is obtained only by combining elements in the training, maybe it is harder to do. My efforts to answer this question: https://arxiv.org/abs/2109.12075

In recent literature, the RETRO Transformer (https://arxiv.org/pdf/2112.04426.pdf) talks about "quantifying dataset leakage", which is related to what I mentioned in the above paragraph. If many training samples are also in the test set, what is the model actually learning?

Until deep learning methods provide a measurement of "difficulty", it will be difficult to gauge the prowess of any new model that appears on the scene.

ahgamut··on Actually Portable Executables
You can compile it yourself if you like. I created a fork of the Lua Github mirror and made the necessary changes to compile with Cosmopolitan:

https://github.com/ahgamut/lua/tree/cosmopolitan

ahgamut··on Actually Portable Executables
I'm the author of the blog post!

As someone who has never messed around with Libc-level programming, it was surprisingly straightforward (and exciting!) to compile Lua all the way.

Cosmopolitan is incredible, thank you so much.

ahgamut··on Python’s tug of war between beginner-friendly and advanced features
J has the verbs behead[0] (for xs[1:]) and curtail[1] (for xs[:-1]), so the J oneliner for the above code would be

    <./ ([&}. - }:) xs 
[0] https://code.jsoftware.com/wiki/Vocabulary/curlyrtdot [1] https://code.jsoftware.com/wiki/Vocabulary/curlyrtco
ahgamut··on NN-SVG: Generate publication-ready NN-architecture schematics
I wrote a Python package that uses graphviz to draw NN architectures of PyTorch neural nets[1]. Visualizing a neural net is a fun problem by itself; neural nets are essentially DAGs, but somehow recording the flow of data has lots of quirks (especially when dealing with RNNs or skip connections). There's a top-level view where you're just discussing about the layers as they are connected, and a low-level view where the output of each op matters.

[1] https://pytorchrec.readthedocs.io

← PreviousPage 2 of 2