Skip to content

Instantly share code, notes, and snippets.

@cloneofsimo
Last active October 7, 2024 06:33
Show Gist options
  • Save cloneofsimo/5b2561edf8b6d4216ee9fd58b9aca2e6 to your computer and use it in GitHub Desktop.
Save cloneofsimo/5b2561edf8b6d4216ee9fd58b9aca2e6 to your computer and use it in GitHub Desktop.
Very common stuff that I forget all the time and I really shouldn't

clean clean

black .
autoflake --remove-all-unused-imports -i ./*
isort .

Kill cuda shit

lsof /dev/nvidia* | awk '{print $2}' | xargs -I {} kill {}

Check basic stuff

du -h | awk '$1 ~ /G/ && $1 > 1' | sort -h : over 1gb of current disk

Local git setup

git config --global init.defaultBranch main
git config user.name "Simo Ryu"
git config user.email "[email protected]"

common initial machine setups

Install python3.9, venv, and make venv

cd
export DEBIAN_FRONTEND=noninteractive
sudo apt update
sudo apt install -y software-properties-common
sudo apt install -y pdsh
sudo apt-get install -y tmux
sudo apt-get install -y htop
sudo apt-get install -y git-lfs
sudo git lfs install
sudo apt install -y ffmpeg
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install -y python3.9
sudo apt install -y python3.9-venv python3.9-distutils 
sudo apt install -y libpython3.9-dev python3.9-dev

python3.9 -m ensurepip
python3.9 -m venv py39cuda
source ~/py39cuda/bin/activate
pip install torch deepspeed mosaicml-streaming tqdm click transformers wandb plotly pandas
wandb login

Install basic stuff, git config, and cmd

git config --global user.name "Simo Ryu"
git config --global user.email "[email protected]"

ACTIVATE_CMD="source ~/py39cuda/bin/activate"

# Check if the command is already in .bashrc
if grep -Fxq "$ACTIVATE_CMD" ~/.bashrc
then
    echo "Virtual environment activation command already in .bashrc"
else
    # Add the command to .bashrc
    echo "$ACTIVATE_CMD" >> ~/.bashrc
    echo "Virtual environment activation command added to .bashrc"
fi

$ACTIVATE_CMD
@cloneofsimo
Copy link
Author

cloneofsimo commented Jun 15, 2024

Iterate over servers to put the key

SIMO_PUBKEY="ssh-rsa ..."

# Nodes
NODES=(
  "4a78144e-01.cloud.together.ai"
  "4a78144e-02.cloud.together.ai"
  "4a78144e-03.cloud.together.ai"
  "4a78144e-04.cloud.together.ai"
)

# Loop through each node and configure the SSH access for simo
for NODE in "${NODES[@]}"; do
  ssh root@$NODE <<EOF
    # Create .ssh directory and set permissions
    sudo -u simo mkdir -p /home/simo/.ssh
    sudo -u simo chmod 700 /home/simo/.ssh

    # Add the public key to authorized_keys
    echo "$SIMO_PUBKEY" | sudo -u simo tee -a /home/simo/.ssh/authorized_keys
    sudo -u simo chmod 600 /home/simo/.ssh/authorized_keys
EOF
done

@cloneofsimo
Copy link
Author

addkey

#!/bin/bash

# Create the addkey script
cat << 'EOF' > ~/addkey
#!/bin/bash

# Check if an argument is provided
if [ -z "$1" ]; then
  echo "Usage: addkey \"ssh-rsa ...\""
  exit 1
fi

# Ensure the .ssh directory exists
mkdir -p ~/.ssh

# Add the provided key to the authorized_keys file
echo "$1" >> ~/.ssh/authorized_keys

# Set the correct permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

echo "Key added successfully."
EOF

# Make the addkey script executable
chmod +x ~/addkey

# Move the addkey script to /usr/local/bin to make it available system-wide
sudo mv ~/addkey /usr/local/bin/addkey

# Verify the installation
if command -v addkey &> /dev/null; then
  echo "The addkey command has been successfully installed."
else
  echo "There was an error installing the addkey command."
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment