forked from AkaliKong/MiniOneRec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.sh
More file actions
94 lines (79 loc) · 3.28 KB
/
evaluate.sh
File metadata and controls
94 lines (79 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Industrial_and_Scientific
# Office_Products
for category in "Industrial_and_Scientific"
do
# your model path
exp_name="xxx"
exp_name_clean=$(basename "$exp_name")
echo "Processing category: $category with model: $exp_name_clean (STANDARD MODE)"
train_file=$(ls ./data/Amazon/train/${category}*.csv 2>/dev/null | head -1)
test_file=$(ls ./data/Amazon/test/${category}*11.csv 2>/dev/null | head -1)
info_file=$(ls ./data/Amazon/info/${category}*.txt 2>/dev/null | head -1)
if [[ ! -f "$test_file" ]]; then
echo "Error: Test file not found for category $category"
continue
fi
if [[ ! -f "$info_file" ]]; then
echo "Error: Info file not found for category $category"
continue
fi
temp_dir="./temp/${category}-${exp_name_clean}"
echo "Creating temp directory: $temp_dir"
mkdir -p "$temp_dir"
echo "Splitting test data..."
python ./split.py --input_path "$test_file" --output_path "$temp_dir" --cuda_list "0,1,2,3,4,5,6,7"
if [[ ! -f "$temp_dir/0.csv" ]]; then
echo "Error: Data splitting failed for category $category"
continue
fi
cudalist="0 1 2 3 4 5 6 7"
echo "Starting parallel evaluation (STANDARD MODE)..."
for i in ${cudalist}
do
if [[ -f "$temp_dir/${i}.csv" ]]; then
echo "Starting evaluation on GPU $i for category ${category}"
CUDA_VISIBLE_DEVICES=$i python -u ./evaluate.py \
--base_model "$exp_name" \
--info_file "$info_file" \
--category ${category} \
--test_data_path "$temp_dir/${i}.csv" \
--result_json_data "$temp_dir/${i}.json" \
--batch_size 8 \
--num_beams 50 \
--max_new_tokens 256 \
--temperature 1.0 \
--guidance_scale 1.0 \
--length_penalty 0.0 &
else
echo "Warning: Split file $temp_dir/${i}.csv not found, skipping GPU $i"
fi
done
echo "Waiting for all evaluation processes to complete..."
wait
result_files=$(ls "$temp_dir"/*.json 2>/dev/null | wc -l)
if [[ $result_files -eq 0 ]]; then
echo "Error: No result files generated for category $category"
continue
fi
output_dir="./results/${exp_name_clean}"
echo "Creating output directory: $output_dir"
mkdir -p "$output_dir"
actual_cuda_list=$(ls "$temp_dir"/*.json 2>/dev/null | sed 's/.*\///g' | sed 's/\.json//g' | tr '\n' ',' | sed 's/,$//')
echo "Merging results from GPUs: $actual_cuda_list"
python ./merge.py \
--input_path "$temp_dir" \
--output_path "$output_dir/final_result_${category}.json" \
--cuda_list "$actual_cuda_list"
if [[ ! -f "$output_dir/final_result_${category}.json" ]]; then
echo "Error: Result merging failed for category $category"
continue
fi
echo "Calculating metrics..."
python ./calc.py \
--path "$output_dir/final_result_${category}.json" \
--item_path "$info_file"
echo "Completed processing for category: $category"
echo "Results saved to: $output_dir/final_result_${category}.json"
echo "----------------------------------------"
done
echo "All categories processed!"