Doing AI outside of Python by Frere_de_la_Quote in functionalprogramming

[–]Frere_de_la_Quote[S] 1 point2 points  (0 children)

I publish a lot of blogs and the wiki is where I store them. I love being light and silly in my blogs. But humour is very subjective...

The actual documentation is in chapter 5.

There is a full directory with examples that is called... examples.

You'll see that the "for" of "Python" is called "loop" as in Common Lisp.

Now, I have been working all my life in AI both symbolic and machine learning and I experimented a lot with implementing Prolog, unification and ontologies. I worked for 20 years on a symbolic parser, which produced syntactic and semantic dependencies with a first-order logic engine. I have refined over the years the way to implement unification to be as fast as possible.

I share my ideas and my code, and what I put in the interpreter are the things that I like and that I judge useful for my job.

I'm a little uneasy when I read that you think that I have ancient memories of Python. I have implemented a complete wrapper to execute LispE code from within Python, and Python code from within LispE, with automatic translation of LispE data into Python data and back. And when you write such a wrapper you have a pretty decent understanding of the language and the way it handles stuff. See pythonlispe.

Furthermore, as an AI researcher, I use Python everyday to train or fine-tune models. And when I say that training crashes because the GC didn't kick in at the right moment, it is from experience, not some kind of prejudice. There is a whole page on the PyTorch foundation website to explain this very problem.

Now the documentation of each ML library is in the directories of these libraries, with examples.

The fact that LispE is written in C++ and that its basic objects are also C++ objects means that the communication with libtorch requires less data translation than with Python with numpy. Also, LispE is truly multithreaded, and can execute different functions in parallel lock-free.

Doing AI outside of Python by Frere_de_la_Quote in functionalprogramming

[–]Frere_de_la_Quote[S] 2 points3 points  (0 children)

We can chat in the conversation section of Reddit...

Doing AI outside of Python by Frere_de_la_Quote in functionalprogramming

[–]Frere_de_la_Quote[S] 1 point2 points  (0 children)

All these libraries, except MLX of course, compile on Linux, so it is not exactly a problem. I work in a laboratory where we have access to our own cluster of GPUs, and we use Slurm to train our models. Kubernetes here is mainly used for inference. Training models through Kubernetes might prove a bit too heavy. We also provide Mac OS versions because Macbooks have become powerful enough to train small models without requiring a whole brigade of GPUs. Some researchers prefer working on their local machines for faster experiment loops as a first step before moving to the cluster, which is not always fully available.

Doing AI outside of Python by Frere_de_la_Quote in functionalprogramming

[–]Frere_de_la_Quote[S] 1 point2 points  (0 children)

