Yixin Liu commited on
Commit
7017395
1 Parent(s): bb690a1
Files changed (38) hide show
  1. .gitattributes +34 -0
  2. README.md +11 -6
  3. __pycache__/config.cpython-39.pyc +0 -0
  4. __pycache__/parse_code.cpython-39.pyc +0 -0
  5. app.py +153 -0
  6. res/20230615-17h44m58s/gpu_utility.sh +0 -118
  7. res/20230615-17h44m58s/script.sh +0 -29
  8. res/20230615-17h45m38s/gpu_utility.sh +0 -118
  9. res/20230615-17h45m38s/script.sh +0 -29
  10. res/20230615-17h46m42s/gpu_utility.sh +0 -118
  11. res/20230615-17h46m42s/script.sh +0 -29
  12. res/20230615-17h48m58s.zip +0 -0
  13. res/20230615-17h48m58s/gpu_utility.sh +0 -118
  14. res/20230615-17h48m58s/script.sh +0 -29
  15. res/20230615-17h49m08s.zip +0 -0
  16. res/20230615-17h49m08s/gpu_utility.sh +0 -118
  17. res/20230615-17h49m08s/script.sh +0 -29
  18. res/20230615-17h49m45s/gpu_utility.sh +0 -118
  19. res/20230615-17h49m45s/script.sh +0 -29
  20. res/20230615-17h50m13s/gpu_utility.sh +0 -118
  21. res/20230615-17h50m13s/script.sh +0 -29
  22. res/20230615-17h50m22s/gpu_utility.sh +0 -118
  23. res/20230615-17h50m22s/script.sh +0 -29
  24. res/20230615-17h50m57s/gpu_utility.sh +0 -118
  25. res/20230615-17h50m57s/script.sh +0 -29
  26. res/20230615-17h51m33s/gpu_utility.sh +0 -118
  27. res/20230615-17h51m33s/script.sh +0 -29
  28. res/20230615-17h51m43s/gpu_utility.sh +0 -118
  29. res/20230615-17h51m43s/script.sh +0 -29
  30. res/20230615-17h53m28s/gpu_utility.sh +0 -118
  31. res/20230615-17h53m28s/script.sh +0 -25
  32. res/20230615-17h53m44s/gpu_utility.sh +0 -118
  33. res/20230615-17h53m44s/script.sh +0 -24
  34. res/20230615-17h55m17s/gpu_utility.sh +0 -118
  35. res/20230615-17h55m17s/script.sh +0 -23
  36. res/20230615-17h56m22s/gpu_utility.sh +0 -118
  37. res/20230615-17h56m22s/script.sh +0 -23
  38. test.py +6 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,7 +1,12 @@
1
- # exp-comman-generator
 
 
 
 
 
 
 
 
 
2
 
3
- ```bash
4
- streamlit run main.py --server.address localhost
5
- ```
6
-
7
- My personal tool for experiment command generation. Check this: https://experiment-comamnd-genertator.herokuapp.com/
 
1
+ ---
2
+ title: Experiment-Command-Generator
3
+ emoji: :robot:
4
+ colorFrom: "#FFD700"
5
+ colorTo: "#FF8C00"
6
+ sdk: streamlit
7
+ sdk_version: "1.22.0"
8
+ app_file: main.py
9
+ pinned: true
10
+ ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
__pycache__/config.cpython-39.pyc DELETED
Binary file (5.37 kB)
 
__pycache__/parse_code.cpython-39.pyc DELETED
Binary file (1.61 kB)
 
app.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import imp
2
+ from email.policy import default
3
+ import streamlit as st
4
+ import pandas as pd
5
+ import numpy as np
6
+ import time
7
+ # import matplotlib.pyplot as plt
8
+ # import seaborn as sns
9
+ # import plotly.figure_factory as ff
10
+ # import altair as alt
11
+ # from PIL import Image
12
+ # import base64
13
+ # import tarfile
14
+ # import os
15
+ # import requests
16
+
17
+
18
+
19
+ # title
20
+ st.title("Exp Command Generator")
21
+
22
+ # experiment mode
23
+ exp_mode = st.sidebar.selectbox("Select Experiment Mode", ["MultipleExpOnecard","OneExpOnecard"],key="MultipleExpOnecard")
24
+
25
+ ## 检查框
26
+ debug = st.sidebar.checkbox("Debug:选择则会串行地执行命令", value=True)
27
+ # st.sidebar.write(f"checkbox的值是{res}")
28
+
29
+ setup = st.sidebar.text_area("Hyperparameters or some setup of env at beginning.", """cd $(dirname $(dirname $0))
30
+ source activate xai
31
+ export PYTHONPATH=${PYTHONPATH}:/Users/apple/Desktop/workspace/research_project/attention:/mnt/yixin/:/home/yila22/prj""")
32
+
33
+ # exp_hyper = st.sidebar.text_area("Hyperparameters", """exp_name="debug-adv-training-emotion"
34
+ # dataset=emotion
35
+ # n_epoch=3
36
+ # K=3
37
+ # encoder=bert
38
+ # lambda_1=1
39
+ # lambda_2=1
40
+ # x_pgd_radius=0.01
41
+ # pgd_radius=0.001
42
+ # seed=2
43
+ # bsize=8
44
+ # lr=5e-5""")
45
+
46
+ ## gpu 相关参数
47
+ gpu_list = st.sidebar.multiselect("multi select", range(10), [5, 6, 7, 8, 9])
48
+ # print(gpu_list)
49
+ if exp_mode == "OneExpOnecard":
50
+ allow_gpu_memory_threshold_default = 20000
51
+ gpu_threshold_default = 1
52
+ elif exp_mode == "MultipleExpOnecard":
53
+ allow_gpu_memory_threshold_default = 3000
54
+ gpu_threshold_default = 70
55
+ allow_gpu_memory_threshold = st.sidebar.number_input("最小单卡剩余容量", value=allow_gpu_memory_threshold_default, min_value=0, max_value=30000, step=1000)
56
+ gpu_threshold = st.sidebar.number_input("最大单卡利用率", value=gpu_threshold_default, min_value=0, max_value=100, step=10)
57
+ sleep_time_after_loading_task= st.sidebar.number_input("加载任务后等待秒数", value=20, min_value=0,step=5)
58
+ all_full_sleep_time = st.sidebar.number_input("全满之后等待秒数", value=20, min_value=0,step=5)
59
+
60
+ gpu_list_str = ' '.join([str(i) for i in gpu_list])
61
+ gpu_hyper = f"gpu=({gpu_list_str})\n"
62
+ gpu_hyper+=f"allow_gpu_memory_threshold={allow_gpu_memory_threshold}\n"
63
+ gpu_hyper+=f"gpu_threshold={gpu_threshold}\n"
64
+ gpu_hyper+=f"sleep_time_after_loading_task={sleep_time_after_loading_task}s\n"
65
+ gpu_hyper+=f"all_full_sleep_time={all_full_sleep_time}s\n"
66
+ gpu_hyper+="gpunum=${#gpu[@]}\n"
67
+ gpu_hyper+="i=0\n"
68
+
69
+ main_loop = st.text_area("Main loop", """for lambda_1 in 1 3;do
70
+ for lambda_2 in 1 10;do
71
+ for n_epoch in 3;do
72
+ for x_pgd_radius in 0.005 0.01;do
73
+ for pgd_radius in 0.0005 0.001 0.002;do
74
+ python train.py --dataset $dataset --data_dir . --output_dir ./outputs/ --attention tanh \
75
+ --encoder $encoder \
76
+ --exp_name $exp_name --lambda_1 $lambda_1 --lambda_2 $lambda_2 --pgd_radius $pgd_radius --x_pgd_radius $x_pgd_radius \
77
+ --K $K --seed $seed --train_mode adv_train --bsize $bsize --n_epoch $n_epoch --lr $lr \
78
+ --eval_baseline
79
+ done;done;done;done;done;""")
80
+ if 'python' in main_loop:
81
+ hyper_loop = main_loop.split("python")[0]
82
+ python_cmd = main_loop[main_loop.index('python'):].split('done;')[0]
83
+ elif 'bash' in main_loop:
84
+ hyper_loop = main_loop.split("bash")[0]
85
+ python_cmd = main_loop[main_loop.index('bash'):].split('done;')[0]
86
+ print(hyper_loop)
87
+ print(python_cmd)
88
+ end_loop = "done;"*hyper_loop.count("for")
89
+ print(end_loop)
90
+
91
+ g = st.button("Generate")
92
+ if g:
93
+ s = ""
94
+ s += setup + "\n\n"
95
+ # s += exp_hyper + "\n\n"
96
+ s += gpu_hyper + "\n\n"
97
+ s += hyper_loop + "\n\n"
98
+ s += """
99
+ while true; do
100
+ gpu_id=${gpu[$i]}
101
+ # nvidia-smi --query-gpu=utilization.gpu --format=csv -i 2 | grep -Eo "[0-9]+"
102
+ gpu_u=$(nvidia-smi --query-gpu=utilization.gpu --format=csv -i $gpu_id | grep -Eo "[0-9]+")
103
+ free_mem=$(nvidia-smi --query-gpu=memory.free --format=csv -i $gpu_id | grep -Eo "[0-9]+")
104
+ if [[ $free_mem -lt $allow_gpu_memory_threshold || $gpu_u -ge ${gpu_threshold} ]]; then
105
+ i=`expr $i + 1`
106
+ i=`expr $i % $gpunum`
107
+ echo "gpu id ${gpu[$i]} is full loaded, skip"
108
+ if [ "$i" == "0" ]; then
109
+ sleep ${all_full_sleep_time}
110
+ echo "all the gpus are full, sleep 1m"
111
+ fi
112
+ else
113
+ break
114
+ fi
115
+ done
116
+
117
+ gpu_id=${gpu[$i]}
118
+ # search from the next gpu
119
+ i=`expr $i + 1`
120
+ i=`expr $i % $gpunum`
121
+
122
+ free_mem=$(nvidia-smi --query-gpu=memory.free --format=csv -i $gpu_id | grep -Eo "[0-9]+")
123
+ gpu_u=$(nvidia-smi --query-gpu=utilization.gpu --format=csv -i $gpu_id | grep -Eo "[0-9]+")
124
+ export CUDA_VISIBLE_DEVICES=$gpu_id
125
+ echo "use gpu id is ${gpu[$i]}, free memory is $free_mem, it utilization is ${gpu_u}%"
126
+ """
127
+ s += f"""com="{python_cmd}"\n"""
128
+ s += "echo $com\n"
129
+ s += "echo ==========================================================================================\n"
130
+ if debug:
131
+ s += "$com\n"
132
+ s += "# mkdir -p ./logs/\n"
133
+ s += "# nohup $com > ./logs/$exp_name-$RANDOM.log 2>&1 &\n"
134
+ else:
135
+ s += "# $com\n"
136
+ s += "mkdir -p ./logs/\n"
137
+ import time
138
+ from datetime import datetime
139
+ current_timestamp = int(time.time())
140
+ human_readable_timestamp = datetime.utcfromtimestamp(current_timestamp).strftime('%Y-%m-%d-%H')
141
+ s += f"date_time={human_readable_timestamp}\n"
142
+ s += "mkdir -p ./logs/$date_time\n"
143
+ s += "nohup $com > ./logs/$date_time/$exp_name-$RANDOM.log 2>&1 &\n"
144
+ s += """echo "sleep for $sleep_time_after_loading_task to wait the task loaded"
145
+ sleep $sleep_time_after_loading_task\n"""
146
+ s += end_loop
147
+ st.success("Finished")
148
+ st.code(s, language="shell")
149
+
150
+
151
+
152
+
153
+
res/20230615-17h44m58s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h44m58s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h45m38s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h45m38s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h46m42s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h46m42s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h48m58s.zip DELETED
Binary file (1.9 kB)
 
