Instructions to use AjayRangoji/AR-4B-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AjayRangoji/AR-4B-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AjayRangoji/AR-4B-base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("AjayRangoji/AR-4B-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AjayRangoji/AR-4B-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AjayRangoji/AR-4B-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AjayRangoji/AR-4B-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/AjayRangoji/AR-4B-base
- SGLang
How to use AjayRangoji/AR-4B-base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "AjayRangoji/AR-4B-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AjayRangoji/AR-4B-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "AjayRangoji/AR-4B-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AjayRangoji/AR-4B-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use AjayRangoji/AR-4B-base with Docker Model Runner:
docker model run hf.co/AjayRangoji/AR-4B-base
Download training_code/watchdog.sh from AjayRangoji/AR-4B-base: direct link, hf CLI and curl.
- Browser
- Download file 6.42 kB
-
https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/watchdog.sh
- Command line
-
hf download hf://AjayRangoji/AR-4B-base/training_code/watchdog.sh
-
curl -L -o watchdog.sh https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/watchdog.sh
6.42 kB
| # Keeps training alive, checking every 10 min. When no training job exists: | |
| # 1) 4 fully free nodes -> run there (no time limit) | |
| # 2) >= 3 clean nodes held for another job (plnd), >= 2 h before it starts -> backfill | |
| # 3) 2 fully free nodes -> run there (gradient accumulation 2) | |
| # 4) >= 2 clean nodes anywhere -> queue for 2, allowing only clean nodes | |
| # 5) otherwise wait | |
| # While running on fewer than 4 nodes: if 4 free nodes appear, start a 4-node job, | |
| # and only once it holds its nodes, stop the small job ("make before break"). | |
| cd /fsx/ajay-stu/AR | |
| FINAL=/fsx/ajay-stu/ar-data/checkpoints/ckpt_619699 | |
| STATIC_EXCLUDE=ip-10-0-136-14,ip-10-0-136-94,ip-10-0-136-253,ip-10-0-138-178,ip-10-0-139-113,ip-10-0-140-247 | |
| BAD=logs/bad_nodes.txt | |
| touch $BAD | |
| launches=0; pinned_wait=0; queued_wait=0; running_for=0; last_job="" | |
| upgrade_job=""; old_job=""; up_wait=0 | |
| not_excluded() { grep -vxF -f <(echo $STATIC_EXCLUDE | tr ',' '\n') | grep -vxF -f $BAD | grep -vxF -f logs/bad_nodes_perm.txt; } | |
| clean_nodes() { | |
| # GPUs use < 2 GB in total, read from gpu_check's full table | |
| /usr/bin/python3 /fsx/ajay-stu/gpu_check.py 2>/dev/null \ | |
| | awk -F'|' '$1 ~ /^ *10\.0\.[0-9]+\.[0-9]+ *$/ { split($4, m, "/"); if (m[1] + 0 < 2000) { gsub(/ /, "", $1); print $1 } }' \ | |
| | sed 's/\./-/g; s/^/ip-/' | sort -u | not_excluded | |
| } | |
| backfill_minutes() { | |
| # minutes until the next other user's waiting job is expected to start, minus a 15-min margin | |
| t=$(squeue --start -p dev -t PD -h -o "%S %u" | awk -v me=$USER '$2 != me && $1 ~ /^20/ {print $1}' | sort | head -1) | |
| [ -z "$t" ] && { echo 0; return; } | |
| echo $(( ($(date -u -d "$t" +%s) - $(date -u +%s)) / 60 - 15 )) | |
| } | |
| submit() { | |
| out=$(sbatch "$@" train_real.sbatch); echo "$out" | |
| last_job=${out##* } | |
| } | |
| while true; do | |
| CAP=$(cat logs/MAX_NODES 2>/dev/null || echo 8) # node limit: echo N > logs/MAX_NODES | |
| [ -f $FINAL/.metadata ] && { echo "$(date) training finished, watchdog exiting"; exit 0; } | |
| # learn from the last job: remember nodes whose GPUs were busy at pre-flight | |
| if [ -n "$last_job" ] && [ -f logs/real_$last_job.log ]; then | |
| grep -oE "preflight \S+ gpu_used=[0-9]+" logs/real_$last_job.log \ | |
| | awk '{split($3, a, "="); if (a[2] >= 2000) print $2}' >> $BAD | |
| sort -u $BAD -o $BAD | |
| fi | |
| # --- an upgrade to 4 nodes is in progress --- | |
| if [ -n "$upgrade_job" ]; then | |
| ustate=$(squeue -j $upgrade_job -h -o %T 2>/dev/null) | |
| if [ "$ustate" = "RUNNING" ]; then | |
| echo "$(date) upgrade: 4-node job $upgrade_job holds its nodes, stopping small job $old_job" | |
| scancel $old_job; last_job=$upgrade_job; upgrade_job=""; running_for=0 | |
| elif [ "$ustate" = "PENDING" ]; then | |
| up_wait=$((up_wait + 1)) | |
| [ $up_wait -ge 2 ] && { echo "$(date) upgrade: nodes taken, cancelling $upgrade_job"; scancel $upgrade_job; upgrade_job=""; } | |
| else | |
| echo "$(date) upgrade: job $upgrade_job ended early (pre-flight?), keeping small job" | |
| last_job=$upgrade_job; upgrade_job="" | |
| fi | |
| sleep 600; continue | |
| fi | |
| state=$(squeue -u $USER -h -n ar-real -o %T | head -1) | |
| if [ "$state" = "PENDING" ]; then | |
| if [ -f logs/.wd_pinned ]; then | |
| pinned_wait=$((pinned_wait + 1)) | |
| [ $pinned_wait -ge 2 ] && { echo "$(date) pinned job stuck, cancelling"; scancel -u $USER -n ar-real; pinned_wait=0; } | |
| else | |
| queued_wait=$((queued_wait + 1)) | |
| [ $queued_wait -ge 12 ] && { echo "$(date) refreshing queued job"; scancel -u $USER -n ar-real; queued_wait=0; } | |
| fi | |
| elif [ "$state" = "RUNNING" ]; then | |
| pinned_wait=0; queued_wait=0; running_for=$((running_for + 1)) | |
| [ $running_for -eq 6 ] && : > $BAD # healthy for ~1 hour: forget bad nodes | |
| # on fewer than 4 nodes and stable for 30 min? try to upgrade | |
| nn=$(squeue -u $USER -h -n ar-real -t RUNNING -o %D | head -1) | |
| if [ "$nn" -gt "$CAP" ]; then touch logs/STOP logs/RELOAD; echo "$(date) limit $CAP < $nn nodes: clean stop after the next checkpoint"; fi | |
| if [ "$nn" -lt 8 ] && [ $running_for -ge 3 ]; then | |
| FREE=$(./find_nodes.sh | not_excluded); N=$(echo "$FREE" | grep -c .) | |
| T=$(( N < CAP ? N : CAP )) # as many free nodes as possible, max 8 | |
| if [ "$T" -ge 4 ] && { [ "$T" -ge $((nn + 2)) ] || [ "$T" -eq 8 ]; }; then # 7 -> 8 allowed too | |
| old_job=$(squeue -u $USER -h -n ar-real -t RUNNING -o %i | head -1) | |
| NODES=$(echo "$FREE" | head -$T | paste -sd,) | |
| out=$(sbatch -N $T --nodelist=$NODES train_real.sbatch); echo "$out" | |
| upgrade_job=${out##* }; up_wait=0 | |
| echo "$(date) upgrade: started $T-node job $upgrade_job on $NODES (small job $old_job keeps running)" | |
| fi | |
| fi | |
| elif [ -z "$state" ]; then | |
| pinned_wait=0; queued_wait=0; running_for=0 | |
| FREE=$(./find_nodes.sh | not_excluded); N=$(echo "$FREE" | grep -c .) | |
| CLEAN=$(clean_nodes); C=$(echo "$CLEAN" | grep -c .) | |
| CAND=$(comm -12 <(sinfo -p dev -h -N -o "%N %t" | awk '$2=="plnd"{print $1}' | sort -u) <(echo "$CLEAN")) | |
| K=$(echo "$CAND" | grep -c .) | |
| W=$(backfill_minutes) | |
| if [ "$N" -ge 2 ] || [ "$C" -ge 2 ] || [ "$K" -ge 3 ]; then | |
| launches=$((launches + 1)) | |
| [ $launches -gt 50 ] && { echo "$(date) 50 launches reached, stopping - check logs"; exit 1; } | |
| fi | |
| if [ "$N" -ge $(( CAP < 4 ? CAP : 4 )) ]; then | |
| T=$(( N < CAP ? N : CAP )) | |
| NODES=$(echo "$FREE" | head -$T | paste -sd,); touch logs/.wd_pinned | |
| echo "$(date) launch #$launches: $T free nodes $NODES" | |
| submit -N $T --nodelist=$NODES | |
| elif [ "$K" -ge 3 ] && [ "$W" -ge 120 ]; then | |
| n=$(( K < CAP ? K : CAP )) | |
| NODES=$(echo "$CAND" | head -$n | paste -sd,); touch logs/.wd_pinned | |
| echo "$(date) launch #$launches: backfill on $n held nodes for $W min ($NODES)" | |
| submit -N $n --nodelist=$NODES --time=$W | |
| elif [ "$N" -ge 2 ]; then | |
| NODES=$(echo "$FREE" | head -2 | paste -sd,); touch logs/.wd_pinned | |
| echo "$(date) launch #$launches: 2 free nodes $NODES (grad_accum 2)" | |
| submit -N2 --nodelist=$NODES | |
| elif [ "$C" -ge 2 ]; then | |
| rm -f logs/.wd_pinned | |
| EXC=$(comm -23 <(sinfo -p dev -h -N -o %N | sort -u) <(echo "$CLEAN") | paste -sd,) | |
| echo "$(date) launch #$launches: queueing for 2 nodes among $C clean nodes" | |
| submit -N2 --exclude=$EXC | |
| else | |
| echo "$(date) no usable nodes (free=$N clean=$C held-clean=$K window=${W}min), waiting" | |
| fi | |
| fi | |
| sleep 600 | |
| done | |