Motivation

Artificial Intelligence (AI) is often presented like a complex field, the state of the art being impossible to understand, models too large to train, incredible work in progress moving forward that could change anything, yet a black box inscrutable for anyone except the selected few.

This is truly damaging to the field as it is a fascinating topic and even though indeed nobody can understand it all, we can all benefit from tinkering with it, learning from it and possibly even using it.

It's also often showcased as impractical for a "normal" person with their "normal" computer. Consequently everything must be done in the "cloud", far away from our scrutiny.

This is also damaging as it is simply false. Some very large models are indeed too large to run on a single computers but most, including what was considered the state of the art just a couple of years ago, can be run locally. In fact the trend to scale might be problematic for the entire field.

Regardless of all those limitations the goal here is to showcase that even though not everything can be done on your desktop, a lot can. Composing from that and learning how it works can help to reconsider a potential feeling of helplessness.

Not only can you self-host AI models, use them, adapt them, but there is a whole community and set of tools to help you do so. This movement itself is very encouraging. AI does not have to be a black box. Your digital life does not have to be owned by someone else, even for the state of the art.

PS: this is also aligned with my own naive heuristic explicited since 2020 : avoiding gadgets or services (free or not) that increase inequality by design, through technology or business model or both, would be a good starting point.

Timeline of warnings

Own page on ML started in 2011, cf MachineLearning?action=diff#diff1320660278 with other page on own wiki in 2008, cf Seedea:Seedea/AImatrix?action=diff#diff1221994306

Specific to OpenAI

A lot more on https://x.com/search?q=%40utopiah%20openai

Specific to ecology

Prompted by recent (July 2024) news on Microsoft and Google completely busting their own energy goals due to AI.

Requirements

Software

Familiarity with self-hosting, e.g Linux command line, see Shell, and containerization, e.g Docker. Ideally familiarity with Python the most popular work in AI is currently often done in that Programming language.

Hardware

A desktop with a proper graphic card is recommended. Some solutions do not need it all while others need the last generation of GPU. It is also possible to rent such a configuration in the cloud if necessary, while insuring that the cloud provider has terms of services and overall practices aligned with your needs.

Ideal

Linux desktop with latest generation NVIDIA GPU, Docker installed and running with NVIDIA support. Not that this can be done rootlessly to insure a bit more safety. Overall do remember to backup your data regardless of what you are trying.

Notes on integration

Using Telegram bot I am able to query models from any device while my desktop is turned on, e.g here llama.cpp running Mistral https://twitter.com/utopiah/status/1720122249938628951 , and consequently considering a local first (no 3rd party relaying messages) via https://git.benetou.fr/utopiah/offline-octopus/issues/22

This way I can for example generate text from my mobile phone, being on the same network or not.

Chaining example of speech-to-text, LLM then text-to-speech for a "natural" (albeit slow) kind of "hands-free conversation" https://twitter.com/utopiah/status/1720475902218317930

This could also be done behind a VPN or relying on Tailscale without using Telegram or any chat program. For now using a chat porogram makes sharing on a mobile phone a lot more convenient.

Used locally

Trying to insure combinatoriality/compositionality

Short scripts in ~/bin to make the different tools and their result to combine more conveniently.

  • stt: using Whisper.cpp to convert an audio file to text
  • screenocr: capture part of the screen then OCR the result then Web search
  • ocr-to-wikiembeddings: capture part of the screen then semantic search it
  • monitor-voice-via-whispercpp-stream: using Whisper.cpp interatively
  • get-pages-from-embeddings: returns top10 wiki pages after embedding
  • santacoder: complete a code prompt via HuggingFace API and clean output

Relying on

  • url-to-text: uses readibility to get text content from a URL
  • yt-dlp to get online videos with optionally Ffmpeg to get audio for transcription

Used non locally but still open

example as tweets

Remarks

Typical process

  1. discover news about AI
  2. live demo availability, if so try with own data
  3. open-source repository
  4. models availability
  5. image availability, as Docker or replicate (cog)
    1. otherwise make Dockerfile
      1. very often relying on Anaconda3
  6. try locally
  7. if out of memory (e.g OOM error with Torch) look for slimmed down version
  8. if no Web interface available, use Python or NodeJS to make a basic interface
  9. build demo using the Web API, integrating with other tools, e.g WebXR

Tooling

Python Flask template

Often models and inference comes from Python code. Using Flask provides an HTTP (or even HTTPS) endpoint that makes it easy to integrate with a frontend, e.g a WebXR page.

# consider a venv then ./bin/pip3 install flask uuid
# res is the result from a Python function, any inference here with models already downloaded.
import uuid    
from flask import request, Flask
app = Flask(__name__)

from flask import request
@app.route('/toimage/<prompt>', methods=['GET'])
def login(prompt):
    myuuid = uuid.uuid4().hex
    res[0].save('./static/'+myuuid+'.jpg','JPEG')
    return {'prompt': prompt, 'url': '/static/'+myuuid+'.jpg'}

@app.route('/totext/<query>', methods=['GET'])
def gen(query):
    return {'prompt': query, 'top10': res}

if __name__ == '__main__':
    print('can then expose as https via e.g ngrok http 5000')
    app.run()

Note this could also use Gradio instead.

Constrained model pathfinder

Adversarial protections

Training followed

  • university training
  • MOOCs
    • AIClass
    • MLClass
    • Coursera
      • Sequences, Time Series and Prediction
      • Natural Language Processing in TensorFlow
      • Convolutional Neural Networks in TensorFlow
      • Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning
      • Computational Molecular Evolution
    • Dataquest.io
      • Data Cleaning Course
      • Data Science Projects Course
      • Data Visualization Course

To try

See also