Search Blogs

Thursday, June 20, 2024

Terminal Diary Galore

I had this idea the other day about tracking my entire life in the Linux terminal. My thinking is that I have probably typed hundreds, if not millions, of content into the terminal and when I try to recall them I end up doing a Google search1 to reproduce something I've probably done hundreds to thousands of times. The idea I had of tracking my terminal input/output by recording it, came about when I stumbled accidently upon asciinema and thought "well this might be useful". At first I thought "oh I'll just use this to record workflows that are complicated and I might forget", but then I realized I'll just forget what recording I need to watch.

Then I saw an interesting [post] by Miles Cranmer regarding an approach on how he is using a vector database to make finding and pointing others to github discussions more streamlined. In my head something went off. I was like: "Okay, I think I'm going to record my terminal sessions everytime and feed them into a vector database". Seems straightforward to do so.

Well what use is a vector database really? I mean its just semantic search, and even if I get the retrieved text I'm most likely looking for, will I really remember what I wanted to do with it or what it did. This is where using a LLM would be a tremendous utlity. I basically can have it re-teach me my terminal workflows2 and what I did by adding in context, instruction, and descriptions.

So I'm going to try proofing this out. I think the utility of this approach needs to have 2 components:

  1. It's easy to start recording and update the vector database.
  2. Querying and LLM to find what I'm looking for is straight forward.

For the vector database could use something like Pinecone or Chroma. Then need to regularly update the vector database. Once that is done, I can get the embedding for user input and then query the vector database. This will give me some number of top retrieved results but then the goal should be to use an instructed LLM to always output some useful script or set of steps. Here is an illustration of what I envision:

$ querylog "Show me how to install materials project api/pymatgen, then query the most stable copper oxide structure, and analyze the structure factor (i.e., radial distribution function)"

Which then outputs something like:

To achieve the the desired workflow:
1. In the terminal, create a python venv: python -m venv .venv and activate source .venv/bin/activate 2. In terminal, install materials project api and pymatgen: pip install -U mp-api pymatgen pymatgen-analysis-diffusion 3. To query materials project for Cu-O stable structures in python:

with MPRester(apikey) as mpr: # Query the database for all materials containing copper copper_oxide = mpr.summary.search(chemsys="Cu-O", is_stable=True, fields=["structure"])
structure = copper_oxide[0].structure

Get RDF

from pymatgen.analysis.diffusion.aimd.rdf import RadialDistributionFunctionFast rdf_func = RadialDistributionFunctionFast(structures=structure, ngrid=101, rmax=10.0, sigma=0.2) r,rdf = rdf_func.get_rdf(["Cu","O"],["Cu","O"]) plt.plot(r,rdf)

The example above is a bit generic and your standard LLM would probably get this correct on its own, but if you had some idiosyncratic way of doing things you would need to prompt the LLM so that it would know those specific details. Here the idea is to just find previous examples and have a generic LLM organize, format, and style in a informative way. Lets see if I can get something working.

Footnotes


  1. Now its more common for me to use an LLM or something like perplexity

  2. A user on the asciinema site replied to a question post I made, their thinking was to use the .history for capturing all my terminal IO. The issue is that will not capture things that go on in emacs or python interpreter. I really want to capture ever IO that goes on int the terminal. 



Reuse and Attribution

Tuesday, June 11, 2024

Acutely Tuned & Karpathy Aware

In the world of AI there is a whole subfield dedicated to making sure AI systems work in the best interest of humanity. From my understanding this is called AI alignment or safety. My guess is that this field researches AI systems by putting them through a serious of tests (in a sandbox) to ensure they behave in the most responsive way. Other than that presumption, I'm not really sure what AI alignment or safet really means.

The reason I bring it up in this post is there was a very interesting [report] posted by Leopold Aschenbrenner1, a leading AI safety researcher at OpenAI who was fired[1]. In summary the report discusses topics related to energy consumption and security needs for artificial general intelligence (AGI) and artificial superintelligence (ASI) systems, as well as other aspects of national security. My view is that I don't really think AI researchers really know if current neural network architecture will enable AGI or ASI, or what will, but the analysis is quite through and detailed and provides some aspects to think about.

After skimming the report, what stood out to me is the fact that we (the U.S.) would need to improve our energy production and security greatly. I do think Aschenbrenner's analysis brushes aside anticipated improvements in energy efficient hardware for inference. Regardless, there is going to be a huge demand for compute based on AI systems. The other concern is in the global arena, we will be competing with each other and dominence of the world order is on the table. While I'm not so sure the gloom and doom is so pressing, it is something that cannot be ignored.

I suggest reading it even if your not really interested in these types of topics because Leopold, whether you agree with him or not, seems to be very through and brilliant in thought.

Coding GPT-2 from Scratch

I've followed Andrej Karpathy for some time since the release of ChatGPT because he is one of the few people who showed how to build these type of AI architectures from scratch2. My plan is to follow Karpathy's 4-hour video and reproduce it using Julia's Flux.jl and Transformers.jl. I'm using Julia so that I avoid copying exactly the same PyTorch code that Karpathy is implementing. I was thinking about using JAX but decided to go with Flux.jl because its more familiar to me at the moment.

Footnotes


  1. I had never heard of this person but seems very well known in the AI community. Also find him to be very interesting. 

  2. For whatever reason I am draw to people who build things from first-principles. Yes this is not efficient for useful tools or applications but in my experience it has been really hard to get to a 90% "expertise" level without building the darn thing from scratch. When I was learning Finite-Difference Time-Domain Methods, moelcular dynamics, or density functional theory, I always wrote a basic code from scratch to prove to myself that I knew how the guts worked. 


References

[1] L. Aschenbrenner, Situational Awareness, (2024). https://situational-awareness.ai/leopold-aschenbrenner (accessed June 10, 2024).



Reuse and Attribution