res/20230615-17h48m58s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h48m58s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h49m08s.zip DELETED
Binary file (1.9 kB)
 
res/20230615-17h49m08s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h49m08s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h49m45s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h49m45s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h50m13s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h50m13s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h50m22s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h50m22s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h50m57s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h50m57s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h51m33s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h51m33s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h51m43s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h51m43s/script.sh DELETED
@@ -1,29 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- command="""
19
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
20
- """
21
- eval $command &
22
-
23
-
24
- sleep $sleeptime
25
-
26
- #####
27
-
28
- #####
29
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h53m28s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h53m28s/script.sh DELETED
@@ -1,25 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
-
18
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
19
-
20
- sleep $sleeptime
21
-
22
- #####
23
-
24
- #####
25
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h53m44s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h53m44s/script.sh DELETED
@@ -1,24 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
-
15
- update_device_idx;
16
-
17
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
18
-
19
- sleep $sleeptime
20
-
21
- #####
22
-
23
- #####
24
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h55m17s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=True
13
- constrain_rate=True
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h55m17s/script.sh DELETED
@@ -1,23 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
- update_device_idx;
15
-
16
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
17
-
18
- sleep $sleeptime
19
-
20
- #####
21
-
22
- #####
23
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h56m22s/gpu_utility.sh DELETED
@@ -1,118 +0,0 @@
1
-
2
- username=yila22
3
- max_gpu_utilization=90
4
- total_gpu_memory=24564
5
- max_gpu_memory_gap=5000
6
- available_devices=( 0 1 2 3 4 )
7
- current_device_idx=-1
8
- sleeptime=10
9
- cpu_mean_max=77
10
- memory_rate_max=80
11
- constrain_total=True
12
- constrain_mine=False
13
- constrain_rate=2
14
-
15
-
16
-
17
- function update_device_idx {
18
- if [ $constrain_total = true ]; then
19
- # check total cpu usage
20
- while true; do
21
- cpu_mean_1=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
22
- sleep 1
23
- cpu_mean_2=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
24
- sleep 1
25
- cpu_mean_3=$(mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ { cpu_usage=100-$NF; total+=cpu_usage; count++ } END { print total/count }')
26
- cpu_mean=$(echo "scale=2; ($cpu_mean_1+$cpu_mean_2+$cpu_mean_3)/3" | bc)
27
-
28
- # if currently cpu usage is less than the threshold, then break
29
- if [ $(echo "$cpu_mean < $cpu_mean_max" | bc) -eq 1 ]; then
30
- echo "total cpu mean: $cpu_mean is less than $cpu_mean_max, continue to check total memory usage"
31
- break
32
- else
33
- echo "total cpu mean: $cpu_mean is greater than $cpu_mean_max, sleep 10 seconds"
34
- sleep 10
35
- fi
36
- done;
37
-
38
- # check total memory usage
39
- while true; do
40
- # get memory usage of whole system
41
- mem_used_1=$(free -m | awk '/Mem:/ {print $3}')
42
- sleep 1
43
- mem_used_2=$(free -m | awk '/Mem:/ {print $3}')
44
- sleep 1
45
- mem_used_3=$(free -m | awk '/Mem:/ {print $3}')
46
- mem_used=$(echo "scale=2; ($mem_used_1+$mem_used_2+$mem_used_3)/3" | bc)
47
-
48
- # echo $mem_used
49
- # get rate of memory usage
50
- mem_rate=$(echo "scale=2; $mem_used/$(free -m | awk '/Mem:/ {print $2}')*100" | bc)
51
- # echo $mem_rate
52
- if [ $(echo "$mem_rate < $memory_rate_max" | bc) -eq 1 ]; then
53
- echo "total memory rate: $mem_rate is less than $memory_rate_max, continue to check my own cpu and memory usage"
54
- break
55
- else
56
- echo "total memory rate: $mem_rate is greater than $memory_rate_max, sleep 10 seconds"
57
- sleep 10
58
- fi
59
- done;
60
- fi;
61
-
62
- # if constrain_mine
63
- if [ $constrain_mine = true ]; then
64
-
65
- # check my own cpu and memory usage, it should be less than 1/$constrain_rate of the given cpu_mean_max / memory_rate_max
66
- while true; do
67
- username=$username_mine
68
- cpu_usage_user_sum=$(ps -u $username -o %cpu | awk '{sum+=$1} END {print sum}')
69
- # echo $cpu_usage_user_sum
70
- total_aviable_cpu=$(nproc)
71
- total_aviable_cpu=$(echo "$total_aviable_cpu*100" | bc)
72
- # echo $total_aviable_cpu
73
- cpu_usage_user_ratio=$(echo "scale=2; $cpu_usage_user_sum/$total_aviable_cpu*100" | bc)
74
- # echo $cpu_usage_user_ratio
75
-
76
- memory_usage_user_sum=$(ps -u $username -o rss | awk '{sum+=$1} END {print sum/1024}')
77
- # echo $memory_usage_user_sum
78
- memory_usage_total=$(free -m | awk '/Mem:/ {print $2}')
79
- # echo $memory_usage_total
80
- memory_usage_user_ratio=$(echo "scale=2; $memory_usage_user_sum/$memory_usage_total*100" | bc)
81
- # echo $memory_usage_user_ratio
82
-
83
- # so my ratio should be less than 1/$constrain_rate of the given threshold
84
- cpu_mean_max_mine=$(echo "$cpu_mean_max/$constrain_rate" | bc)
85
- memory_rate_max_mine=$(echo "$memory_rate_max/$constrain_rate" | bc)
86
- if [ $(echo "$cpu_usage_user_ratio < $cpu_mean_max_mine" | bc) -eq 1 ] && [ $(echo "$memory_usage_user_ratio < $memory_rate_max_mine" | bc) -eq 1 ]; then
87
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is less than half of the given threshold for cpu: $cpu_mean_max_mine and memory: $memory_rate_max_mine, ready to take off"
88
- break
89
- else
90
- echo "my cpu usage: $cpu_usage_user_ratio, memory usage: $memory_usage_user_ratio is greater than half of the given threshold, sleep 10 seconds"
91
- sleep 10
92
- fi
93
- done;
94
- fi;
95
-
96
- # so all the conditions are satisfied, we can update the device idx and run the next experiment
97
- while true; do
98
- current_device_idx=$((current_device_idx+1))
99
- if [ $current_device_idx -ge ${#available_devices[@]} ]; then
100
- # reset
101
- current_device_idx=0
102
- fi
103
- # check whether this device is fully booked using nvidia-smi
104
- # get the gpu current memory usage
105
- useage=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
106
- utilization=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i ${available_devices[$current_device_idx]})
107
-
108
- if [ $useage -ge $((total_aviable-max_gpu_memory_gap)) ] || [ $utilization -ge $max_gpu_utilization ]; then
109
- echo "device ${available_devices[$current_device_idx]} is fully booked, try next one"
110
- sleep 3
111
- continue
112
- else
113
- break
114
- fi
115
- done
116
- echo "current device: ${available_devices[$current_device_idx]}"
117
- device=${available_devices[$current_device_idx]}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
res/20230615-17h56m22s/script.sh DELETED
@@ -1,23 +0,0 @@
1
- cd $(cd "$(dirname "$0")";pwd); source gpu_utility.sh
2
-
3
- ##### setup
4
- export CUDA_VISIBLE_DEVICES=2
5
- source activate /data/yixin/anaconda/mib
6
- exp_name="single_user"
7
- #####
8
-
9
- ##### loop
10
- for poison_method in char_basic word_basic sent_basic; do
11
- for dataset_idx in 0 1 2; do
12
- #####
13
-
14
- update_device_idx;
15
-
16
- python single_user.py --dataset_idx $dataset_idx --trigger_size 1 --target 0 --loc 0 --batch_size 16 --num_epochs 2 --poison_method $poison_method --lr 5e-5 --pattern 0 --exp_name $exp_name --log_wb
17
-
18
- sleep $sleeptime
19
-
20
- #####
21
-
22
- #####
23
- done;done;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import time
2
+ from datetime import datetime
3
+
4
+ current_timestamp = int(time.time())
5
+ human_readable_timestamp = datetime.utcfromtimestamp(current_timestamp).strftime('%Y-%m-%d-%H')
6
+ print(human_readable_timestamp)