Skip to main content

New Computer Setup

Follow these instructions when installing the IoT-GPT app on a new computer. The checklist to verify during the final round is followed by the setup section.

Setup

1. Prepare Environment

  1. Launch WSL2 (Ubuntu) and stay in the user's home directory.

  2. Install PSQL:

     sudo apt update
    sudo apt install postgresql postgresql-contrib
    # check if service is running
    sudo service postgresql status
    # start the service if necessary
    sudo service postgresql start
  3. Install Conda:

    git clone https://github.com/fastai/fastsetup.git
    cd fastsetup
    source setup-conda.sh
    . ~/.bashrc
    conda install -yq mamba
  4. Add conda bash aliases:

    # Run the command:
    nano ~/.bash_aliases

    # Paste these aliases into the file:
    alias a=alias
    a cls="clear"
    a multipull="ls | parallel git -C {} pull"
    a jp="jupyter notebook --no-browser"
    a jl="jupyter lab --no-browser"
    a ca="conda activate ''"
    a mkpth="conda create -n pth python=3.10"
    a cals="conda env list"
    a gs='git status'

    # Close, save, and source the file:
    ctrl+x
    y
    source ~/.bash_aliases
  5. Install Cuda:

    sudo apt-key del 7fa2af80
    wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
    sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
    wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda-repo-wsl-ubuntu-12-2-local_12.2.2-1_amd64.deb
    sudo cp /var/cuda-repo-wsl-ubuntu-12-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
    sudo dpkg -i cuda-repo-wsl-ubuntu-12-2-local_12.2.2-1_amd64.deb
    sudo apt-get update
    sudo apt-get -y install cuda
  6. Add SSH key for GH cloning (no passphrase needed). Make sure you add this new key in GitHub account under Settings > SSH and GPG Keys.

    ssh-keygen -t ed25519 -C "sudhir@gqc.com"
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
  7. Create an ai3 dir and clone the 3 repositories:

    mkdir /home/gqc/git
    mkdir /home/gqc/git/gqc
    mkdir /home/gqc/git/gqc/ai3
    cd /home/gqc/git/gqc/ai3
    git clone git@github.com:gqc/ai3-hackathon.git
    git clone git@github.com:gqc/ai3-api-drf.git
    git clone git@github.com:gqc/ai3-frontend-react.git
  8. Navigate to the main codebase: cd /home/gqc/git/gqc/ai3/ai3-hackathon

  9. Setup the Python virtual environment (both vanilla Python with venvwrapper and Conda have been tested).

    # NOTE: Sudhir and Jake can't get the conda env to work properly, so we're just moving forward with the root conda env.
    pip install -r requirements.txt
    pip install -e .
  10. Pull and extract the LFS files:

    # Install LFS
    sudo apt install git-lfs

    # Pull LFS files:
    git lfs pull

    # Install unzip
    sudo apt install unzip

    # unzip the files:
    unzip input_data.zip
    unzip PSIAP_AI3.zip
  11. Login and cache huggingface credentials:

    python

    import huggingface_hub as hf
    hf.login()

    # Paste this key:
    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

    # Add token as git credential? (Y/n)
    n

    quit()
  12. Install mosquitto MQTT:

    sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
    sudo apt-get update
    sudo apt-get install mosquitto mosquitto-clients
    sudo apt clean

2. Setup Database and API

  1. Open a terminal and run these commands:

    cd /home/gqc/git/gqc/ai3/ai3-api-drf
    ca base # or ca ai3 if you made a venv
    pip install -r requirements-essential.txt
    cd scripts
    ./1_install_psql.sh
    sudo su postgres
    psql
  2. In the resulting PSQL command window, run these commands:

    SELECT 'CREATE DATABASE ai3'
    WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'mydb')\gexec

    ALTER USER postgres WITH PASSWORD 'gq010102';

    \q
  3. Exit the postgres user: exit

  4. Continue in the terminal:

    cd /home/gqc/git/gqc/ai3/ai3-api-drf
    ca base # or ca ai3 if you made a venv
    python manage.py migrate

    NOTE If the migrate fails because postgres might not be listening on the IP/port, try changing the PORT value in settings.py to 5433 instead of 5432.

  5. Run the API: python manage.py runserver 0.0.0.0:8000

3. Setup and Start Frontend

  1. Check Node version: node --version.

  2. If node is less than 16, uninstall and reinstall a higher version:

    1. Uninstall existing node versions:

      sudo apt remove '^node.*$'
      sudo apt remove '^libnode.*$'
      apt-get purge nodejs &&\
      rm -r /etc/apt/sources.list.d/nodesource.list &&\
      rm -r /etc/apt/keyrings/nodesource.gpg
    2. Install newer version:

      # Download and import the Nodesource GPG key
      sudo apt-get update
      sudo apt-get install -y ca-certificates curl gnupg
      sudo mkdir -p /etc/apt/keyrings
      curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

      # Create deb repository
      NODE_MAJOR=20
      echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

      # Run Update and Install
      sudo apt-get update
      sudo apt-get install nodejs -y
  3. Install yarn globally: sudo npm install -g yarn

  4. cd /home/gqc/git/gqc/ai3/ai3-frontend-react

  5. Install dependencies: yarn install

  6. Start the app: yarn start

4. Start Publisher

Open a terminal and run these commands:

cd /home/gqc/git/gqc/ai3/ai3-hackathon
# activate env
ca base
# start publisher
multi-publisher

5. Start Subscriber

  1. Open a terminal.
  2. cd /home/gqc/git/gqc/ai3/ai3-hackathon
  3. For first time setup:
    1. Start the subscriber: multi-subscriber -c subscriber-multi.ymlNOTE If the connection to DB fails, check port 5432 vs 5433.
    2. After the model loads (it will take a few minutes), kill the subscriber process.
    3. Switch huggingface model to offline mode:
      export HF_DATASETS_OFFLINE=1
      export TRANSFORMERS_OFFLINE=1
  4. After the first setup has been complete, you can start the subscriber with the command: multi-subscriber -c subscriber-multi.yml