Would you like me to debug your math?

by Gurkenglas1 min read11th Jun 202114 comments

32

CommunityPractical
Personal Blog

At AI safety camp I noticed that people are bad at math and when I look over their shoulder as they code I notice nested for loops that could have been one matrix multiplication.

Therefore I'll try offering this service to the public: You screenshare as you do your daily tinkering, I watch for algorithmic or theoretical squiggles that cost you compute or accuracy or maintainability.

Maybe some people are less effective pair programming than alone. You choose whether we pretend I'm not there, whether you think out loud, or whether we talk theory instead.

We might learn engineering from each other. I have shown multiple people IDE features such as debuggers, and I still don't know a way as elegant as I feel it should be to, say, spin up a minimal transformer implementation for tinkering in a few minutes.

If I do this for a bunch of people someone might notice me and put me in an environment where I'm much more productive than now. Not to say I expect you to be well-connected, the time for pickiness is after I have users.

If your workflow is embarassing, that's fine: You are particularly likely to benefit, and I expect this is actually quite common.

I did Java years ago, Haskell less years ago and Python the last few months. Of course, pseudocode is the real language. Here's examples of me rewriting other people's Haskell code: https://codereview.stackexchange.com/users/84131/gurkenglas

Schedule here: https://calendly.com/gurkenglas/consultation

14 comments, sorted by Highlighting new comments since Today at 6:11 PM
New Comment

After reading this post, I decided to send a message to Gurkenglas.
This was the best decision I made. I have been developing a mobile software for the last 120 days, and this is my first experience developing something this big. Sharing my screen on Discord, he was able to:
- Completely change my debugging workflow, which is likely to save me hundreds of hours in the long-term
- Teach me a new testing ritual
- Make it easier to identify useless pieces of code
- Refactor hundreds of lines with simple intuitions and good regex
- Teach me dozens of useful keyboard shortcuts and IDE features
- Give me some useful career advice

I wasn't expecting to level up that fast, but in retrospect it seems obvious that accepting a group invitation from a more experienced player would allow me to level up much faster and learn new tricks. Great learning experience.

I had a similar experience. Gurkenglas is legit.

I am one of those people that have benefited from working with Gurkenglas this way.

For me in particular the main benefits have been two-fold.

  1. Becoming more aware of short comings in how I program. Especially noticing when something I'm doing a lot has a better solution, but I haven't gotten round to investigating alternatives because each individual time is faster to do the old way rather than learning a new way. Gurkenglas helped me get around to actually doing something about this.
  2. Math. It could be when you are doing something that feels too ad-hoc, Gurkenglas can help you work out a more canonical approach.

Now if I had seen this post before I had worked with Gurkenglas I would most probably not have reached out for mainly two reasons

  1. Reaching out to strangers is hard and I might not have felt that what I was doing would be worth taking up a whole other persons time.
  2. I would probably not know what I was missing. I would think that the way I was doing things were fine and there would be little to benefit from it.

If you are thinking something similar, I'm here to tell you that you should probably try it out anyway. The risk of trying and finding that it wasn't worth it is probably much lower than the risk of not trying and missing some good level up opportunities.

as they code I notice nested for loops that could have been one matrix multiplication.

 

This seems like an odd choice for your primary example.

  • Is the primary concern that a sufficiently smart compiler could take your matrix multiplication and turn it into a vectorized instruction?
    • Is it only applicable in certain languages then? E.g. do JVM languages typically enable vectorized instruction optimizations?
  • Is the primary concern that a single matrix multiplication is more maintainable than nested for loops?
    • Is it only applicable in certain domains then (e.g. machine learning)? Most of my data isn't modelled as matrices, so would I need some nested for loops anyway to populate a matrix to enable this refactoring?

Is it perhaps worth writing a (short?) top level post with an worked out example of the refactoring you have in mind, and why matrix multiplication would be better than nested for loops?
 

It's not my one trick, of course, but it illustrates my usefulness. It's more maintainable not just because it is shorter but also because it has decades of theory behind it. Drawing the connection unlocks inspiration from entire branches of math. And the speedups from standing on the shoulders of giants go far beyond the constant factors from vectorized instructions.

I'm not disagreeing with you (I don't think?), but just pointing out a mistaken lesson someone new to programming might draw from your comment.

it's more maintainable not just because it is shorter but also because it has decades of theory behind it

Being shorter is way down the list of things you should consider when you're thinking about how to make your code more maintainable.  In fact, longer code is often more maintainable.  As a trivial example, imagine a variable called x and the alternate name for it: seconds_since_midnight

I'm not sure there is a good rule of thumb wherein you say "shorter/longer is more maintainable".  

What about after the maddening 8-hour debug session where you finally realise they were storing a number representing seconds since noon in that variable?

It's good to keep in mind that whomever wrote the code is probably a freakin' liar!

I had similar thought, but then most of the languages I use don't support matrix operations directly in the language anyway. Great believer in "tried and true" numerical analysis libraries though.

Does your offer stand for learning math instead programming something? Some possible examples are:

  1. Solving exercises in the end of a chapter
  2. Given a chapter from a textbook, redoing it on my own for a more general case or for a slightly different case .
  3. Reading some proofs and understanding them.
  4. The whole loop of reading a chapter, understanding it, looking up things I don't understand, solving exercises, proving things I want to prove on my own, adding notes to my notes database.

Sure, I'll try it. I don't expect to be an order-of-magnitude power multiplier in that case, though.

"Disclaimer" - I have no relationship with Gurkenglas outside the ~2hr session we just went through. But I got the feeling I should tout his skills to the community, so I'm doing it. He did not solicit my comment.

This was fun. We didn't do maths so much, because I don't have a maths problem. I have several major problems. We identified some of them.

Gurkenglas has a pretty good handle on looking at completely foreign code, grokking some high-level problems (need to refactor) and some low-level problems (useless conditionals) and even backing off and not fixing a low-level problem when it turns out it might just be idiomatic to the language (Golang and the omnipresent "if err != nil...") These are reasonably sophisticated habits/skills.

I got the impression he's pretty passionate about alignment and other AI-related topics, so if you've got an important AI project that needs someone who's willing to do whatever it takes to add value, schedule time on his Calendly and let's get this going!

Are you open to auditing existing math (vs. observing and commenting on real-time creation)?

Seems like less of a market niche, but link it!