Skip to content

Commit

Permalink
feat: n-workers.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed May 27, 2024
1 parent 06cd0eb commit 83745fd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vscode/settings.json

*.o
*.0
*.dSYM
*.data
__pycache__
Expand Down
52 changes: 52 additions & 0 deletions examples/n-workers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# This script starts N workers from a single command. Mainly useful for testing and debugging.
# Usage:
#
# W=7 T=2 bash n-workers.sh start
# W=7 bash n-workers.sh stop
#
# Env vars:
# W - n workers
# T - n threads per worker

cd "$(dirname "$0")"

if [ -z "$W" ]; then
W=3
fi
if [ -z "$T" ]; then
T=1
fi

if [ "$1" == "start" ]; then
for (( w = 0; w < $W ; w += 1 ));
do
PORT=$(expr 9999 - $w)
PROC_ID=$(lsof -ti:$PORT)
if [ -n "$PROC_ID" ]; then
kill -9 $PROC_ID
echo "Killed process $PROC_ID"
fi

mkdir -p dllama_worker_$w # macOs does not support -Logfile argument, so we place logs inside different directories
cd dllama_worker_$w
screen -d -L -S dllama_worker_$w -m ../../dllama worker --port $PORT --nthreads $T
cd ..
echo "Started worker $w on port $PORT"
done

sleep 2
elif [ "$1" == "stop" ]; then
for (( w = 0; w < $W ; w += 1 ));
do
screen -S dllama_worker_$w -X quit
done

echo "Stopped $W workers"
else
echo "Usage: $0 [start|stop]"
fi

echo "> screen -ls"
screen -ls
2 changes: 2 additions & 0 deletions src/funcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
const unsigned int varStart = threadIndex * rangeSlice + (threadIndex < rangeRest ? threadIndex : rangeRest); \
const unsigned int varEnd = varStart + rangeSlice + (threadIndex < rangeRest ? 1 : 0);

#define DEBUG_FLOATS(name, v, n) printf("⭕ %s ", name); for (int i = 0; i < n; i++) printf("%f ", v[i]); printf("\n");

void softmax(float* x, const unsigned int size);
float rms(const float* x, const unsigned int size);
void rmsnorm(float* o, const float* x, const float ms, const float* weight, const unsigned int size, const unsigned int nThreads, const unsigned int threadIndex);
Expand Down

0 comments on commit 83745fd

Please sign in to comment.