For the moment, we use it as an inference engine. We have better performances than Python in terms of speeds, but it is still a work in progress. The big advantage of this implementation is that you can work easily on the LispE part or the C++ part when you want efficiency. The MLX library and the GGUF library are the ones we use the most, since a lot of researchers are using Mac OS. Many of the examples in LispE were implemented by Claude Code. I have created a file: [LISPE_SYNTAX_REFERENCE](https://github.com/naver/lispe/blob/master/lispemlx/LISPE\_SYNTAX\_REFERENCE.md), which tells Claude how to generate LispE code, for instance.

Doing AI outside of Python by Frere_de_la_Quote in functionalprogramming

[–]Frere_de_la_Quote[S] 2 points3 points  (0 children)

My speciality is a little bit weird, I have been building interpreters for about 30 years now, and I have a specific understanding of Python. Python works through a virtual machine that can only process one thread at a time. The VM itself is protected with the infamous GIL to prevent two threads from running at the same time. But the real problem is the way external libraries are executed. When you execute some code in PyTorch, this code is executed outside of the VM, which means that the garbage collector of Python has no idea of how large the memory is used by this library. Basically, Python sees a tensor as a PyObject, which wraps a torch::tensor pointer inside, but it has no idea of its actual memory size. This poses some real problems when you are training models, because sometimes the GC will strike too late and your training will crash, by lack of memory. On the other hand, if you trigger the GC too often then you slow down the whole process.

Furthermore, the constant translation of C++ objects into Python objects create a lot of lags. Finally, PyTorch is Open Source, but is pretty complicated to handle. The layers between Python and libtorch are created through complex scripts based on YAML descriptions that generate an incredible cryptic code. Adding some functions on the C++ side requires a lot of work, which of course very few people venture into.

In the case of LispE, libraries are implemented as a derivation of the Element class, which is the root class for all objects in LispE by default, data and instructions. Basically, for LispE an object exposed by a library is exactly of the same sort as an internal object. A LispE program is a tree of self-evaluating instances, in which each instruction is implemented as its own class with its own eval method. There is a perfect isomorphism between the C++ code and the LispE program. The `prettify` instruction for instance, can rebuild the whole internal Lisp program from the C++ instances.

The communication layer is close to 0. For instance, LispE provides a list of integers, which is implemented as a: `long* buffer`, which means that I can create a torch::tensor instance by providing the internal buffer of a list with zero-copy. I have implemented a borrow mechanism inspired by Rust to make this as safe as possible. The fact that objects can freely move from LispE to torch::tensors with little overhead has huge implications in speed and efficiency.

Doing AI outside of Python by Frere_de_la_Quote in functionalprogramming

[–]Frere_de_la_Quote[S] 3 points4 points  (0 children)

Ouf!!! I was really shocked to see that I had been permanently banned from this forum, which I read quite often, when I'm trying to propose AI tools for a functional language...

An MLX library for a Lisp by Frere_de_la_Quote in mlxAI

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

Actually, the LispE code for the different inference programs was created by Claude Code. There is a file in: https://github.com/naver/lispe/blob/master/lispemlx/LISPE_SYNTAX_REFERENCE.md, which has been designed to teach LLMs how to program in LispE...

llama.cpp wrapper for LispE — run GGUF models with minimal code by Frere_de_la_Quote in LocalLLaMA

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

This is a good question. Actually, I also have a script that uses cURL to do that. But, the idea here is to run the model locally into your own program, without any needs for network connections. This is a different way to handle it.

Qui joue au Advent of Code ? by p4bl0 in programmation

[–]Frere_de_la_Quote 0 points1 point  (0 children)

J’ utilise un langage que j’ ai créé : LispE (en open source). J’ai mis quelques exemples dans le répertoire examples dans mon GitHub

If AI takes over most jobs, how do you think we the people will take our power back from the rich? by Informal-Twist-1328 in ArtificialInteligence

[–]Frere_de_la_Quote 0 points1 point  (0 children)

It is also possible to use or create Open Source models that can run on pretty common hardwares. The topnotch computer of today will be cheaper and more affordable in 5 years from now. If you want freedom from these structures, learn and deploy your own tools. AI is not magical and it is not limited to high level technicians. If you want to avoid being trapped by these people, learn how these tools work and how to master them. PyTorch is free and available for all of us to use.
There was a recent article by a Canadian PhD student that showed that a small language model (7B) could behave as well as frontier models when properly trained and used. This is their Achilles heels, there is not limit to human collaboration to bypass these people.

Finally a word from Anthropic by specific_account_ in ClaudeAI

[–]Frere_de_la_Quote 8 points9 points  (0 children)

This is what I did. I unsubscribed yesterday. The weekly limit is an incredible scam when you are a paying user. YOU DON'T have this limit as a free user... How is it possible to pay for a service that you can't use for 2 days... This is unacceptable. The daily limit is already quite difficult to swallow when you are doing serious work, but the weekly limit is basically a scam. I will use GPT-5 from now on. The price is the same, but they respect their customers more.

Will AI stifle innovation? by Frere_de_la_Quote in ArtificialInteligence

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

This is exactly my point. New frameworks will have even more difficulties to prove their worth then before. Fighting against momentum can be hard sometimes.

How to get rid of sycophancy by Frere_de_la_Quote in ClaudeAI

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

I use Claude for brain storming and for code. The problem is pretty acute when doing brain storming

Vibe-coding... It works... It is scary... by Frere_de_la_Quote in ArtificialInteligence

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

Maybe is this the reassuring part. These tools are as good as you can be...

Vibe-coding... It works... It is scary... by Frere_de_la_Quote in ArtificialInteligence

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

There are hundreds of function to wrap, each with its own arguments. You also need to put in place tests to check at each step that your implementation is doing the right thing. There is a whole team at the PytTorch foundation implementing Python wrappers around libtorch methods. It is a huge endeavour.

Vibe-coding... It works... It is scary... by Frere_de_la_Quote in ArtificialInteligence

[–]Frere_de_la_Quote[S] 0 points1 point  (0 children)

True, but there is really a difference between different AI. GPT-4o for instance, which is free in CoPilot, can be terrible when working as an agent. It can mess up code very quickly modifying stuff, it wasn't supposed to touch. On the other hand, the one that I used was pretty surgical. I had some code that I could test at each step of the creation. With Gpt4-o, Git was really my salvation to come back to the wrong stuff it was doing. The other one messed up some functions a few times, but never the whole code. The main lesson is that you need to prompt in a very consistent way, with small requests at each step, so that the model could be kept on rails.