From 9b9b2ddfc701e27412f357a3bb31d237bcbbe280 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 09:17:59 +0800 Subject: [PATCH 01/24] scripts: load the final checkpoint for Inv models --- .../clone-bcb_inv-contrabert_c.sh | 2 +- .../clone-bcb_inv-contrabert_g.sh | 2 +- .../clone-codenet_C++1400_inv-contrabert_c.sh | 2 +- .../clone-codenet_C++1400_inv-contrabert_g.sh | 2 +- .../clone-codenet_Java250_inv-contrabert_c.sh | 4 +++- .../clone-codenet_Java250_inv-contrabert_g.sh | 2 +- .../clone-codenet_Python800_inv-contrabert_c.sh | 2 +- .../clone-codenet_Python800_inv-contrabert_g.sh | 2 +- .../Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh | 2 +- .../Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh | 2 +- .../cls-codenet_C++1400_inv-contrabert_c.sh | 2 +- .../cls-codenet_C++1400_inv-contrabert_g.sh | 2 +- .../cls-codenet_Java250_inv-contrabert_c.sh | 2 +- .../cls-codenet_Java250_inv-contrabert_g.sh | 2 +- .../cls-codenet_Python800_inv-contrabert_c.sh | 2 +- .../cls-codenet_Python800_inv-contrabert_g.sh | 2 +- .../cls-poj104_Cpp_inv-contrabert_c.sh | 2 +- .../cls-poj104_Cpp_inv-contrabert_g.sh | 2 +- .../Code-translation/translation_inv-contrabert_c.sh | 2 +- .../Code-translation/translation_inv-contrabert_g.sh | 2 +- .../Defect-detection/defect_inv-contrabert_c.sh | 2 +- .../Defect-detection/defect_inv-contrabert_g.sh | 2 +- experiments_downstream/gen_all.py | 4 ++-- 23 files changed, 26 insertions(+), 24 deletions(-) diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh index f037725..7b68456 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-BigCloneBench" +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh index 4ff8ed8..4603516 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-BigCloneBench" +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh index 40b89fb..e8a2a30 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh index 6ad5cce..aef5834 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh index 269102c..f601c7d 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh @@ -5,4 +5,6 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" \ + "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" \ + Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh index 1591e84..560b680 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh index ac08095..e26f718 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh index c515dc1..14e3427 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh index 9be34d9..fc33042 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-POJ104" roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-POJ104" roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh index ad23aa4..7f7e376 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Clone-detection-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-POJ104" roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-POJ104" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh index 9ff69f6..1a291d3 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh index 8d5df3c..069df73 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh index 8103c60..2460b8f 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh index 1bbfb4a..1b51fce 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh index 30269f6..44eda9d 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh index f8f6f08..02ccdd5 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh index 71a2807..82230a5 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-POJ104" Cpp roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-POJ104" Cpp roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh index 48df121..ae0d033 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh b/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh index 4aa7dfa..347e64a 100755 --- a/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh +++ b/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-translation" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Code-translation" +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh b/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh index 5000dc1..10254ef 100755 --- a/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh +++ b/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Code-translation" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Code-translation" +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-translation" diff --git a/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh b/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh index fdc2c5a..651376d 100755 --- a/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh +++ b/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Defect-detection" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon" "$ROOT_DIR/results/inv-contrabert_c/Defect-detection" +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh b/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh index 390d8db..4909ad4 100755 --- a/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh +++ b/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" cd "$ROOT_DIR/downstream/Defect-detection" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon" "$ROOT_DIR/results/inv-contrabert_g/Defect-detection" +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Defect-detection" diff --git a/experiments_downstream/gen_all.py b/experiments_downstream/gen_all.py index 3b54ad4..5491ca3 100644 --- a/experiments_downstream/gen_all.py +++ b/experiments_downstream/gen_all.py @@ -43,13 +43,13 @@ ), ( "inv-contrabert_c", - "./saved_models/InvContraBERT_C-supcon", + "./saved_models/InvContraBERT_C-supcon/final", "microsoft/codebert-base", "roberta", ), ( "inv-contrabert_g", - "./saved_models/InvContraBERT_G-supcon", + "./saved_models/InvContraBERT_G-supcon/final", "microsoft/graphcodebert-base", "roberta", ), From b8f0751a033d046060c2b936700cb40dba6ccf77 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 09:29:11 +0800 Subject: [PATCH 02/24] ignore results --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 86c194d..dd3e348 100644 --- a/.gitignore +++ b/.gitignore @@ -194,3 +194,4 @@ cplus_transforms/traverse.py *.pdf .references/* +/results/ From 24208eea63de984f6b79fe3d48efbc802f89fddd Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 09:51:26 +0800 Subject: [PATCH 03/24] take cli argument as input --- .../clone-bcb_codebert.sh | 6 ++++++ .../clone-bcb_contrabert_c.sh | 6 ++++++ .../clone-bcb_contrabert_g.sh | 6 ++++++ .../clone-bcb_graphcodebert.sh | 6 ++++++ .../clone-bcb_inv-codebert.sh | 6 ++++++ .../clone-bcb_inv-contrabert_c.sh | 6 ++++++ .../clone-bcb_inv-contrabert_g.sh | 6 ++++++ .../clone-bcb_inv-graphcodebert.sh | 6 ++++++ .../clone-codenet_C++1400_codebert.sh | 6 ++++++ .../clone-codenet_C++1400_contrabert_c.sh | 6 ++++++ .../clone-codenet_C++1400_contrabert_g.sh | 6 ++++++ .../clone-codenet_C++1400_graphcodebert.sh | 6 ++++++ .../clone-codenet_C++1400_inv-codebert.sh | 6 ++++++ .../clone-codenet_C++1400_inv-contrabert_c.sh | 6 ++++++ .../clone-codenet_C++1400_inv-contrabert_g.sh | 6 ++++++ .../clone-codenet_C++1400_inv-graphcodebert.sh | 6 ++++++ .../clone-codenet_Java250_codebert.sh | 6 ++++++ .../clone-codenet_Java250_contrabert_c.sh | 6 ++++++ .../clone-codenet_Java250_contrabert_g.sh | 6 ++++++ .../clone-codenet_Java250_graphcodebert.sh | 6 ++++++ .../clone-codenet_Java250_inv-codebert.sh | 6 ++++++ .../clone-codenet_Java250_inv-contrabert_c.sh | 10 +++++++--- .../clone-codenet_Java250_inv-contrabert_g.sh | 6 ++++++ .../clone-codenet_Java250_inv-graphcodebert.sh | 6 ++++++ .../clone-codenet_Python800_codebert.sh | 6 ++++++ .../clone-codenet_Python800_contrabert_c.sh | 6 ++++++ .../clone-codenet_Python800_contrabert_g.sh | 6 ++++++ .../clone-codenet_Python800_graphcodebert.sh | 6 ++++++ .../clone-codenet_Python800_inv-codebert.sh | 6 ++++++ .../clone-codenet_Python800_inv-contrabert_c.sh | 6 ++++++ .../clone-codenet_Python800_inv-contrabert_g.sh | 6 ++++++ .../clone-codenet_Python800_inv-graphcodebert.sh | 6 ++++++ .../Clone-detection-POJ104/clone-poj104_codebert.sh | 6 ++++++ .../clone-poj104_contrabert_c.sh | 6 ++++++ .../clone-poj104_contrabert_g.sh | 6 ++++++ .../clone-poj104_graphcodebert.sh | 6 ++++++ .../clone-poj104_inv-codebert.sh | 6 ++++++ .../clone-poj104_inv-contrabert_c.sh | 6 ++++++ .../clone-poj104_inv-contrabert_g.sh | 6 ++++++ .../clone-poj104_inv-graphcodebert.sh | 6 ++++++ .../cls-codenet_C++1400_codebert.sh | 6 ++++++ .../cls-codenet_C++1400_contrabert_c.sh | 6 ++++++ .../cls-codenet_C++1400_contrabert_g.sh | 6 ++++++ .../cls-codenet_C++1400_graphcodebert.sh | 6 ++++++ .../cls-codenet_C++1400_inv-codebert.sh | 6 ++++++ .../cls-codenet_C++1400_inv-contrabert_c.sh | 6 ++++++ .../cls-codenet_C++1400_inv-contrabert_g.sh | 6 ++++++ .../cls-codenet_C++1400_inv-graphcodebert.sh | 6 ++++++ .../cls-codenet_Java250_codebert.sh | 6 ++++++ .../cls-codenet_Java250_contrabert_c.sh | 6 ++++++ .../cls-codenet_Java250_contrabert_g.sh | 6 ++++++ .../cls-codenet_Java250_graphcodebert.sh | 6 ++++++ .../cls-codenet_Java250_inv-codebert.sh | 6 ++++++ .../cls-codenet_Java250_inv-contrabert_c.sh | 6 ++++++ .../cls-codenet_Java250_inv-contrabert_g.sh | 6 ++++++ .../cls-codenet_Java250_inv-graphcodebert.sh | 6 ++++++ .../cls-codenet_Python800_codebert.sh | 6 ++++++ .../cls-codenet_Python800_contrabert_c.sh | 6 ++++++ .../cls-codenet_Python800_contrabert_g.sh | 6 ++++++ .../cls-codenet_Python800_graphcodebert.sh | 6 ++++++ .../cls-codenet_Python800_inv-codebert.sh | 6 ++++++ .../cls-codenet_Python800_inv-contrabert_c.sh | 6 ++++++ .../cls-codenet_Python800_inv-contrabert_g.sh | 6 ++++++ .../cls-codenet_Python800_inv-graphcodebert.sh | 6 ++++++ .../cls-poj104_Cpp_codebert.sh | 6 ++++++ .../cls-poj104_Cpp_contrabert_c.sh | 6 ++++++ .../cls-poj104_Cpp_contrabert_g.sh | 6 ++++++ .../cls-poj104_Cpp_graphcodebert.sh | 6 ++++++ .../cls-poj104_Cpp_inv-codebert.sh | 6 ++++++ .../cls-poj104_Cpp_inv-contrabert_c.sh | 6 ++++++ .../cls-poj104_Cpp_inv-contrabert_g.sh | 6 ++++++ .../cls-poj104_Cpp_inv-graphcodebert.sh | 6 ++++++ .../Code-translation/translation_codebert.sh | 6 ++++++ .../Code-translation/translation_contrabert_c.sh | 6 ++++++ .../Code-translation/translation_contrabert_g.sh | 6 ++++++ .../Code-translation/translation_graphcodebert.sh | 6 ++++++ .../Code-translation/translation_inv-codebert.sh | 6 ++++++ .../Code-translation/translation_inv-contrabert_c.sh | 6 ++++++ .../Code-translation/translation_inv-contrabert_g.sh | 6 ++++++ .../Code-translation/translation_inv-graphcodebert.sh | 6 ++++++ .../Defect-detection/defect_codebert.sh | 6 ++++++ .../Defect-detection/defect_contrabert_c.sh | 6 ++++++ .../Defect-detection/defect_contrabert_g.sh | 6 ++++++ .../Defect-detection/defect_graphcodebert.sh | 6 ++++++ .../Defect-detection/defect_inv-codebert.sh | 6 ++++++ .../Defect-detection/defect_inv-contrabert_c.sh | 6 ++++++ .../Defect-detection/defect_inv-contrabert_g.sh | 6 ++++++ .../Defect-detection/defect_inv-graphcodebert.sh | 6 ++++++ experiments_downstream/gen_all.py | 6 ++++++ 89 files changed, 535 insertions(+), 3 deletions(-) diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_codebert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_codebert.sh index f934894..275290c 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_codebert.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_c.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_c.sh index 3160e0b..d59981f 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_c.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_g.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_g.sh index 1c83546..d87a720 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_g.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_graphcodebert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_graphcodebert.sh index 9421fa4..ff65f51 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_graphcodebert.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh index cbcf312..f5f7921 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh index 7b68456..654585a 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh index 4603516..2404aac 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh index 4c6d4a6..3a2aa1e 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-BigCloneBench with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_codebert.sh index 06a7a1a..92dae63 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_c.sh index 1ac93ab..5746536 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_g.sh index 9980723..09a946f 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_graphcodebert.sh index 232b7d7..d5f7849 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh index 1fd8e12..2e7ebc7 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh index e8a2a30..2c4640e 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh index aef5834..8cac84d 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh index 82568e4..1ea2e05 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (C++1400) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_codebert.sh index f584af0..ea86a95 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_c.sh index e2f33f4..5d795d9 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_g.sh index 5c45ae0..61bd93a 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_graphcodebert.sh index a228875..8c8fcc2 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh index ce83d95..3e8bbce 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh index f601c7d..14e57e0 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_c.sh @@ -1,10 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" \ - "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" \ - Java250 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh index 560b680..55faa2b 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh index b298954..0884879 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Java250) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_codebert.sh index 8f4affc..1b46200 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_c.sh index 7c7291d..7b7839b 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_g.sh index 211c493..a2e5190 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_graphcodebert.sh index 926a7fa..a45be28 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh index 9d684bc..2bf8cf7 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh index e26f718..a6a86cf 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh index 14e3427..1ccf942 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh index 05e3cb2..6ee9e5b 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-CodeNet (Python800) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_codebert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_codebert.sh index dc50820..3c11b52 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_codebert.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Clone-detection-POJ104" roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_c.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_c.sh index c5c1f1f..98b0176 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_c.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Clone-detection-POJ104" roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_g.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_g.sh index f481c1c..ccb63ee 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_g.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Clone-detection-POJ104" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_graphcodebert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_graphcodebert.sh index a154952..66c499f 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_graphcodebert.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Clone-detection-POJ104" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh index 953b883..e98c640 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-POJ104" roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh index fc33042..ce105db 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Clone-detection-POJ104" roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh index 7f7e376..54d6503 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Clone-detection-POJ104" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh index ec5fff5..18bb9e3 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Clone-detection-POJ104 with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Clone-detection-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-POJ104" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_codebert.sh index a7098eb..31382b8 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_c.sh index 5f25b48..9665711 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_g.sh index 77eb658..e68a245 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_graphcodebert.sh index 420b007..3e93ac1 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh index 2552f68..05c3e7e 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh index 1a291d3..ac30e81 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh index 069df73..61b20de 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh index caed086..a69b7c8 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (C++1400) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_codebert.sh index 8e7ea16..4aa0e51 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_c.sh index 4f27974..47dc5a2 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_g.sh index 0fd50b1..592b704 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_graphcodebert.sh index fe99ed7..515cd6c 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh index 69e8108..6d4e77e 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh index 2460b8f..4b79406 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh index 1b51fce..c78d8de 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh index 97a648c..ac6e17e 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Java250) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_codebert.sh index 39fb03c..1c3389d 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_c.sh index 1aa25b7..69aba3d 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_g.sh index f1cef41..45d606b 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_graphcodebert.sh index aca03e6..5286874 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh index a8f6379..d7992e7 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh index 44eda9d..cc03fe7 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh index 02ccdd5..5fab41d 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh index b67e352..4998a2b 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-CodeNet (Python800) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-CodeNet" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh index f406cf7..182cc41 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-classification-POJ104" Cpp roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh index f9fa75e..ca20d20 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-classification-POJ104" Cpp roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh index a87fb4f..5bc3d62 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh index aa05ab0..34c273f 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh index 0306d6f..f9ec35c 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-POJ104" Cpp roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh index 82230a5..271fb4d 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-POJ104" Cpp roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh index ae0d033..9279c88 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh index db645bd..ae2e925 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-classification-POJ104" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-translation/translation_codebert.sh b/experiments_downstream/Code-translation/translation_codebert.sh index 4e1156a..07d81d6 100755 --- a/experiments_downstream/Code-translation/translation_codebert.sh +++ b/experiments_downstream/Code-translation/translation_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_contrabert_c.sh b/experiments_downstream/Code-translation/translation_contrabert_c.sh index 35eb1cf..c70ba5f 100755 --- a/experiments_downstream/Code-translation/translation_contrabert_c.sh +++ b/experiments_downstream/Code-translation/translation_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_contrabert_g.sh b/experiments_downstream/Code-translation/translation_contrabert_g.sh index b273b76..42a02c0 100755 --- a/experiments_downstream/Code-translation/translation_contrabert_g.sh +++ b/experiments_downstream/Code-translation/translation_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_graphcodebert.sh b/experiments_downstream/Code-translation/translation_graphcodebert.sh index 9a61086..afd3dcc 100755 --- a/experiments_downstream/Code-translation/translation_graphcodebert.sh +++ b/experiments_downstream/Code-translation/translation_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_inv-codebert.sh b/experiments_downstream/Code-translation/translation_inv-codebert.sh index 91621d0..f227b4f 100755 --- a/experiments_downstream/Code-translation/translation_inv-codebert.sh +++ b/experiments_downstream/Code-translation/translation_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh b/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh index 347e64a..4f13441 100755 --- a/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh +++ b/experiments_downstream/Code-translation/translation_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh b/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh index 10254ef..bbc7036 100755 --- a/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh +++ b/experiments_downstream/Code-translation/translation_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh b/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh index 759ca8a..34725a7 100755 --- a/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh +++ b/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Code-translation with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Code-translation" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-translation" diff --git a/experiments_downstream/Defect-detection/defect_codebert.sh b/experiments_downstream/Defect-detection/defect_codebert.sh index f9d68b2..86418c6 100755 --- a/experiments_downstream/Defect-detection/defect_codebert.sh +++ b/experiments_downstream/Defect-detection/defect_codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_contrabert_c.sh b/experiments_downstream/Defect-detection/defect_contrabert_c.sh index fbd9e5c..f2136f5 100755 --- a/experiments_downstream/Defect-detection/defect_contrabert_c.sh +++ b/experiments_downstream/Defect-detection/defect_contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_contrabert_g.sh b/experiments_downstream/Defect-detection/defect_contrabert_g.sh index 57caab6..6e0c441 100755 --- a/experiments_downstream/Defect-detection/defect_contrabert_g.sh +++ b/experiments_downstream/Defect-detection/defect_contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_graphcodebert.sh b/experiments_downstream/Defect-detection/defect_graphcodebert.sh index 3ef89f9..ca81163 100755 --- a/experiments_downstream/Defect-detection/defect_graphcodebert.sh +++ b/experiments_downstream/Defect-detection/defect_graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_inv-codebert.sh b/experiments_downstream/Defect-detection/defect_inv-codebert.sh index 930e26f..a32de11 100755 --- a/experiments_downstream/Defect-detection/defect_inv-codebert.sh +++ b/experiments_downstream/Defect-detection/defect_inv-codebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with inv-codebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh b/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh index 651376d..315aa99 100755 --- a/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh +++ b/experiments_downstream/Defect-detection/defect_inv-contrabert_c.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with inv-contrabert_c set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh b/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh index 4909ad4..9fc514b 100755 --- a/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh +++ b/experiments_downstream/Defect-detection/defect_inv-contrabert_g.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with inv-contrabert_g set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh b/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh index 1b40338..8c15850 100755 --- a/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh +++ b/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh @@ -1,8 +1,14 @@ #!/bin/bash # Downstream evaluation: Defect-detection with inv-graphcodebert set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + cd "$ROOT_DIR/downstream/Defect-detection" ./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Defect-detection" diff --git a/experiments_downstream/gen_all.py b/experiments_downstream/gen_all.py index 5491ca3..3f831ff 100644 --- a/experiments_downstream/gen_all.py +++ b/experiments_downstream/gen_all.py @@ -84,9 +84,15 @@ def make_script( "#!/bin/bash", f"# Downstream evaluation: {task_dir}{sl} with {short}", "set -euo pipefail", + "", + "# Parse CUDA device argument (default: 0)", + 'CUDA_DEVICE="${1:-0}"', + "", SD_LINE, RD_LINE, "", + 'export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE"', + "", f'cd "{D}ROOT_DIR/downstream/{task_dir}"', f"./run.sh {mr} {op}{args_extra}", "", From 0b9d594ddf527b7102ba4a905731e170a2955a37 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 10:28:54 +0800 Subject: [PATCH 04/24] Add ModernBERT downstream eval scripts and docs --- AGENTS.md | 3 +++ README.md | 3 +++ .../clone-bcb_inv-modernbert.sh | 14 ++++++++++++ .../clone-codenet_C++1400_inv-modernbert.sh | 14 ++++++++++++ .../clone-codenet_Java250_inv-modernbert.sh | 14 ++++++++++++ .../clone-codenet_Python800_inv-modernbert.sh | 14 ++++++++++++ .../clone-poj104_inv-modernbert.sh | 14 ++++++++++++ .../cls-codenet_C++1400_inv-modernbert.sh | 14 ++++++++++++ .../cls-codenet_Java250_inv-modernbert.sh | 14 ++++++++++++ .../cls-codenet_Python800_inv-modernbert.sh | 14 ++++++++++++ .../cls-poj104_Cpp_inv-modernbert.sh | 14 ++++++++++++ .../translation_inv-modernbert.sh | 14 ++++++++++++ .../Defect-detection/defect_inv-modernbert.sh | 14 ++++++++++++ experiments_downstream/gen_all.py | 22 +++++++++++++++---- 14 files changed, 178 insertions(+), 4 deletions(-) create mode 100755 experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-modernbert.sh create mode 100755 experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-modernbert.sh create mode 100755 experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-modernbert.sh create mode 100755 experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-modernbert.sh create mode 100755 experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-modernbert.sh create mode 100755 experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-modernbert.sh create mode 100755 experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-modernbert.sh create mode 100755 experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-modernbert.sh create mode 100755 experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh create mode 100755 experiments_downstream/Code-translation/translation_inv-modernbert.sh create mode 100755 experiments_downstream/Defect-detection/defect_inv-modernbert.sh diff --git a/AGENTS.md b/AGENTS.md index 7afb14c..3c3be48 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -136,6 +136,9 @@ cd downstream/Clone-detection-POJ-104 ./run.sh ``` +Pre-generated per-model evaluation scripts live in `experiments_downstream/`, including +ModernBERT variants. Regenerate them with `python3 experiments_downstream/gen_all.py`. + Metrics: MAP@R for clone detection, accuracy for defect detection and code classification. ## Code Conventions diff --git a/README.md b/README.md index c13f1f4..b9e1b81 100755 --- a/README.md +++ b/README.md @@ -262,6 +262,9 @@ cd downstream/Clone-detection-POJ-104 ./run.sh ``` +Pre-generated per-model evaluation scripts live in `experiments_downstream/`, including +ModernBERT variants. Regenerate them with `python3 experiments_downstream/gen_all.py`. + To evaluate robustness, use the augmented test scripts: ```sh diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-modernbert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-modernbert.sh new file mode 100755 index 0000000..f30bce8 --- /dev/null +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Clone-detection-BigCloneBench with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-modernbert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-modernbert.sh new file mode 100755 index 0000000..8f20cde --- /dev/null +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Clone-detection-CodeNet (C++1400) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Clone-detection-CodeNet" C++1400 modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-modernbert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-modernbert.sh new file mode 100755 index 0000000..407f06a --- /dev/null +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Clone-detection-CodeNet (Java250) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Clone-detection-CodeNet" Java250 modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-modernbert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-modernbert.sh new file mode 100755 index 0000000..d00f72f --- /dev/null +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Clone-detection-CodeNet (Python800) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Clone-detection-CodeNet" Python800 modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-modernbert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-modernbert.sh new file mode 100755 index 0000000..f6bd6c4 --- /dev/null +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Clone-detection-POJ104 with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Clone-detection-POJ104" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Clone-detection-POJ104" modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-modernbert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-modernbert.sh new file mode 100755 index 0000000..aef8d25 --- /dev/null +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Code-classification-CodeNet (C++1400) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Code-classification-CodeNet" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-classification-CodeNet" C++1400 modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-modernbert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-modernbert.sh new file mode 100755 index 0000000..d3e99f7 --- /dev/null +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Code-classification-CodeNet (Java250) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Code-classification-CodeNet" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-classification-CodeNet" Java250 modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-modernbert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-modernbert.sh new file mode 100755 index 0000000..416d497 --- /dev/null +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Code-classification-CodeNet (Python800) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Code-classification-CodeNet" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-classification-CodeNet" Python800 modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh new file mode 100755 index 0000000..fb4c60e --- /dev/null +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Code-classification-POJ104" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-classification-POJ104" Cpp modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/Code-translation/translation_inv-modernbert.sh b/experiments_downstream/Code-translation/translation_inv-modernbert.sh new file mode 100755 index 0000000..16fdbf2 --- /dev/null +++ b/experiments_downstream/Code-translation/translation_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Code-translation with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Code-translation" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-translation" diff --git a/experiments_downstream/Defect-detection/defect_inv-modernbert.sh b/experiments_downstream/Defect-detection/defect_inv-modernbert.sh new file mode 100755 index 0000000..03b85d3 --- /dev/null +++ b/experiments_downstream/Defect-detection/defect_inv-modernbert.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Downstream evaluation: Defect-detection with inv-modernbert +set -euo pipefail + +# Parse CUDA device argument (default: 0) +CUDA_DEVICE="${1:-0}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" + +cd "$ROOT_DIR/downstream/Defect-detection" +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Defect-detection" diff --git a/experiments_downstream/gen_all.py b/experiments_downstream/gen_all.py index 3f831ff..668a0b2 100644 --- a/experiments_downstream/gen_all.py +++ b/experiments_downstream/gen_all.py @@ -53,6 +53,12 @@ "microsoft/graphcodebert-base", "roberta", ), + ( + "inv-modernbert", + "./saved_models/aug-only/InvModernBERT-supcon/final", + "answerdotai/ModernBERT-base", + "modernbert", + ), ] # These are the literal shell lines we want in the output. @@ -69,6 +75,13 @@ def model_ref(model_path: str) -> str: return model_path +def tokenizer_ref(tokenizer_path: str) -> str: + """Return the shell expression for the tokenizer path.""" + if tokenizer_path.startswith("./"): + return f'"{D}ROOT_DIR/{tokenizer_path[2:]}"' + return tokenizer_path + + def make_script( task_dir: str, short: str, @@ -110,12 +123,13 @@ def write_script(task_dir: str, fname: str, content: str) -> None: count = 0 for short, mpath, tok, mtype in models: + tok_ref = tokenizer_ref(tok) # Clone-detection-POJ104: run.sh write_script( "Clone-detection-POJ104", f"clone-poj104_{short}.sh", make_script( - "Clone-detection-POJ104", short, mpath, args_extra=f" {mtype} {tok}" + "Clone-detection-POJ104", short, mpath, args_extra=f" {mtype} {tok_ref}" ), ) count += 1 @@ -130,7 +144,7 @@ def write_script(task_dir: str, fname: str, content: str) -> None: short, mpath, subset=sub, - args_extra=f" {sub} {mtype} {tok}", + args_extra=f" {sub} {mtype} {tok_ref}", ), ) count += 1 @@ -152,7 +166,7 @@ def write_script(task_dir: str, fname: str, content: str) -> None: short, mpath, subset="Cpp", - args_extra=f" Cpp {mtype} {tok}", + args_extra=f" Cpp {mtype} {tok_ref}", ), ) count += 1 @@ -167,7 +181,7 @@ def write_script(task_dir: str, fname: str, content: str) -> None: short, mpath, subset=sub, - args_extra=f" {sub} {mtype} {tok}", + args_extra=f" {sub} {mtype} {tok_ref}", ), ) count += 1 From ae0abc8c7b141b086681890007bb764bb83e0442 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 13:22:05 +0800 Subject: [PATCH 05/24] concurrent script to run all --- README.md | 13 + experiments_downstream/run_all_downstream.py | 239 +++++++++++++++++++ 2 files changed, 252 insertions(+) create mode 100644 experiments_downstream/run_all_downstream.py diff --git a/README.md b/README.md index b9e1b81..53ef06e 100755 --- a/README.md +++ b/README.md @@ -265,6 +265,19 @@ cd downstream/Clone-detection-POJ-104 Pre-generated per-model evaluation scripts live in `experiments_downstream/`, including ModernBERT variants. Regenerate them with `python3 experiments_downstream/gen_all.py`. +To launch the 8 downstream tasks (clone detection + code classification across POJ and +CodeNet) in parallel on 8 GPUs, use the helper script in `experiments_downstream/`: + +```sh +python experiments_downstream/run_all_downstream.py --loss supcon --model inv-codebert +``` + +Override GPU ids with `--gpus` (comma-separated, must be 8): + +```sh +python experiments_downstream/run_all_downstream.py --loss supcon --model inv-codebert --gpus 0,1,2,3,4,5,6,7 +``` + To evaluate robustness, use the augmented test scripts: ```sh diff --git a/experiments_downstream/run_all_downstream.py b/experiments_downstream/run_all_downstream.py new file mode 100644 index 0000000..5e14ec3 --- /dev/null +++ b/experiments_downstream/run_all_downstream.py @@ -0,0 +1,239 @@ +#!/usr/bin/env python3 +"""Launch downstream tasks in parallel across 8 GPUs.""" + +from __future__ import annotations + +import os +import subprocess +from dataclasses import dataclass +from pathlib import Path +from typing import TextIO + +import typer + + +@dataclass(frozen=True) +class ModelSpec: + model_path: str + tokenizer_name: str + model_type: str + + +@dataclass(frozen=True) +class RunHandle: + label: str + process: subprocess.Popen + log_file: TextIO + + +MODELS: dict[tuple[str, str], ModelSpec] = { + ("inv-codebert", "supcon"): ModelSpec( + "./saved_models/InvCodeBERT-supcon/final", + "microsoft/codebert-base", + "roberta", + ), + ("inv-graphcodebert", "supcon"): ModelSpec( + "./saved_models/InvGraphCodeBERT-supcon/final", + "microsoft/graphcodebert-base", + "roberta", + ), + ("inv-contrabert_c", "supcon"): ModelSpec( + "./saved_models/InvContraBERT_C-supcon/final", + "microsoft/codebert-base", + "roberta", + ), + ("inv-contrabert_g", "supcon"): ModelSpec( + "./saved_models/InvContraBERT_G-supcon/final", + "microsoft/graphcodebert-base", + "roberta", + ), + ("inv-modernbert", "supcon"): ModelSpec( + "./saved_models/aug-only/InvModernBERT-supcon/final", + "answerdotai/ModernBERT-base", + "modernbert", + ), +} + + +TASKS = [ + ("Clone-detection-POJ104", None), + ("Clone-detection-CodeNet", "Java250"), + ("Clone-detection-CodeNet", "Python800"), + ("Clone-detection-CodeNet", "C++1400"), + ("Code-classification-POJ104", "Cpp"), + ("Code-classification-CodeNet", "Java250"), + ("Code-classification-CodeNet", "Python800"), + ("Code-classification-CodeNet", "C++1400"), +] + + +app = typer.Typer(add_completion=False, no_args_is_help=True) + + +def resolve_model(model_key: str, loss: str) -> ModelSpec: + key = (model_key, loss) + if key not in MODELS: + available = ", ".join( + f"{model}/{loss_key}" + for model, loss_key in sorted(MODELS.keys(), key=lambda x: (x[0], x[1])) + ) + raise typer.BadParameter( + f"Unknown model/loss: {model_key}/{loss}. Available: {available}" + ) + return MODELS[key] + + +def run_task( + root: Path, + model_key: str, + spec: ModelSpec, + task_dir: str, + subset: str | None, + gpu_id: str, + results_root: Path, + dry_run: bool, +) -> RunHandle | None: + task_path = root / "downstream" / task_dir + model_path = spec.model_path + if model_path.startswith("./"): + model_path = str((root / model_path[2:]).resolve()) + + results_base = results_root / model_key / task_dir + results_base_str = str(results_base.resolve()) + log_path = results_base / "run.log" + + cmd = ["./run.sh", model_path] + if task_dir == "Clone-detection-POJ104": + cmd.extend([results_base_str, spec.model_type, spec.tokenizer_name]) + elif task_dir == "Clone-detection-CodeNet": + if subset is None: + raise ValueError("Subset is required for Clone-detection-CodeNet") + cmd.extend( + [ + results_base_str, + subset, + spec.model_type, + spec.tokenizer_name, + ] + ) + elif task_dir == "Code-classification-POJ104": + if subset is None: + raise ValueError("Subset is required for Code-classification-POJ104") + cmd.extend( + [ + results_base_str, + subset, + spec.model_type, + spec.tokenizer_name, + ] + ) + elif task_dir == "Code-classification-CodeNet": + if subset is None: + raise ValueError("Subset is required for Code-classification-CodeNet") + cmd.extend( + [ + results_base_str, + subset, + spec.model_type, + spec.tokenizer_name, + ] + ) + else: + raise ValueError(f"Unsupported task: {task_dir}") + + env = os.environ.copy() + env["CUDA_VISIBLE_DEVICES"] = gpu_id + + label = f"{task_dir}{'/' + subset if subset else ''}" + if dry_run: + print(f"[launch] GPU {gpu_id}: {label}") + print(f" cwd: {task_path}") + print(f" cmd: {' '.join(cmd)}") + return None + + results_base.mkdir(parents=True, exist_ok=True) + log_file = log_path.open("w") + log_file.write(f"[launch] GPU {gpu_id}: {label}\n") + log_file.write(f"[launch] cwd: {task_path}\n") + log_file.write(f"[launch] cmd: {' '.join(cmd)}\n\n") + log_file.flush() + proc = subprocess.Popen( + cmd, + cwd=str(task_path), + env=env, + stdout=log_file, + stderr=subprocess.STDOUT, + ) + return RunHandle(label=label, process=proc, log_file=log_file) + + +@app.command() +def main( + loss: str = typer.Option( + ..., "--loss", help="Training loss identifier (e.g., supcon)." + ), + model: str = typer.Option( + ..., "--model", help="Pretrained model key (e.g., inv-codebert)." + ), + gpus: str = typer.Option( + "0,1,2,3,4,5,6,7", + "--gpus", + help="Comma-separated GPU ids to use (must be 8).", + ), + results_root: str = typer.Option( + "results", "--results-root", help="Base output directory for results." + ), + dry_run: bool = typer.Option( + False, "--dry-run", help="Print commands without executing them." + ), +) -> None: + root = Path(__file__).resolve().parents[1] + + model_key = model.strip() + loss_key = loss.strip() + spec = resolve_model(model_key, loss_key) + + gpu_ids = [gpu.strip() for gpu in gpus.split(",") if gpu.strip()] + if len(gpu_ids) != len(TASKS): + raise typer.BadParameter( + f"Expected {len(TASKS)} GPU ids, got {len(gpu_ids)}: {gpu_ids}" + ) + + results_root_path = Path(results_root).resolve() + + processes: list[RunHandle] = [] + for (task_dir, subset), gpu_id in zip(TASKS, gpu_ids, strict=True): + proc = run_task( + root, + model_key, + spec, + task_dir, + subset, + gpu_id, + results_root_path, + dry_run, + ) + if proc is not None: + processes.append(proc) + + if dry_run: + raise typer.Exit(0) + + failures: list[str] = [] + for handle in processes: + code = handle.process.wait() + handle.log_file.close() + if code != 0: + failures.append(f"{handle.label} (exit {code})") + + if failures: + print("\n[error] Some tasks failed:") + for failure in failures: + print(f" - {failure}") + raise typer.Exit(1) + + print("\n[done] All downstream tasks completed successfully.") + + +if __name__ == "__main__": + app() From ed68f3f632ff6fe1cad17a0595e6a84c1226d132 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 13:28:00 +0800 Subject: [PATCH 06/24] run all models --- run.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 run.sh diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..d7d6381 --- /dev/null +++ b/run.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +loss="supcon" +models=( + "inv-codebert" + "inv-graphcodebert" + "inv-contrabert_c" + "inv-contrabert_g" + "codebert" + "graphcodebert" + "contrabert_c" + "contrabert_g" + # "inv-modernbert" + # "modernbert" +) + +for model in "${models[@]}"; do + uv run experiments_downstream/run_all_downstream.py \ + --loss "${loss}" \ + --model "${model}" +done From b225988073ca466bef6d0fcd951ba7427cef7309 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 13:30:24 +0800 Subject: [PATCH 07/24] add progress bar --- run.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index d7d6381..8beb414 100644 --- a/run.sh +++ b/run.sh @@ -15,8 +15,26 @@ models=( # "modernbert" ) +total_models=${#models[@]} +current=0 + +render_progress() { + local idx="$1" + local total="$2" + local width=30 + local filled=$((idx * width / total)) + local empty=$((width - filled)) + local bar + bar="$(printf '%*s' "${filled}" '' | tr ' ' '#')" + bar+="$(printf '%*s' "${empty}" '' | tr ' ' '-')" + printf "[%s] %d/%d" "${bar}" "${idx}" "${total}" +} + for model in "${models[@]}"; do - uv run experiments_downstream/run_all_downstream.py \ - --loss "${loss}" \ - --model "${model}" + current=$((current + 1)) + progress_line=$(render_progress "${current}" "${total_models}") + printf "%s %s\n" "${progress_line}" "${model}" + uv run experiments_downstream/run_all_downstream.py \ + --loss "${loss}" \ + --model "${model}" done From 94ae105032e9ace6a34c66034aed77913c074748 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 13:48:22 +0800 Subject: [PATCH 08/24] route downstream outputs per subtask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Write each CodeNet/POJ104 subset to its own results folder so logs and artifacts don’t collide when running tasks in parallel. --- README.md | 3 ++- downstream/Clone-detection-CodeNet/run.sh | 7 ++++++- .../Clone-detection-CodeNet/run_aug_test.sh | 7 ++++++- downstream/Code-classification-CodeNet/run.sh | 7 ++++++- .../Code-classification-CodeNet/run_aug_test.sh | 7 ++++++- downstream/Code-classification-POJ104/run.sh | 7 ++++++- .../Code-classification-POJ104/run_aug_test.sh | 7 ++++++- experiments_downstream/run_all_downstream.py | 15 ++++++++------- 8 files changed, 46 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 53ef06e..ee6add7 100755 --- a/README.md +++ b/README.md @@ -266,7 +266,8 @@ Pre-generated per-model evaluation scripts live in `experiments_downstream/`, in ModernBERT variants. Regenerate them with `python3 experiments_downstream/gen_all.py`. To launch the 8 downstream tasks (clone detection + code classification across POJ and -CodeNet) in parallel on 8 GPUs, use the helper script in `experiments_downstream/`: +CodeNet) in parallel on 8 GPUs, use the helper script in `experiments_downstream/`. +Each subtask writes to its own output directory (e.g., `results////`): ```sh python experiments_downstream/run_all_downstream.py --loss supcon --model inv-codebert diff --git a/downstream/Clone-detection-CodeNet/run.sh b/downstream/Clone-detection-CodeNet/run.sh index d5fbaef..198d298 100755 --- a/downstream/Clone-detection-CodeNet/run.sh +++ b/downstream/Clone-detection-CodeNet/run.sh @@ -5,7 +5,12 @@ subset=$3 model_type=${4:-roberta} tokenizer_name=${5:-roberta-base} -output_dir=$save_path/$subset +base_name=$(basename "$save_path") +if [ "$base_name" = "$subset" ]; then + output_dir=$save_path +else + output_dir=$save_path/$subset +fi mkdir -p $output_dir touch $output_dir/train.log diff --git a/downstream/Clone-detection-CodeNet/run_aug_test.sh b/downstream/Clone-detection-CodeNet/run_aug_test.sh index dc06ce8..8d62804 100755 --- a/downstream/Clone-detection-CodeNet/run_aug_test.sh +++ b/downstream/Clone-detection-CodeNet/run_aug_test.sh @@ -5,7 +5,12 @@ subset=$3 model_type=${4:-roberta} tokenizer_name=${5:-roberta-base} -output_dir=$save_path/$subset +base_name=$(basename "$save_path") +if [ "$base_name" = "$subset" ]; then + output_dir=$save_path +else + output_dir=$save_path/$subset +fi mkdir -p $output_dir touch $output_dir/aug_train.log diff --git a/downstream/Code-classification-CodeNet/run.sh b/downstream/Code-classification-CodeNet/run.sh index 2c4d515..dd3c68d 100755 --- a/downstream/Code-classification-CodeNet/run.sh +++ b/downstream/Code-classification-CodeNet/run.sh @@ -5,7 +5,12 @@ subset=$3 model_type=${4:-roberta} tokenizer_name=${5:-microsoft/codebert-base} -output_dir=$save_path/$subset +base_name=$(basename "$save_path") +if [ "$base_name" = "$subset" ]; then + output_dir=$save_path +else + output_dir=$save_path/$subset +fi mkdir -p $output_dir touch $output_dir/test_train.log diff --git a/downstream/Code-classification-CodeNet/run_aug_test.sh b/downstream/Code-classification-CodeNet/run_aug_test.sh index bcfe01f..1e9bf94 100755 --- a/downstream/Code-classification-CodeNet/run_aug_test.sh +++ b/downstream/Code-classification-CodeNet/run_aug_test.sh @@ -5,7 +5,12 @@ subset=$3 model_type=${4:-roberta} tokenizer_name=${5:-microsoft/codebert-base} -output_dir=$save_path/$subset +base_name=$(basename "$save_path") +if [ "$base_name" = "$subset" ]; then + output_dir=$save_path +else + output_dir=$save_path/$subset +fi mkdir -p $output_dir touch $output_dir/test_train.log diff --git a/downstream/Code-classification-POJ104/run.sh b/downstream/Code-classification-POJ104/run.sh index 963d538..971642c 100755 --- a/downstream/Code-classification-POJ104/run.sh +++ b/downstream/Code-classification-POJ104/run.sh @@ -5,7 +5,12 @@ subset=$3 model_type=${4:-roberta} tokenizer_name=${5:-microsoft/codebert-base} -output_dir=$save_path/$subset +base_name=$(basename "$save_path") +if [ "$base_name" = "$subset" ]; then + output_dir=$save_path +else + output_dir=$save_path/$subset +fi mkdir -p $output_dir touch $output_dir/test_train.log diff --git a/downstream/Code-classification-POJ104/run_aug_test.sh b/downstream/Code-classification-POJ104/run_aug_test.sh index bcfe01f..1e9bf94 100755 --- a/downstream/Code-classification-POJ104/run_aug_test.sh +++ b/downstream/Code-classification-POJ104/run_aug_test.sh @@ -5,7 +5,12 @@ subset=$3 model_type=${4:-roberta} tokenizer_name=${5:-microsoft/codebert-base} -output_dir=$save_path/$subset +base_name=$(basename "$save_path") +if [ "$base_name" = "$subset" ]; then + output_dir=$save_path +else + output_dir=$save_path/$subset +fi mkdir -p $output_dir touch $output_dir/test_train.log diff --git a/experiments_downstream/run_all_downstream.py b/experiments_downstream/run_all_downstream.py index 5e14ec3..b63a2f3 100644 --- a/experiments_downstream/run_all_downstream.py +++ b/experiments_downstream/run_all_downstream.py @@ -99,18 +99,19 @@ def run_task( model_path = str((root / model_path[2:]).resolve()) results_base = results_root / model_key / task_dir - results_base_str = str(results_base.resolve()) - log_path = results_base / "run.log" + results_dir = results_base / subset if subset else results_base + results_dir_str = str(results_dir.resolve()) + log_path = results_dir / "run.log" cmd = ["./run.sh", model_path] if task_dir == "Clone-detection-POJ104": - cmd.extend([results_base_str, spec.model_type, spec.tokenizer_name]) + cmd.extend([results_dir_str, spec.model_type, spec.tokenizer_name]) elif task_dir == "Clone-detection-CodeNet": if subset is None: raise ValueError("Subset is required for Clone-detection-CodeNet") cmd.extend( [ - results_base_str, + results_dir_str, subset, spec.model_type, spec.tokenizer_name, @@ -121,7 +122,7 @@ def run_task( raise ValueError("Subset is required for Code-classification-POJ104") cmd.extend( [ - results_base_str, + results_dir_str, subset, spec.model_type, spec.tokenizer_name, @@ -132,7 +133,7 @@ def run_task( raise ValueError("Subset is required for Code-classification-CodeNet") cmd.extend( [ - results_base_str, + results_dir_str, subset, spec.model_type, spec.tokenizer_name, @@ -151,7 +152,7 @@ def run_task( print(f" cmd: {' '.join(cmd)}") return None - results_base.mkdir(parents=True, exist_ok=True) + results_dir.mkdir(parents=True, exist_ok=True) log_file = log_path.open("w") log_file.write(f"[launch] GPU {gpu_id}: {label}\n") log_file.write(f"[launch] cwd: {task_path}\n") From 7222ad6c7ff0634b8949d3e9f33c44dbcc56ba10 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 14:48:24 +0800 Subject: [PATCH 09/24] fix: POJ104 Code classification path --- downstream/Code-classification-POJ104/run.sh | 11 ++++++++--- downstream/Code-classification-POJ104/run_aug_test.sh | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/downstream/Code-classification-POJ104/run.sh b/downstream/Code-classification-POJ104/run.sh index 971642c..292cf66 100755 --- a/downstream/Code-classification-POJ104/run.sh +++ b/downstream/Code-classification-POJ104/run.sh @@ -16,6 +16,11 @@ mkdir -p $output_dir touch $output_dir/test_train.log echo "Running fine-tuning for POJ104" +train_suffix="" +if [ -n "$subset" ]; then + train_suffix="/$subset" +fi + python ./code/run.py \ --output_dir=$output_dir \ --model_type=$model_type \ @@ -23,9 +28,9 @@ python ./code/run.py \ --model_name_or_path=$model_path \ --do_train \ --do_test \ - --train_data_file=./dataset/$subset/train.jsonl \ - --eval_data_file=./dataset/$subset/valid.jsonl \ - --test_data_file=./dataset/$subset/test.jsonl \ + --train_data_file=./dataset${train_suffix}/train.jsonl \ + --eval_data_file=./dataset${train_suffix}/valid.jsonl \ + --test_data_file=./dataset${train_suffix}/test.jsonl \ --num_train_epochs 10 \ --block_size 512 \ --train_batch_size 32 \ diff --git a/downstream/Code-classification-POJ104/run_aug_test.sh b/downstream/Code-classification-POJ104/run_aug_test.sh index 1e9bf94..6abcc64 100755 --- a/downstream/Code-classification-POJ104/run_aug_test.sh +++ b/downstream/Code-classification-POJ104/run_aug_test.sh @@ -15,15 +15,20 @@ fi mkdir -p $output_dir touch $output_dir/test_train.log +train_suffix="" +if [ -n "$subset" ]; then + train_suffix="/$subset" +fi + python ./code/run.py \ --output_dir=$output_dir \ --model_type=$model_type \ --tokenizer_name=$tokenizer_name \ --model_name_or_path=$model_path \ --do_test \ - --train_data_file=./dataset/$subset/train.jsonl \ - --eval_data_file=./dataset/$subset/valid.jsonl \ - --test_data_file=./dataset/$subset/aug_test.jsonl \ + --train_data_file=./dataset${train_suffix}/train.jsonl \ + --eval_data_file=./dataset${train_suffix}/valid.jsonl \ + --test_data_file=./dataset${train_suffix}/aug_test.jsonl \ --num_train_epochs 5 \ --block_size 256 \ --train_batch_size 8 \ From fd0e48ba983541379a5debcb50cd69a7a54e6619 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 14:48:37 +0800 Subject: [PATCH 10/24] fix runner script Code-classification-POJ104 path logic --- experiments_downstream/run_all_downstream.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/experiments_downstream/run_all_downstream.py b/experiments_downstream/run_all_downstream.py index b63a2f3..59e42c6 100644 --- a/experiments_downstream/run_all_downstream.py +++ b/experiments_downstream/run_all_downstream.py @@ -60,7 +60,7 @@ class RunHandle: ("Clone-detection-CodeNet", "Java250"), ("Clone-detection-CodeNet", "Python800"), ("Clone-detection-CodeNet", "C++1400"), - ("Code-classification-POJ104", "Cpp"), + ("Code-classification-POJ104", None), ("Code-classification-CodeNet", "Java250"), ("Code-classification-CodeNet", "Python800"), ("Code-classification-CodeNet", "C++1400"), @@ -118,12 +118,11 @@ def run_task( ] ) elif task_dir == "Code-classification-POJ104": - if subset is None: - raise ValueError("Subset is required for Code-classification-POJ104") + subset_arg = subset or "" cmd.extend( [ results_dir_str, - subset, + subset_arg, spec.model_type, spec.tokenizer_name, ] From fe6962e29fa74ef01a9dab01f365649ec0f8c368 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sat, 14 Feb 2026 23:24:23 -0800 Subject: [PATCH 11/24] feat: GPU work-stealing pool for downstream experiments with --all flag --- experiments_downstream/run_all_downstream.py | 142 ++++++++++++++----- run.sh | 38 +---- 2 files changed, 109 insertions(+), 71 deletions(-) diff --git a/experiments_downstream/run_all_downstream.py b/experiments_downstream/run_all_downstream.py index 59e42c6..fed681b 100644 --- a/experiments_downstream/run_all_downstream.py +++ b/experiments_downstream/run_all_downstream.py @@ -1,10 +1,13 @@ #!/usr/bin/env python3 -"""Launch downstream tasks in parallel across 8 GPUs.""" +"""Launch downstream tasks across GPUs with a work-stealing pool.""" from __future__ import annotations import os +import queue import subprocess +import threading +from concurrent.futures import ThreadPoolExecutor from dataclasses import dataclass from pathlib import Path from typing import TextIO @@ -27,6 +30,28 @@ class RunHandle: MODELS: dict[tuple[str, str], ModelSpec] = { + # --- baselines --- + ("codebert", "supcon"): ModelSpec( + "microsoft/codebert-base", + "microsoft/codebert-base", + "roberta", + ), + ("graphcodebert", "supcon"): ModelSpec( + "microsoft/graphcodebert-base", + "microsoft/graphcodebert-base", + "roberta", + ), + ("contrabert_c", "supcon"): ModelSpec( + "./saved_models/ContraBERT_C", + "microsoft/codebert-base", + "roberta", + ), + ("contrabert_g", "supcon"): ModelSpec( + "./saved_models/ContraBERT_G", + "microsoft/graphcodebert-base", + "roberta", + ), + # --- InvPT models --- ("inv-codebert", "supcon"): ModelSpec( "./saved_models/InvCodeBERT-supcon/final", "microsoft/codebert-base", @@ -144,7 +169,7 @@ def run_task( env = os.environ.copy() env["CUDA_VISIBLE_DEVICES"] = gpu_id - label = f"{task_dir}{'/' + subset if subset else ''}" + label = f"{model_key}/{task_dir}{'/' + subset if subset else ''}" if dry_run: print(f"[launch] GPU {gpu_id}: {label}") print(f" cwd: {task_path}") @@ -169,16 +194,19 @@ def run_task( @app.command() def main( + all_models: bool = typer.Option( + False, "--all", help="Run all models in the registry." + ), loss: str = typer.Option( - ..., "--loss", help="Training loss identifier (e.g., supcon)." + None, "--loss", help="Training loss identifier (e.g., supcon)." ), model: str = typer.Option( - ..., "--model", help="Pretrained model key (e.g., inv-codebert)." + None, "--model", help="Pretrained model key (e.g., inv-codebert)." ), gpus: str = typer.Option( "0,1,2,3,4,5,6,7", "--gpus", - help="Comma-separated GPU ids to use (must be 8).", + help="Comma-separated GPU ids to use.", ), results_root: str = typer.Option( "results", "--results-root", help="Base output directory for results." @@ -189,50 +217,96 @@ def main( ) -> None: root = Path(__file__).resolve().parents[1] - model_key = model.strip() - loss_key = loss.strip() - spec = resolve_model(model_key, loss_key) + # Resolve which models to run + if all_models: + if model is not None: + raise typer.BadParameter("Cannot use --model with --all") + entries = list(MODELS.items()) + if loss is not None: + loss_key = loss.strip() + entries = [((m, lk), s) for (m, lk), s in entries if lk == loss_key] + if not entries: + raise typer.BadParameter(f"No models found for loss={loss}") + else: + if model is None or loss is None: + raise typer.BadParameter( + "Either --all or both --model and --loss are required" + ) + model_key = model.strip() + loss_key = loss.strip() + spec = resolve_model(model_key, loss_key) + entries = [((model_key, loss_key), spec)] gpu_ids = [gpu.strip() for gpu in gpus.split(",") if gpu.strip()] - if len(gpu_ids) != len(TASKS): - raise typer.BadParameter( - f"Expected {len(TASKS)} GPU ids, got {len(gpu_ids)}: {gpu_ids}" - ) + if not gpu_ids: + raise typer.BadParameter("No GPU ids provided") - results_root_path = Path(results_root).resolve() + # Build all jobs: (model_key, spec, task_dir, subset) + jobs: list[tuple[str, ModelSpec, str, str | None]] = [] + for (mk, _lk), sp in entries: + for task_dir, subset in TASKS: + jobs.append((mk, sp, task_dir, subset)) - processes: list[RunHandle] = [] - for (task_dir, subset), gpu_id in zip(TASKS, gpu_ids, strict=True): - proc = run_task( - root, - model_key, - spec, - task_dir, - subset, - gpu_id, - results_root_path, - dry_run, - ) - if proc is not None: - processes.append(proc) + total = len(jobs) + results_root_path = Path(results_root).resolve() if dry_run: + for i, (mk, sp, task_dir, subset) in enumerate(jobs): + gpu_id = gpu_ids[i % len(gpu_ids)] + run_task(root, mk, sp, task_dir, subset, gpu_id, results_root_path, True) + print(f"\n[dry-run] {total} total jobs across {len(gpu_ids)} GPUs") raise typer.Exit(0) + # GPU work-stealing pool + gpu_pool: queue.Queue[str] = queue.Queue() + for gid in gpu_ids: + gpu_pool.put(gid) + + completed = 0 + lock = threading.Lock() failures: list[str] = [] - for handle in processes: - code = handle.process.wait() - handle.log_file.close() - if code != 0: - failures.append(f"{handle.label} (exit {code})") + + def run_job(mk: str, sp: ModelSpec, task_dir: str, subset: str | None) -> None: + nonlocal completed + gpu_id = gpu_pool.get() + label = f"{mk}/{task_dir}{'/' + subset if subset else ''}" + try: + with lock: + print(f"[start] GPU {gpu_id}: {label}") + handle = run_task( + root, mk, sp, task_dir, subset, gpu_id, results_root_path, False + ) + if handle is not None: + code = handle.process.wait() + handle.log_file.close() + with lock: + completed += 1 + if code != 0: + failures.append(f"{label} (exit {code})") + print( + f"[FAIL] GPU {gpu_id}: {label} " + f"(exit {code}) [{completed}/{total}]" + ) + else: + print(f"[done] GPU {gpu_id}: {label} [{completed}/{total}]") + finally: + gpu_pool.put(gpu_id) + + with ThreadPoolExecutor(max_workers=len(gpu_ids)) as executor: + futures = [ + executor.submit(run_job, mk, sp, task_dir, subset) + for mk, sp, task_dir, subset in jobs + ] + for f in futures: + f.result() if failures: - print("\n[error] Some tasks failed:") + print(f"\n[error] {len(failures)}/{total} tasks failed:") for failure in failures: print(f" - {failure}") raise typer.Exit(1) - print("\n[done] All downstream tasks completed successfully.") + print(f"\n[done] All {total} downstream tasks completed successfully.") if __name__ == "__main__": diff --git a/run.sh b/run.sh index 8beb414..d1c5ec5 100644 --- a/run.sh +++ b/run.sh @@ -1,40 +1,4 @@ #!/usr/bin/env bash set -euo pipefail -loss="supcon" -models=( - "inv-codebert" - "inv-graphcodebert" - "inv-contrabert_c" - "inv-contrabert_g" - "codebert" - "graphcodebert" - "contrabert_c" - "contrabert_g" - # "inv-modernbert" - # "modernbert" -) - -total_models=${#models[@]} -current=0 - -render_progress() { - local idx="$1" - local total="$2" - local width=30 - local filled=$((idx * width / total)) - local empty=$((width - filled)) - local bar - bar="$(printf '%*s' "${filled}" '' | tr ' ' '#')" - bar+="$(printf '%*s' "${empty}" '' | tr ' ' '-')" - printf "[%s] %d/%d" "${bar}" "${idx}" "${total}" -} - -for model in "${models[@]}"; do - current=$((current + 1)) - progress_line=$(render_progress "${current}" "${total_models}") - printf "%s %s\n" "${progress_line}" "${model}" - uv run experiments_downstream/run_all_downstream.py \ - --loss "${loss}" \ - --model "${model}" -done +uv run experiments_downstream/run_all_downstream.py --all --loss supcon From c2086c565f044310418a7ab24e28c4994fb01cc1 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sat, 14 Feb 2026 23:37:46 -0800 Subject: [PATCH 12/24] progress bar --- experiments_downstream/run_all_downstream.py | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/experiments_downstream/run_all_downstream.py b/experiments_downstream/run_all_downstream.py index fed681b..0e3e2c6 100644 --- a/experiments_downstream/run_all_downstream.py +++ b/experiments_downstream/run_all_downstream.py @@ -13,6 +13,7 @@ from typing import TextIO import typer +from tqdm import tqdm @dataclass(frozen=True) @@ -262,17 +263,20 @@ def main( for gid in gpu_ids: gpu_pool.put(gid) - completed = 0 + running = 0 + failed = 0 lock = threading.Lock() failures: list[str] = [] + pbar = tqdm(total=total, desc="Downstream", unit="task") def run_job(mk: str, sp: ModelSpec, task_dir: str, subset: str | None) -> None: - nonlocal completed + nonlocal running, failed gpu_id = gpu_pool.get() label = f"{mk}/{task_dir}{'/' + subset if subset else ''}" try: with lock: - print(f"[start] GPU {gpu_id}: {label}") + running += 1 + pbar.set_postfix(running=running, failed=failed, refresh=True) handle = run_task( root, mk, sp, task_dir, subset, gpu_id, results_root_path, False ) @@ -280,15 +284,15 @@ def run_job(mk: str, sp: ModelSpec, task_dir: str, subset: str | None) -> None: code = handle.process.wait() handle.log_file.close() with lock: - completed += 1 + running -= 1 if code != 0: + failed += 1 failures.append(f"{label} (exit {code})") - print( - f"[FAIL] GPU {gpu_id}: {label} " - f"(exit {code}) [{completed}/{total}]" - ) + tqdm.write(f"[FAIL] GPU {gpu_id}: {label} (exit {code})") else: - print(f"[done] GPU {gpu_id}: {label} [{completed}/{total}]") + tqdm.write(f"[done] GPU {gpu_id}: {label}") + pbar.set_postfix(running=running, failed=failed, refresh=False) + pbar.update(1) finally: gpu_pool.put(gpu_id) @@ -299,6 +303,7 @@ def run_job(mk: str, sp: ModelSpec, task_dir: str, subset: str | None) -> None: ] for f in futures: f.result() + pbar.close() if failures: print(f"\n[error] {len(failures)}/{total} tasks failed:") From 8e2abbc8f13f927a251e6bc11409023e57176c0c Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 05:11:45 +0800 Subject: [PATCH 13/24] add script to parse results --- AGENTS.md | 177 +---------------- CLAUDE.md | 1 - README.md | 8 + experiments_downstream/__init__.py | 0 experiments_downstream/parse_results.py | 254 ++++++++++++++++++++++++ tests/test_parse_results.py | 65 ++++++ 6 files changed, 331 insertions(+), 174 deletions(-) delete mode 120000 CLAUDE.md create mode 100644 experiments_downstream/__init__.py create mode 100644 experiments_downstream/parse_results.py create mode 100644 tests/test_parse_results.py diff --git a/AGENTS.md b/AGENTS.md index 3c3be48..bba8f44 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,175 +1,6 @@ -# AGENTS.md +# Claude Notes -## Project Overview +## Scripts -**InvPT** (Invariant Pre-training) is a research project for robust code representation learning. -It continues pre-training encoder-based code models (GraphCodeBERT, ContraBERT) using -semantic-preserving code transformations combined with contrastive learning and curriculum learning. -The goal is to improve both downstream task performance and robustness against syntactically -different but semantically equivalent programs (invariant programs). - -Paper: *Invariant Pre-training for Robust Code Representation Learning* (ICSE 2026) - -## Repository Structure - -``` -InvPT/ -├── modeling/ # Core training pipeline -│ ├── cli.py # Typer CLI entry point (run / pretrain subcommands) -│ ├── config.py # PretrainConfig dataclass, YAML config loading -│ ├── pretrain.py # Pre-training logic (main function) -│ ├── model.py # ContrastiveTrainer (MLM + InfoNCE loss) -│ ├── dataloader.py # Data collation, AugType enum, CodeSearchNetExample -│ └── common.py # Device setup, seed utilities -├── python_transform/ # Python AST-based code transformations -│ ├── transform.py # Transformation orchestrator -│ ├── augment_pretrain.py# Batch augmentation for pre-training data -│ ├── src/ # Individual transformers (NodeTransformer subclasses) -│ └── tests/ # Unit tests for transformations -├── java_transform/ # Java code transformations via SPAT -│ ├── transform.py # Transformation orchestrator -│ ├── augment_pretrain.py# Batch augmentation for pre-training data -│ ├── utils.py # SPAT JAR interface -│ └── SPAT-linux.jar # External Java transformation tool -├── cpp_transforms/ # C/C++ transformations via libclang -│ ├── transform.py # Transformation orchestrator -│ └── transformations/ # Individual transformation modules -├── data/ # Pre-training dataset scripts -│ └── get_code_search_net.py # Downloads CodeSearchNet from HuggingFace -├── downstream/ # Fine-tuning & evaluation (7 tasks from CodeXGLUE) -│ ├── Clone-detection-POJ-104/ -│ ├── Clone-detection-CodeNet/ -│ ├── Clone-detection-BigCloneBench/ -│ ├── Code-classification-POJ104/ -│ ├── Code-classification-CodeNet/ -│ ├── Defect-detection/ -│ └── Code-translation/ -├── plot/ # t-SNE visualization of embeddings -│ └── visualize.py -├── experiments/ # YAML experiment configurations -│ ├── base.yaml # Base supcon config (matches original run_pretrain.sh) -│ ├── grouped_example.yaml # Grouped contrastive mode example -│ └── modernbert_base.yaml # ModernBERT-base config (mean pooling) -├── saved_models/ # Pre-trained model checkpoints -├── run_pretrain.sh # Pre-training launch script -├── clang.sh # LLVM 14 installation script -├── pyproject.toml # Dependencies (managed by uv) -└── .envrc # Environment variables (direnv) -``` - -## Key Concepts - -- **Invariant programs**: Semantically equivalent code with different syntax (variable names, loop structures, branching). These occur naturally in real codebases. -- **Training loss**: `L = L_MLM(X) + L_MLM(X_inv) + alpha * L_InfoNCE(X, X_inv)` where alpha=0.7. -- **Curriculum learning**: Self-contrast (easy, same code with different MLM masks) and invariant-contrast (hard, transformed code) are trained simultaneously with low learning rate. -- **PL-only**: Unlike prior work (CodeBERT, ContraBERT), InvPT removes natural language docstrings during pre-training. -- **No MoCo**: Uses a single shared encoder for original and transformed code, unlike ContraBERT which uses momentum contrast. -- **Contrastive modes**: `info_nce` (diagonal positives), `supcon` (multi-positive by function_id mask), `grouped` (grouped multi-key contrast with explicit aug grouping via `--max_num_augs`). -- **Model types**: `roberta` (RoBERTa/CodeBERT/ContraBERT, default) and `modernbert` (ModernBERT with RoPE, Flash Attention, 8K context). Configured via `model_type` in YAML configs. -- **Pooling strategies**: `cls` (CLS token, default for RoBERTa) and `mean` (mean pooling over non-padding tokens, recommended for ModernBERT). - -## Transformation Operators - -| Operator | Python | Java | C/C++ | Description | -|----------|--------|------|-------|-------------| -| VarRe | yes | yes | yes | Rename local variables to random strings | -| F2W | no | yes | yes | Convert for-loop to while-loop | -| W2F | no | yes | yes | Convert while-loop to for-loop | -| PP2AA | no | yes | yes | Convert `x++` to `x += 1` | -| AA2EA | yes | yes | yes | Convert `x += 1` to `x = x + 1` | -| RevIf | yes | yes | yes | Negate condition, swap if/else branches | - -## Development Setup - -```sh -uv sync # Install Python dependencies -source .envrc # Load environment variables -./clang.sh # Install LLVM 14 (for C/C++ transforms) -``` - -Requires: Python 3.11+, JDK 11+ (for Java transforms), LLVM 14 (for C/C++ transforms), transformers >= 4.48 (for ModernBERT support). - -## Running Tests - -```sh -pytest python_transform/tests/ -``` - -## Pre-training Pipeline - -1. Download data: `cd data && python get_code_search_net.py` -2. Augment Python: `python python_transform/augment_pretrain.py -i data/raw_csn_py.jsonl -o data/aug_csn_py.jsonl` -3. Augment Java: `python java_transform/augment_pretrain.py -i data/raw_csn_java.jsonl -o data/aug_csn_java.jsonl` -4. Combine: `cat data/raw_csn.jsonl data/aug_csn_py.jsonl data/aug_csn_java.jsonl > data/csn.jsonl` -5. Train: `./run_pretrain.sh` or `python modeling/cli.py run experiments/base.yaml` - -Pre-training runs for 50k steps on 4 GPUs with batch size 256, learning rate 5e-5, and 5000 warmup steps. - -### Experiment Configuration - -The CLI (`modeling/cli.py`) has two subcommands: - -- **`run`** — load a YAML config from `experiments/` (no CLI overrides; edit the YAML to change parameters) -- **`pretrain`** — pass all parameters directly as CLI options (backward compatible) - -```sh -# From a YAML config (recommended) -python modeling/cli.py run experiments/base.yaml - -# Direct CLI options (backward compatible) -python modeling/cli.py pretrain --batch-size 64 --num-epochs 3 --model-name ./saved_models/ContraBERT_G - -# See available subcommands / options -python modeling/cli.py --help -python modeling/cli.py run --help -python modeling/cli.py pretrain --help -``` - -To create a new experiment, copy an existing YAML file in `experiments/` and modify the parameters. - -## Downstream Evaluation - -Each task in `downstream/` has a `run.sh` script: - -```sh -cd downstream/Clone-detection-POJ-104 -./run.sh -``` - -Pre-generated per-model evaluation scripts live in `experiments_downstream/`, including -ModernBERT variants. Regenerate them with `python3 experiments_downstream/gen_all.py`. - -Metrics: MAP@R for clone detection, accuracy for defect detection and code classification. - -## Code Conventions - -- Type annotations are used throughout; checked with mypy (strict mode, see `mypy.ini`). -- Functional error handling via `returns` library (`Maybe`, `Some`, `Nothing`). -- Parallel processing via `pathos` (serializable lambdas). -- CLI interfaces use `typer`. Pre-training uses YAML configs via `modeling/config.py`. -- Experiment tracking via Weights & Biases (`wandb`). - -## Development Guidelines - -### Developing - -- Before start working, refresh your knowledge from contents in `.agents` first. -- Always update `README.md` and `CLAUDE.md` when you introduce new features or libraries. -- Always write unit tests for integration testing and functional testing of new features. -- Always test your code after your implementation. -- Use `pre-commit install --install-hooks` (and optionally `--hook-type pre-push`) to enable local git hooks. -- You should not commit anything and create pull request, let human do them. However, please suggest commit messages after implementation. - -1. Use `.agents/sandbox/` for throwaway exploration that will not be committed. -2. Use `.agents/notes/` for longer-term notes that may be useful later. -Always write down your plans and reasoning for future reference when encountering major tasks, -like adding a feature. -3. Use `.agents/accomplished/` for recording completed tasks and the summary of what we did, -this may be useful for future reference. - - -## Common Tasks - -- **Add a new transformation operator**: Implement it in the relevant `*_transform/` directory. For Python, subclass `ast.NodeTransformer`; for Java, use a SPAT rule ID; for C/C++, use libclang AST traversal. Register it in the corresponding `TRANSFORMATION_MAP`. -- **Change the contrastive loss**: Modify `ContrastiveTrainer.compute_loss()` in `modeling/model.py`. Alternative loss functions (e.g., Barlow Twins) are already stubbed there. -- **Add a new downstream task**: Follow the CodeXGLUE structure in `downstream/`. Each task needs a `code/` directory with training scripts, a `dataset/` directory, and a `run.sh` entry point. +- `python experiments_downstream/parse_results.py --results-root results` + parses downstream evaluation logs into a table with regular vs augmented scores. diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 120000 index 47dc3e3..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1 +0,0 @@ -AGENTS.md \ No newline at end of file diff --git a/README.md b/README.md index ee6add7..91529d7 100755 --- a/README.md +++ b/README.md @@ -293,6 +293,14 @@ Generate t-SNE visualizations of code embeddings across models: uv run plot/visualize.py --input_test_file dataset/aug_test.jsonl --output_file clusters.png ``` +### Results Parsing + +Parse downstream evaluation outputs into a regular vs augmented table: + +```sh +python experiments_downstream/parse_results.py --results-root results --digits 2 +``` + ## Invariant Code Transformations InvPT uses six semantic-preserving transformation operators: diff --git a/experiments_downstream/__init__.py b/experiments_downstream/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/experiments_downstream/parse_results.py b/experiments_downstream/parse_results.py new file mode 100644 index 0000000..c7e3ee4 --- /dev/null +++ b/experiments_downstream/parse_results.py @@ -0,0 +1,254 @@ +#!/usr/bin/env python3 +"""Parse downstream evaluation logs into a summary table.""" + +from __future__ import annotations + +import argparse +import json +import re +from dataclasses import dataclass +from pathlib import Path +from typing import Iterable + + +@dataclass(frozen=True) +class ScorePair: + regular: float | None + augmented: float | None + + +@dataclass(frozen=True) +class ParsedResult: + model: str + dataset: str + task: str + metric: str + scores: ScorePair + + +CLONE_TASKS = { + "Clone-detection-POJ104", + "Clone-detection-CodeNet", +} +CLS_TASKS = { + "Code-classification-POJ104", + "Code-classification-CodeNet", +} + +MAP_PATTERN = re.compile(r"MAP@R\W*[:=]?\W*(\d*\.?\d+)") +TEST_ACC_PATTERN = re.compile(r"\btest_acc\b\s*=\s*(\d*\.?\d+)") +FLOAT64_PATTERN = re.compile(r"np\.float64\((\d*\.?\d+)\)") + + +def _read_text(path: Path) -> str: + try: + return path.read_text(encoding="utf-8", errors="ignore") + except FileNotFoundError: + return "" + + +def parse_clone_score(path: Path) -> float | None: + text = _read_text(path).strip() + if not text: + return None + match = MAP_PATTERN.search(text) + if match: + return float(match.group(1)) + match = FLOAT64_PATTERN.search(text) + if match: + return float(match.group(1)) + try: + data = json.loads(text.replace("'", '"')) + except json.JSONDecodeError: + return None + value = data.get("MAP@R") + if isinstance(value, (int, float)): + return float(value) + if isinstance(value, str): + try: + return float(value) + except ValueError: + return None + return None + + +def parse_classification_score(path: Path) -> float | None: + text = _read_text(path) + if not text: + return None + matches = TEST_ACC_PATTERN.findall(text) + if not matches: + return None + return float(matches[-1]) + + +def iter_result_dirs(results_root: Path) -> Iterable[tuple[str, Path]]: + if not results_root.exists(): + return iter(()) + for model_dir in sorted(results_root.iterdir()): + if not model_dir.is_dir(): + continue + yield model_dir.name, model_dir + + +def infer_task(task_dir: Path) -> str | None: + name = task_dir.name + if name in CLONE_TASKS or name in CLS_TASKS: + return name + return None + + +def dataset_label(task: str, subset: str | None) -> str: + if subset: + return f"{task}/{subset}" + return task + + +def collect_results(results_root: Path) -> list[ParsedResult]: + results: list[ParsedResult] = [] + for model_name, model_dir in iter_result_dirs(results_root): + for task_dir in sorted(model_dir.iterdir()): + if not task_dir.is_dir(): + continue + task = infer_task(task_dir) + if task is None: + continue + if task in CLONE_TASKS: + collect_clone_results(results, model_name, task_dir, task) + elif task in CLS_TASKS: + collect_classification_results(results, model_name, task_dir, task) + return results + + +def collect_clone_results( + results: list[ParsedResult], + model: str, + task_dir: Path, + task: str, +) -> None: + task_paths = list(task_dir.iterdir()) + if any(p.is_dir() for p in task_paths): + for subset_dir in sorted(p for p in task_paths if p.is_dir()): + regular = parse_clone_score(subset_dir / "test.log") + augmented = parse_clone_score(subset_dir / "aug_test.log") + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, subset_dir.name), + task=task, + metric="MAP@R", + scores=ScorePair(regular, augmented), + ) + ) + else: + regular = parse_clone_score(task_dir / "test.log") + augmented = parse_clone_score(task_dir / "aug_test.log") + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, None), + task=task, + metric="MAP@R", + scores=ScorePair(regular, augmented), + ) + ) + + +def collect_classification_results( + results: list[ParsedResult], + model: str, + task_dir: Path, + task: str, +) -> None: + task_paths = list(task_dir.iterdir()) + if any(p.is_dir() for p in task_paths): + for subset_dir in sorted(p for p in task_paths if p.is_dir()): + regular = parse_classification_score(subset_dir / "test_train.log") + augmented = parse_classification_score(subset_dir / "aug_test.log") + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, subset_dir.name), + task=task, + metric="Accuracy", + scores=ScorePair(regular, augmented), + ) + ) + else: + regular = parse_classification_score(task_dir / "test_train.log") + augmented = parse_classification_score(task_dir / "aug_test.log") + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, None), + task=task, + metric="Accuracy", + scores=ScorePair(regular, augmented), + ) + ) + + +def format_score(value: float | None, digits: int) -> str: + if value is None: + return "-" + return f"{value * 100:.{digits}f}%" + + +def render_table(results: list[ParsedResult], digits: int) -> str: + headers = ["Model", "Dataset", "Metric", "Regular (%)", "Augmented (%)"] + rows = [] + for result in results: + rows.append( + [ + result.model, + result.dataset, + result.metric, + format_score(result.scores.regular, digits), + format_score(result.scores.augmented, digits), + ] + ) + + widths = [len(h) for h in headers] + for row in rows: + for idx, value in enumerate(row): + widths[idx] = max(widths[idx], len(value)) + + header_line = " ".join(h.ljust(widths[idx]) for idx, h in enumerate(headers)) + divider = " ".join("-" * widths[idx] for idx in range(len(headers))) + body = [ + " ".join(row[idx].ljust(widths[idx]) for idx in range(len(headers))) + for row in rows + ] + return "\n".join([header_line, divider, *body]) + + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser( + description="Parse downstream results into a table." + ) + parser.add_argument( + "--results-root", + default="results", + help="Root directory containing result folders.", + ) + parser.add_argument( + "--digits", + type=int, + default=2, + help="Decimal places for percentage scores.", + ) + return parser.parse_args() + + +def main() -> None: + args = parse_args() + results_root = Path(args.results_root).resolve() + results = collect_results(results_root) + if not results: + print(f"No results found under {results_root}") + return + print(render_table(results, args.digits)) + + +if __name__ == "__main__": + main() diff --git a/tests/test_parse_results.py b/tests/test_parse_results.py new file mode 100644 index 0000000..67aa07c --- /dev/null +++ b/tests/test_parse_results.py @@ -0,0 +1,65 @@ +from __future__ import annotations + +from pathlib import Path + +from experiments_downstream.parse_results import collect_results, render_table + + +def _write(path: Path, content: str) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content) + + +def test_collect_results_clone_and_classification(tmp_path: Path) -> None: + results_root = tmp_path / "results" + + _write( + results_root / "inv-codebert" / "Clone-detection-POJ104" / "test.log", + "{'MAP@R': np.float64(0.5621)}\n", + ) + _write( + results_root / "inv-codebert" / "Clone-detection-POJ104" / "aug_test.log", + "{'MAP@R': np.float64(0.4321)}\n", + ) + + test_train_log = """ + 02/16/2026 00:00:00 - INFO - __main__ - ***** Test results ***** + 02/16/2026 00:00:00 - INFO - __main__ - test_acc = 0.3992 + """ + _write( + results_root + / "inv-codebert" + / "Code-classification-CodeNet" + / "Java250" + / "test_train.log", + test_train_log, + ) + _write( + results_root + / "inv-codebert" + / "Code-classification-CodeNet" + / "Java250" + / "aug_test.log", + test_train_log.replace("0.3992", "0.2777"), + ) + + results = collect_results(results_root) + assert len(results) == 2 + clone = next(r for r in results if r.task == "Clone-detection-POJ104") + cls = next(r for r in results if r.task == "Code-classification-CodeNet") + + assert clone.scores.regular == 0.5621 + assert clone.scores.augmented == 0.4321 + assert cls.scores.regular == 0.3992 + assert cls.scores.augmented == 0.2777 + + +def test_render_table_placeholder_for_missing(tmp_path: Path) -> None: + results_root = tmp_path / "results" + _write( + results_root / "inv-codebert" / "Clone-detection-POJ104" / "test.log", + "{'MAP@R': np.float64(0.5621)}\n", + ) + + table = render_table(collect_results(results_root), 4) + assert "-" in table From 5918b0d2d43f61323146b655034ebc28b3556614 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 05:24:54 +0800 Subject: [PATCH 14/24] parser directory discovey --- experiments_downstream/parse_results.py | 91 +++++++++++++++++-------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/experiments_downstream/parse_results.py b/experiments_downstream/parse_results.py index c7e3ee4..436849a 100644 --- a/experiments_downstream/parse_results.py +++ b/experiments_downstream/parse_results.py @@ -126,9 +126,27 @@ def collect_clone_results( task_dir: Path, task: str, ) -> None: - task_paths = list(task_dir.iterdir()) - if any(p.is_dir() for p in task_paths): - for subset_dir in sorted(p for p in task_paths if p.is_dir()): + regular = parse_clone_score(task_dir / "test.log") + augmented = parse_clone_score(task_dir / "aug_test.log") + if regular is not None or augmented is not None: + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, None), + task=task, + metric="MAP@R", + scores=ScorePair(regular, augmented), + ) + ) + return + subset_dirs = [ + path + for path in task_dir.iterdir() + if path.is_dir() + and any((path / log_name).exists() for log_name in ("test.log", "aug_test.log")) + ] + if subset_dirs: + for subset_dir in sorted(subset_dirs): regular = parse_clone_score(subset_dir / "test.log") augmented = parse_clone_score(subset_dir / "aug_test.log") results.append( @@ -140,18 +158,16 @@ def collect_clone_results( scores=ScorePair(regular, augmented), ) ) - else: - regular = parse_clone_score(task_dir / "test.log") - augmented = parse_clone_score(task_dir / "aug_test.log") - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, None), - task=task, - metric="MAP@R", - scores=ScorePair(regular, augmented), - ) + return + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, None), + task=task, + metric="MAP@R", + scores=ScorePair(regular, augmented), ) + ) def collect_classification_results( @@ -160,9 +176,30 @@ def collect_classification_results( task_dir: Path, task: str, ) -> None: - task_paths = list(task_dir.iterdir()) - if any(p.is_dir() for p in task_paths): - for subset_dir in sorted(p for p in task_paths if p.is_dir()): + regular = parse_classification_score(task_dir / "test_train.log") + augmented = parse_classification_score(task_dir / "aug_test.log") + if regular is not None or augmented is not None: + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, None), + task=task, + metric="Accuracy", + scores=ScorePair(regular, augmented), + ) + ) + return + subset_dirs = [ + path + for path in task_dir.iterdir() + if path.is_dir() + and any( + (path / log_name).exists() + for log_name in ("test_train.log", "aug_test.log") + ) + ] + if subset_dirs: + for subset_dir in sorted(subset_dirs): regular = parse_classification_score(subset_dir / "test_train.log") augmented = parse_classification_score(subset_dir / "aug_test.log") results.append( @@ -174,18 +211,16 @@ def collect_classification_results( scores=ScorePair(regular, augmented), ) ) - else: - regular = parse_classification_score(task_dir / "test_train.log") - augmented = parse_classification_score(task_dir / "aug_test.log") - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, None), - task=task, - metric="Accuracy", - scores=ScorePair(regular, augmented), - ) + return + results.append( + ParsedResult( + model=model, + dataset=dataset_label(task, None), + task=task, + metric="Accuracy", + scores=ScorePair(regular, augmented), ) + ) def format_score(value: float | None, digits: int) -> str: From 325166988f15e49c139588a3a9780be139f03871 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 13:37:31 -0800 Subject: [PATCH 15/24] result display in markdown --- experiments_downstream/parse_results.py | 308 +++++++++--------------- 1 file changed, 111 insertions(+), 197 deletions(-) diff --git a/experiments_downstream/parse_results.py b/experiments_downstream/parse_results.py index 436849a..9673698 100644 --- a/experiments_downstream/parse_results.py +++ b/experiments_downstream/parse_results.py @@ -1,39 +1,18 @@ #!/usr/bin/env python3 -"""Parse downstream evaluation logs into a summary table.""" +"""Parse downstream evaluation logs into pivot-style Markdown tables.""" from __future__ import annotations import argparse import json import re -from dataclasses import dataclass from pathlib import Path -from typing import Iterable +import pandas as pd -@dataclass(frozen=True) -class ScorePair: - regular: float | None - augmented: float | None - - -@dataclass(frozen=True) -class ParsedResult: - model: str - dataset: str - task: str - metric: str - scores: ScorePair - - -CLONE_TASKS = { - "Clone-detection-POJ104", - "Clone-detection-CodeNet", -} -CLS_TASKS = { - "Code-classification-POJ104", - "Code-classification-CodeNet", -} +# --------------------------------------------------------------------------- +# Score parsing helpers +# --------------------------------------------------------------------------- MAP_PATTERN = re.compile(r"MAP@R\W*[:=]?\W*(\d*\.?\d+)") TEST_ACC_PATTERN = re.compile(r"\btest_acc\b\s*=\s*(\d*\.?\d+)") @@ -82,189 +61,110 @@ def parse_classification_score(path: Path) -> float | None: return float(matches[-1]) -def iter_result_dirs(results_root: Path) -> Iterable[tuple[str, Path]]: - if not results_root.exists(): - return iter(()) - for model_dir in sorted(results_root.iterdir()): - if not model_dir.is_dir(): - continue - yield model_dir.name, model_dir - - -def infer_task(task_dir: Path) -> str | None: - name = task_dir.name - if name in CLONE_TASKS or name in CLS_TASKS: - return name - return None +# --------------------------------------------------------------------------- +# Column definitions +# --------------------------------------------------------------------------- +# Ordered subsets that become column pairs (, aug). +SUBSETS = ["Java250", "Python800", "C++1400", "POJ104"] -def dataset_label(task: str, subset: str | None) -> str: - if subset: - return f"{task}/{subset}" - return task - - -def collect_results(results_root: Path) -> list[ParsedResult]: - results: list[ParsedResult] = [] - for model_name, model_dir in iter_result_dirs(results_root): - for task_dir in sorted(model_dir.iterdir()): - if not task_dir.is_dir(): - continue - task = infer_task(task_dir) - if task is None: - continue - if task in CLONE_TASKS: - collect_clone_results(results, model_name, task_dir, task) - elif task in CLS_TASKS: - collect_classification_results(results, model_name, task_dir, task) - return results - - -def collect_clone_results( - results: list[ParsedResult], - model: str, - task_dir: Path, - task: str, -) -> None: - regular = parse_clone_score(task_dir / "test.log") - augmented = parse_clone_score(task_dir / "aug_test.log") - if regular is not None or augmented is not None: - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, None), - task=task, - metric="MAP@R", - scores=ScorePair(regular, augmented), - ) - ) - return - subset_dirs = [ - path - for path in task_dir.iterdir() - if path.is_dir() - and any((path / log_name).exists() for log_name in ("test.log", "aug_test.log")) - ] - if subset_dirs: - for subset_dir in sorted(subset_dirs): - regular = parse_clone_score(subset_dir / "test.log") - augmented = parse_clone_score(subset_dir / "aug_test.log") - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, subset_dir.name), - task=task, - metric="MAP@R", - scores=ScorePair(regular, augmented), - ) - ) - return - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, None), - task=task, - metric="MAP@R", - scores=ScorePair(regular, augmented), - ) - ) +# Map from task category to (codenet_task_dir_name, poj104_task_dir_name). +CLONE_CODENET = "Clone-detection-CodeNet" +CLONE_POJ104 = "Clone-detection-POJ104" +CLS_CODENET = "Code-classification-CodeNet" +CLS_POJ104 = "Code-classification-POJ104" -def collect_classification_results( - results: list[ParsedResult], - model: str, - task_dir: Path, - task: str, -) -> None: - regular = parse_classification_score(task_dir / "test_train.log") - augmented = parse_classification_score(task_dir / "aug_test.log") - if regular is not None or augmented is not None: - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, None), - task=task, - metric="Accuracy", - scores=ScorePair(regular, augmented), - ) - ) - return - subset_dirs = [ - path - for path in task_dir.iterdir() - if path.is_dir() - and any( - (path / log_name).exists() - for log_name in ("test_train.log", "aug_test.log") - ) - ] - if subset_dirs: - for subset_dir in sorted(subset_dirs): - regular = parse_classification_score(subset_dir / "test_train.log") - augmented = parse_classification_score(subset_dir / "aug_test.log") - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, subset_dir.name), - task=task, - metric="Accuracy", - scores=ScorePair(regular, augmented), - ) - ) - return - results.append( - ParsedResult( - model=model, - dataset=dataset_label(task, None), - task=task, - metric="Accuracy", - scores=ScorePair(regular, augmented), - ) - ) +# --------------------------------------------------------------------------- +# Result collection +# --------------------------------------------------------------------------- -def format_score(value: float | None, digits: int) -> str: +def _fmt(value: float | None, digits: int) -> str: if value is None: return "-" - return f"{value * 100:.{digits}f}%" - - -def render_table(results: list[ParsedResult], digits: int) -> str: - headers = ["Model", "Dataset", "Metric", "Regular (%)", "Augmented (%)"] - rows = [] - for result in results: - rows.append( - [ - result.model, - result.dataset, - result.metric, - format_score(result.scores.regular, digits), - format_score(result.scores.augmented, digits), - ] - ) - - widths = [len(h) for h in headers] - for row in rows: - for idx, value in enumerate(row): - widths[idx] = max(widths[idx], len(value)) - - header_line = " ".join(h.ljust(widths[idx]) for idx, h in enumerate(headers)) - divider = " ".join("-" * widths[idx] for idx in range(len(headers))) - body = [ - " ".join(row[idx].ljust(widths[idx]) for idx in range(len(headers))) - for row in rows - ] - return "\n".join([header_line, divider, *body]) + return f"{value * 100:.{digits}f}" + + +def _collect_clone_row(model_dir: Path, digits: int) -> dict[str, str]: + row: dict[str, str] = {} + # CodeNet subsets + codenet_dir = model_dir / CLONE_CODENET + for subset in ("Java250", "Python800", "C++1400"): + subset_dir = codenet_dir / subset + reg = parse_clone_score(subset_dir / "test.log") + aug = parse_clone_score(subset_dir / "aug_test.log") + row[subset] = _fmt(reg, digits) + row[f"{subset} aug"] = _fmt(aug, digits) + # POJ104 (logs directly in the task dir) + poj_dir = model_dir / CLONE_POJ104 + reg = parse_clone_score(poj_dir / "test.log") + aug = parse_clone_score(poj_dir / "aug_test.log") + row["POJ104"] = _fmt(reg, digits) + row["POJ104 aug"] = _fmt(aug, digits) + return row + + +def _collect_cls_row(model_dir: Path, digits: int) -> dict[str, str]: + row: dict[str, str] = {} + # CodeNet subsets + codenet_dir = model_dir / CLS_CODENET + for subset in ("Java250", "Python800", "C++1400"): + subset_dir = codenet_dir / subset + reg = parse_classification_score(subset_dir / "test_train.log") + aug = parse_classification_score(subset_dir / "aug_test.log") + row[subset] = _fmt(reg, digits) + row[f"{subset} aug"] = _fmt(aug, digits) + # POJ104 + poj_dir = model_dir / CLS_POJ104 + reg = parse_classification_score(poj_dir / "test_train.log") + aug = parse_classification_score(poj_dir / "aug_test.log") + row["POJ104"] = _fmt(reg, digits) + row["POJ104 aug"] = _fmt(aug, digits) + return row + + +def build_table( + results_root: Path, + collector, + digits: int, +) -> pd.DataFrame: + columns = [] + for s in SUBSETS: + columns.extend([s, f"{s} aug"]) + + rows: list[dict[str, str]] = [] + if not results_root.exists(): + return pd.DataFrame(columns=["Model"] + columns) + + for model_dir in sorted(results_root.iterdir()): + if not model_dir.is_dir(): + continue + row = collector(model_dir, digits) + row["Model"] = model_dir.name + rows.append(row) + + if not rows: + return pd.DataFrame(columns=["Model"] + columns) + + df = pd.DataFrame(rows) + df = df[["Model"] + columns] + return df + + +# --------------------------------------------------------------------------- +# CLI +# --------------------------------------------------------------------------- def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser( - description="Parse downstream results into a table." + description="Parse downstream results into pivot Markdown tables." ) parser.add_argument( "--results-root", default="results", - help="Root directory containing result folders.", + help="Root directory containing model result folders.", ) parser.add_argument( "--digits", @@ -278,11 +178,25 @@ def parse_args() -> argparse.Namespace: def main() -> None: args = parse_args() results_root = Path(args.results_root).resolve() - results = collect_results(results_root) - if not results: + + clone_df = build_table(results_root, _collect_clone_row, args.digits) + cls_df = build_table(results_root, _collect_cls_row, args.digits) + + found = False + if not clone_df.empty: + found = True + print("# Clone Detection (MAP@R)\n") + print(clone_df.to_markdown(index=False)) + print() + + if not cls_df.empty: + found = True + print("# Code Classification (Acc)\n") + print(cls_df.to_markdown(index=False)) + print() + + if not found: print(f"No results found under {results_root}") - return - print(render_table(results, args.digits)) if __name__ == "__main__": From 8b890ed8f40c7883433e41ade9b106bc70713736 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 05:38:26 +0800 Subject: [PATCH 16/24] tabulate --- pyproject.toml | 1 + uv.lock | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 0d67fbf..959a939 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dependencies = [ "pyyaml>=6.0", "returns[compatible-mypy]>=0.23.0", "scikit-learn==1.6.0", + "tabulate>=0.9.0", "tensorboardx==2.6.2.2", "tokenizers>=0.20", "torch>=2.6", diff --git a/uv.lock b/uv.lock index 1ea8840..fbd8b66 100644 --- a/uv.lock +++ b/uv.lock @@ -645,6 +645,7 @@ dependencies = [ { name = "pyyaml" }, { name = "returns", extra = ["compatible-mypy"] }, { name = "scikit-learn" }, + { name = "tabulate" }, { name = "tensorboardx" }, { name = "tokenizers" }, { name = "torch" }, @@ -686,6 +687,7 @@ requires-dist = [ { name = "pyyaml", specifier = ">=6.0" }, { name = "returns", extras = ["compatible-mypy"], specifier = ">=0.23.0" }, { name = "scikit-learn", specifier = "==1.6.0" }, + { name = "tabulate", specifier = ">=0.9.0" }, { name = "tensorboardx", specifier = "==2.6.2.2" }, { name = "tokenizers", specifier = ">=0.20" }, { name = "torch", specifier = ">=2.6" }, @@ -2038,6 +2040,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/99/ff/c87e0622b1dadea79d2fb0b25ade9ed98954c9033722eb707053d310d4f3/sympy-1.13.3-py3-none-any.whl", hash = "sha256:54612cf55a62755ee71824ce692986f23c88ffa77207b30c1368eda4a7060f73", size = 6189483 }, ] +[[package]] +name = "tabulate" +version = "0.9.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ec/fe/802052aecb21e3797b8f7902564ab6ea0d60ff8ca23952079064155d1ae1/tabulate-0.9.0.tar.gz", hash = "sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c", size = 81090 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/40/44/4a5f08c96eb108af5cb50b41f76142f0afa346dfa99d5296fe7202a11854/tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f", size = 35252 }, +] + [[package]] name = "tensorboardx" version = "2.6.2.2" From 0204fdb73a2b379de53ccd7d6d361aa8c92c9b12 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 06:35:51 +0800 Subject: [PATCH 17/24] downstream modernbert config --- .../Code-classification-POJ104/code/run.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/downstream/Code-classification-POJ104/code/run.py b/downstream/Code-classification-POJ104/code/run.py index d612d28..deb6e6a 100644 --- a/downstream/Code-classification-POJ104/code/run.py +++ b/downstream/Code-classification-POJ104/code/run.py @@ -53,6 +53,22 @@ "modernbert": (AutoConfig, AutoModelForSequenceClassification, AutoTokenizer), } + +def resolve_model_type(model_type, model_name_or_path): + if model_type in MODEL_CLASSES: + return model_type + candidate = model_name_or_path or model_type or "" + name = candidate.lower() + resolved = "modernbert" if "modernbert" in name else "roberta" + logger.warning( + "Unknown model_type '%s'; inferring '%s' from '%s'.", + model_type, + resolved, + candidate, + ) + return resolved + + logger = logging.getLogger(__name__) @@ -82,7 +98,8 @@ def convert_examples_to_features(js, tokenizer, args): class TextDataset(Dataset): - def __init__(self, tokenizer, args, file_path=None): + def __init__(self, tokenizer, args, file_path: str): + file_path = cast(str, file_path) self.examples = [] with open(file_path) as f: for line in f: @@ -429,6 +446,7 @@ def main(): # Set seed set_seed(args.seed) + args.model_type = resolve_model_type(args.model_type, args.model_name_or_path) config_class, model_class, tokenizer_class = MODEL_CLASSES[args.model_type] config = config_class.from_pretrained(args.model_name_or_path) config.num_labels = 104 From 7ac7cd93424e5afc422f447d57a8752f21c084f8 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 06:55:48 +0800 Subject: [PATCH 18/24] fix cast error --- downstream/Code-classification-POJ104/code/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/downstream/Code-classification-POJ104/code/run.py b/downstream/Code-classification-POJ104/code/run.py index deb6e6a..4e48a63 100644 --- a/downstream/Code-classification-POJ104/code/run.py +++ b/downstream/Code-classification-POJ104/code/run.py @@ -99,7 +99,7 @@ def convert_examples_to_features(js, tokenizer, args): class TextDataset(Dataset): def __init__(self, tokenizer, args, file_path: str): - file_path = cast(str, file_path) + file_path = str(file_path) self.examples = [] with open(file_path) as f: for line in f: From 27aadb16da2557c6553b46802fd643bf29ce2e6d Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 07:02:58 +0800 Subject: [PATCH 19/24] allow multiple models --- experiments_downstream/run_all_downstream.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/experiments_downstream/run_all_downstream.py b/experiments_downstream/run_all_downstream.py index 0e3e2c6..aa0694e 100644 --- a/experiments_downstream/run_all_downstream.py +++ b/experiments_downstream/run_all_downstream.py @@ -202,7 +202,9 @@ def main( None, "--loss", help="Training loss identifier (e.g., supcon)." ), model: str = typer.Option( - None, "--model", help="Pretrained model key (e.g., inv-codebert)." + None, + "--model", + help="Pretrained model key(s), comma-separated (e.g., inv-codebert,inv-graphcodebert).", ), gpus: str = typer.Option( "0,1,2,3,4,5,6,7", @@ -233,10 +235,14 @@ def main( raise typer.BadParameter( "Either --all or both --model and --loss are required" ) - model_key = model.strip() loss_key = loss.strip() - spec = resolve_model(model_key, loss_key) - entries = [((model_key, loss_key), spec)] + model_keys = [m.strip() for m in model.split(",") if m.strip()] + if not model_keys: + raise typer.BadParameter("No model keys provided") + entries = [] + for model_key in model_keys: + spec = resolve_model(model_key, loss_key) + entries.append(((model_key, loss_key), spec)) gpu_ids = [gpu.strip() for gpu in gpus.split(",") if gpu.strip()] if not gpu_ids: From 27594d0f75b2de5724b0b2e17a7a1697b2d31e27 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 11:27:00 +0800 Subject: [PATCH 20/24] fix: checkoutpoint key mismatch --- downstream/Clone-detection-BigCloneBench/code/run.py | 6 ++++-- downstream/Clone-detection-CodeNet/code/run.py | 6 ++++-- downstream/Clone-detection-CodeNet/run.sh | 2 +- downstream/Clone-detection-POJ104/code/run.py | 6 ++++-- downstream/Code-classification-CodeNet/code/run.py | 6 ++++-- downstream/Code-classification-CodeNet/run.sh | 2 +- downstream/Code-classification-POJ104/code/run.py | 6 ++++-- downstream/Code-classification-POJ104/run.sh | 2 +- downstream/Defect-detection/code/run.py | 6 ++++-- 9 files changed, 27 insertions(+), 15 deletions(-) diff --git a/downstream/Clone-detection-BigCloneBench/code/run.py b/downstream/Clone-detection-BigCloneBench/code/run.py index c964ec6..6ad838a 100644 --- a/downstream/Clone-detection-BigCloneBench/code/run.py +++ b/downstream/Clone-detection-BigCloneBench/code/run.py @@ -882,14 +882,16 @@ def main(): if args.do_eval and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-f1/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) result = evaluate(args, model, tokenizer, pool=pool) if args.do_test and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-f1/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) test(args, model, tokenizer, pool=pool, best_threshold=0.5) diff --git a/downstream/Clone-detection-CodeNet/code/run.py b/downstream/Clone-detection-CodeNet/code/run.py index 84109e2..6480efc 100644 --- a/downstream/Clone-detection-CodeNet/code/run.py +++ b/downstream/Clone-detection-CodeNet/code/run.py @@ -873,7 +873,8 @@ def main(): if args.do_eval and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-map/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir), strict=False) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir), strict=False) model.to(args.device) result = evaluate(args, model, tokenizer) logger.info("***** Eval results *****") @@ -883,7 +884,8 @@ def main(): if args.do_test and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-map/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir), strict=False) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir), strict=False) model.to(args.device) test(args, model, tokenizer) diff --git a/downstream/Clone-detection-CodeNet/run.sh b/downstream/Clone-detection-CodeNet/run.sh index 198d298..42e256c 100755 --- a/downstream/Clone-detection-CodeNet/run.sh +++ b/downstream/Clone-detection-CodeNet/run.sh @@ -45,4 +45,4 @@ python evaluator/evaluator.py \ echo "Running evaluation for augmented test set..." -./run_aug_test.sh $model_path $save_path $subset $model_type $tokenizer_name +./run_aug_test.sh "$model_path" "$save_path" "$subset" "$model_type" "$tokenizer_name" diff --git a/downstream/Clone-detection-POJ104/code/run.py b/downstream/Clone-detection-POJ104/code/run.py index 84109e2..6480efc 100644 --- a/downstream/Clone-detection-POJ104/code/run.py +++ b/downstream/Clone-detection-POJ104/code/run.py @@ -873,7 +873,8 @@ def main(): if args.do_eval and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-map/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir), strict=False) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir), strict=False) model.to(args.device) result = evaluate(args, model, tokenizer) logger.info("***** Eval results *****") @@ -883,7 +884,8 @@ def main(): if args.do_test and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-map/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir), strict=False) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir), strict=False) model.to(args.device) test(args, model, tokenizer) diff --git a/downstream/Code-classification-CodeNet/code/run.py b/downstream/Code-classification-CodeNet/code/run.py index d612d28..f187b44 100644 --- a/downstream/Code-classification-CodeNet/code/run.py +++ b/downstream/Code-classification-CodeNet/code/run.py @@ -456,7 +456,8 @@ def main(): if args.do_eval: checkpoint_prefix = "checkpoint-best-acc/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) result = evaluate(args, model, tokenizer) logger.info("***** Eval results *****") @@ -466,7 +467,8 @@ def main(): if args.do_test: checkpoint_prefix = "checkpoint-best-acc/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) result = test(args, model, tokenizer) logger.info("***** Test results *****") diff --git a/downstream/Code-classification-CodeNet/run.sh b/downstream/Code-classification-CodeNet/run.sh index dd3c68d..b8c475b 100755 --- a/downstream/Code-classification-CodeNet/run.sh +++ b/downstream/Code-classification-CodeNet/run.sh @@ -36,4 +36,4 @@ python ./code/run.py \ echo "Running evaluation for augmented test set..." -./run_aug_test.sh $model_path $save_path $subset $model_type $tokenizer_name +./run_aug_test.sh "$model_path" "$save_path" "$subset" "$model_type" "$tokenizer_name" diff --git a/downstream/Code-classification-POJ104/code/run.py b/downstream/Code-classification-POJ104/code/run.py index 4e48a63..c8c6cb0 100644 --- a/downstream/Code-classification-POJ104/code/run.py +++ b/downstream/Code-classification-POJ104/code/run.py @@ -474,7 +474,8 @@ def main(): if args.do_eval: checkpoint_prefix = "checkpoint-best-acc/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) result = evaluate(args, model, tokenizer) logger.info("***** Eval results *****") @@ -484,7 +485,8 @@ def main(): if args.do_test: checkpoint_prefix = "checkpoint-best-acc/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) result = test(args, model, tokenizer) logger.info("***** Test results *****") diff --git a/downstream/Code-classification-POJ104/run.sh b/downstream/Code-classification-POJ104/run.sh index 292cf66..ad102d5 100755 --- a/downstream/Code-classification-POJ104/run.sh +++ b/downstream/Code-classification-POJ104/run.sh @@ -40,4 +40,4 @@ python ./code/run.py \ --seed 123456 2>&1 | tee $output_dir/test_train.log echo "Running evaluation for augmented test set..." -./run_aug_test.sh $model_path $save_path $subset $model_type $tokenizer_name +./run_aug_test.sh "$model_path" "$save_path" "$subset" "$model_type" "$tokenizer_name" diff --git a/downstream/Defect-detection/code/run.py b/downstream/Defect-detection/code/run.py index fa104d1..a065f54 100644 --- a/downstream/Defect-detection/code/run.py +++ b/downstream/Defect-detection/code/run.py @@ -819,7 +819,8 @@ def main(): if args.do_eval and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-acc/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) result = evaluate(args, model, tokenizer) logger.info("***** Eval results *****") @@ -829,7 +830,8 @@ def main(): if args.do_test and args.local_rank in [-1, 0]: checkpoint_prefix = "checkpoint-best-acc/model.bin" output_dir = os.path.join(args.output_dir, "{}".format(checkpoint_prefix)) - model.load_state_dict(torch.load(output_dir)) + model_to_load = model.module if hasattr(model, "module") else model + model_to_load.load_state_dict(torch.load(output_dir)) model.to(args.device) test(args, model, tokenizer) From fe5362af5eb8474952e522cde9f3514c52fb20e7 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 12:27:56 +0800 Subject: [PATCH 21/24] fix scripts --- ...Cpp_codebert.sh => cls-poj104_codebert.sh} | 4 +- ...rabert_c.sh => cls-poj104_contrabert_c.sh} | 4 +- ...rabert_g.sh => cls-poj104_contrabert_g.sh} | 4 +- ...odebert.sh => cls-poj104_graphcodebert.sh} | 4 +- ...codebert.sh => cls-poj104_inv-codebert.sh} | 4 +- ...rt_c.sh => cls-poj104_inv-contrabert_c.sh} | 4 +- ...rt_g.sh => cls-poj104_inv-contrabert_g.sh} | 4 +- ...ert.sh => cls-poj104_inv-graphcodebert.sh} | 4 +- ...rnbert.sh => cls-poj104_inv-modernbert.sh} | 4 +- experiments_downstream/gen_all.py | 6 +- experiments_downstream/run_task.py | 204 ++++++++++++++++++ 11 files changed, 225 insertions(+), 21 deletions(-) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_codebert.sh => cls-poj104_codebert.sh} (73%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_contrabert_c.sh => cls-poj104_contrabert_c.sh} (69%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_contrabert_g.sh => cls-poj104_contrabert_g.sh} (69%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_graphcodebert.sh => cls-poj104_graphcodebert.sh} (70%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_inv-codebert.sh => cls-poj104_inv-codebert.sh} (69%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_inv-contrabert_c.sh => cls-poj104_inv-contrabert_c.sh} (66%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_inv-contrabert_g.sh => cls-poj104_inv-contrabert_g.sh} (66%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_inv-graphcodebert.sh => cls-poj104_inv-graphcodebert.sh} (66%) rename experiments_downstream/Code-classification-POJ104/{cls-poj104_Cpp_inv-modernbert.sh => cls-poj104_inv-modernbert.sh} (77%) create mode 100755 experiments_downstream/run_task.py diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_codebert.sh similarity index 73% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_codebert.sh index 182cc41..ff8ced4 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_codebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_codebert.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with codebert +# Downstream evaluation: Code-classification-POJ104 with codebert set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-classification-POJ104" Cpp roberta microsoft/codebert-base +./run.sh microsoft/codebert-base "$ROOT_DIR/results/codebert/Code-classification-POJ104" "" roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_contrabert_c.sh similarity index 69% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_contrabert_c.sh index ca20d20..ac022e1 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_c.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_contrabert_c.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with contrabert_c +# Downstream evaluation: Code-classification-POJ104 with contrabert_c set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-classification-POJ104" Cpp roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/ContraBERT_C" "$ROOT_DIR/results/contrabert_c/Code-classification-POJ104" "" roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_contrabert_g.sh similarity index 69% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_contrabert_g.sh index 5bc3d62..d7dd82e 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_contrabert_g.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_contrabert_g.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with contrabert_g +# Downstream evaluation: Code-classification-POJ104 with contrabert_g set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/ContraBERT_G" "$ROOT_DIR/results/contrabert_g/Code-classification-POJ104" "" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_graphcodebert.sh similarity index 70% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_graphcodebert.sh index 34c273f..2168831 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_graphcodebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_graphcodebert.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with graphcodebert +# Downstream evaluation: Code-classification-POJ104 with graphcodebert set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base +./run.sh microsoft/graphcodebert-base "$ROOT_DIR/results/graphcodebert/Code-classification-POJ104" "" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh similarity index 69% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh index f9ec35c..1313bae 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-codebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-codebert +# Downstream evaluation: Code-classification-POJ104 with inv-codebert set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-POJ104" Cpp roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-POJ104" "" roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-contrabert_c.sh similarity index 66% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_inv-contrabert_c.sh index 271fb4d..226d8c7 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_c.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-contrabert_c.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-contrabert_c +# Downstream evaluation: Code-classification-POJ104 with inv-contrabert_c set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-POJ104" Cpp roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_C-supcon/final" "$ROOT_DIR/results/inv-contrabert_c/Code-classification-POJ104" "" roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-contrabert_g.sh similarity index 66% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_inv-contrabert_g.sh index 9279c88..7dd0641 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-contrabert_g.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-contrabert_g.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-contrabert_g +# Downstream evaluation: Code-classification-POJ104 with inv-contrabert_g set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvContraBERT_G-supcon/final" "$ROOT_DIR/results/inv-contrabert_g/Code-classification-POJ104" "" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh similarity index 66% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh index ae2e925..441c9bb 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-graphcodebert +# Downstream evaluation: Code-classification-POJ104 with inv-graphcodebert set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-POJ104" Cpp roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-POJ104" "" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-modernbert.sh similarity index 77% rename from experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh rename to experiments_downstream/Code-classification-POJ104/cls-poj104_inv-modernbert.sh index fb4c60e..aa0264f 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_Cpp_inv-modernbert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-modernbert.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Downstream evaluation: Code-classification-POJ104 (Cpp) with inv-modernbert +# Downstream evaluation: Code-classification-POJ104 with inv-modernbert set -euo pipefail # Parse CUDA device argument (default: 0) @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-classification-POJ104" Cpp modernbert answerdotai/ModernBERT-base +./run.sh "$ROOT_DIR/saved_models/aug-only/InvModernBERT-supcon/final" "$ROOT_DIR/results/inv-modernbert/Code-classification-POJ104" "" modernbert answerdotai/ModernBERT-base diff --git a/experiments_downstream/gen_all.py b/experiments_downstream/gen_all.py index 668a0b2..b3970a2 100644 --- a/experiments_downstream/gen_all.py +++ b/experiments_downstream/gen_all.py @@ -158,15 +158,15 @@ def write_script(task_dir: str, fname: str, content: str) -> None: count += 1 # Code-classification-POJ104: run.sh + # POJ104 has no language subsets — data lives directly in ./dataset/ write_script( "Code-classification-POJ104", - f"cls-poj104_Cpp_{short}.sh", + f"cls-poj104_{short}.sh", make_script( "Code-classification-POJ104", short, mpath, - subset="Cpp", - args_extra=f" Cpp {mtype} {tok_ref}", + args_extra=f' "" {mtype} {tok_ref}', ), ) count += 1 diff --git a/experiments_downstream/run_task.py b/experiments_downstream/run_task.py new file mode 100755 index 0000000..5b7cda7 --- /dev/null +++ b/experiments_downstream/run_task.py @@ -0,0 +1,204 @@ +#!/usr/bin/env python3 +"""Run all models for a given task+dataset combination. + +Usage examples: + # Run all models for Code-classification-POJ104 on GPUs 0-7 + python run_task.py Code-classification-POJ104 + + # Run all models for Clone-detection-CodeNet on GPUs 0,1,2,3 + python run_task.py Clone-detection-CodeNet --gpus 0,1,2,3 + + # Only run scripts matching a subset (e.g., Java250) + python run_task.py Clone-detection-CodeNet --subset Java250 + + # Dry run to see what would execute + python run_task.py Defect-detection --dry-run + + # List all available tasks + python run_task.py --list +""" + +from __future__ import annotations + +import os +import queue +import subprocess +import threading +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + +import typer +from tqdm import tqdm + +app = typer.Typer(add_completion=False, no_args_is_help=True) + +SCRIPT_DIR = Path(__file__).resolve().parent + +# Models to skip (not yet ready / under development) +SKIP_MODELS = {"modernbert"} + + +def _is_skipped(script_name: str) -> bool: + """Return True if the script belongs to a skipped model.""" + return any(m in script_name for m in SKIP_MODELS) + + +def discover_tasks() -> list[str]: + """Return sorted list of task directories (those containing .sh files).""" + return sorted( + d.name for d in SCRIPT_DIR.iterdir() if d.is_dir() and any(d.glob("*.sh")) + ) + + +def discover_scripts(task: str, subset: str | None = None) -> list[Path]: + """Return all .sh scripts for a task, optionally filtered by subset.""" + task_path = SCRIPT_DIR / task + if not task_path.is_dir(): + raise typer.BadParameter( + f"Task directory not found: {task}\n" + f"Available tasks: {', '.join(discover_tasks())}" + ) + scripts = sorted(s for s in task_path.glob("*.sh") if not _is_skipped(s.name)) + if not scripts: + raise typer.BadParameter(f"No .sh scripts found in {task}") + if subset: + filtered = [s for s in scripts if subset in s.name] + if not filtered: + all_names = [s.name for s in scripts] + raise typer.BadParameter( + f"No scripts matching subset '{subset}' in {task}.\n" + f"Available scripts: {', '.join(all_names)}" + ) + scripts = filtered + return scripts + + +@app.command() +def main( + task: str = typer.Argument( + None, + help="Task+dataset directory name (e.g., Code-classification-POJ104). " + "Use --list to see all available tasks.", + ), + gpus: str = typer.Option( + "0,1,2,3,4,5,6,7", + "--gpus", + help="Comma-separated GPU ids to use.", + ), + subset: str | None = typer.Option( + None, + "--subset", + help="Only run scripts whose filename contains this substring " + "(e.g., Java250, inv-, codebert).", + ), + dry_run: bool = typer.Option( + False, "--dry-run", help="Print commands without executing them." + ), + list_tasks: bool = typer.Option( + False, "--list", help="List all available task directories and exit." + ), +) -> None: + """Run all model scripts for a given task+dataset, distributed across GPUs.""" + + # --list mode + if list_tasks: + tasks = discover_tasks() + typer.echo("Available tasks:") + for t in tasks: + n_scripts = len( + [s for s in (SCRIPT_DIR / t).glob("*.sh") if not _is_skipped(s.name)] + ) + typer.echo(f" {t} ({n_scripts} scripts)") + raise typer.Exit(0) + + if task is None: + typer.echo("Error: Missing argument 'TASK'.\n") + typer.echo("Use --list to see available tasks, or --help for usage.") + raise typer.Exit(1) + + scripts = discover_scripts(task, subset) + gpu_ids = [g.strip() for g in gpus.split(",") if g.strip()] + if not gpu_ids: + raise typer.BadParameter("No GPU ids provided") + + total = len(scripts) + typer.echo(f"Task: {task}") + typer.echo(f"Scripts to run: {total}") + typer.echo(f"GPUs: {', '.join(gpu_ids)}") + typer.echo("") + + if dry_run: + for i, script in enumerate(scripts): + gpu_id = gpu_ids[i % len(gpu_ids)] + typer.echo(f" [GPU {gpu_id}] bash {script.name}") + typer.echo(f"\n[dry-run] {total} jobs across {len(gpu_ids)} GPUs") + raise typer.Exit(0) + + # Work-stealing GPU pool + gpu_pool: queue.Queue[str] = queue.Queue() + for gid in gpu_ids: + gpu_pool.put(gid) + + running = 0 + failed = 0 + lock = threading.Lock() + failures: list[str] = [] + pbar = tqdm(total=total, desc=task, unit="script") + + def run_script(script: Path) -> None: + nonlocal running, failed + gpu_id = gpu_pool.get() + name = script.name + log_path = script.with_suffix(".log") + try: + with lock: + running += 1 + pbar.set_postfix(running=running, failed=failed, refresh=True) + + env = os.environ.copy() + env["CUDA_VISIBLE_DEVICES"] = gpu_id + + with open(log_path, "w") as log_file: + log_file.write(f"[launch] GPU {gpu_id}: {name}\n") + log_file.write(f"[launch] cmd: bash {script}\n\n") + log_file.flush() + + proc = subprocess.Popen( + ["bash", str(script), gpu_id], + cwd=str(script.parent), + env=env, + stdout=log_file, + stderr=subprocess.STDOUT, + ) + code = proc.wait() + + with lock: + running -= 1 + if code != 0: + failed += 1 + failures.append(f"{name} (exit {code})") + tqdm.write(f"[FAIL] GPU {gpu_id}: {name} (exit {code})") + else: + tqdm.write(f"[done] GPU {gpu_id}: {name}") + pbar.set_postfix(running=running, failed=failed, refresh=False) + pbar.update(1) + finally: + gpu_pool.put(gpu_id) + + with ThreadPoolExecutor(max_workers=len(gpu_ids)) as executor: + futures = [executor.submit(run_script, s) for s in scripts] + for f in futures: + f.result() + pbar.close() + + if failures: + typer.echo(f"\n[error] {len(failures)}/{total} scripts failed:") + for failure in failures: + typer.echo(f" - {failure}") + raise typer.Exit(1) + + typer.echo(f"\n[done] All {total} scripts for {task} completed successfully.") + + +if __name__ == "__main__": + app() From 5abc2c42a57e1178be4508c1c5c23dfdc8a3a24d Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Mon, 16 Feb 2026 12:57:57 +0800 Subject: [PATCH 22/24] always load final checkpoint --- .../Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh | 2 +- .../clone-bcb_inv-graphcodebert.sh | 2 +- .../clone-codenet_C++1400_inv-codebert.sh | 2 +- .../clone-codenet_C++1400_inv-graphcodebert.sh | 2 +- .../clone-codenet_Java250_inv-codebert.sh | 2 +- .../clone-codenet_Java250_inv-graphcodebert.sh | 2 +- .../clone-codenet_Python800_inv-codebert.sh | 2 +- .../clone-codenet_Python800_inv-graphcodebert.sh | 2 +- .../Clone-detection-POJ104/clone-poj104_inv-codebert.sh | 2 +- .../Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh | 2 +- .../cls-codenet_C++1400_inv-codebert.sh | 2 +- .../cls-codenet_C++1400_inv-graphcodebert.sh | 2 +- .../cls-codenet_Java250_inv-codebert.sh | 2 +- .../cls-codenet_Java250_inv-graphcodebert.sh | 2 +- .../cls-codenet_Python800_inv-codebert.sh | 2 +- .../cls-codenet_Python800_inv-graphcodebert.sh | 2 +- .../Code-classification-POJ104/cls-poj104_inv-codebert.sh | 2 +- .../cls-poj104_inv-graphcodebert.sh | 2 +- .../Code-translation/translation_inv-codebert.sh | 2 +- .../Code-translation/translation_inv-graphcodebert.sh | 2 +- .../Defect-detection/defect_inv-codebert.sh | 2 +- .../Defect-detection/defect_inv-graphcodebert.sh | 2 +- experiments_downstream/gen_all.py | 4 ++-- 23 files changed, 24 insertions(+), 24 deletions(-) diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh index f5f7921..78764dc 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-BigCloneBench" +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh index 3a2aa1e..5c6b1af 100755 --- a/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-BigCloneBench/clone-bcb_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-BigCloneBench" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-BigCloneBench" +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-BigCloneBench" diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh index 2e7ebc7..260d89d 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh index 1ea2e05..a28fbe1 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_C++1400_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh index 3e8bbce..e644659 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh index 0884879..a8f171d 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Java250_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh index 2bf8cf7..0c85cee 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Clone-detection-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh index 6ee9e5b..715dfee 100755 --- a/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-CodeNet/clone-codenet_Python800_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh index e98c640..af4ddba 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Clone-detection-POJ104" roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Clone-detection-POJ104" roberta microsoft/codebert-base diff --git a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh index 18bb9e3..79a12a1 100755 --- a/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh +++ b/experiments_downstream/Clone-detection-POJ104/clone-poj104_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Clone-detection-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-POJ104" roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Clone-detection-POJ104" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh index 05c3e7e..6c27b0e 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" C++1400 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh index a69b7c8..9a35213 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_C++1400_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" C++1400 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh index 6d4e77e..cc57b50 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" Java250 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh index ac6e17e..63d6383 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Java250_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" Java250 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh index d7992e7..4745f51 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Code-classification-CodeNet" Python800 roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh index 4998a2b..34c119e 100755 --- a/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-CodeNet/cls-codenet_Python800_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-CodeNet" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-CodeNet" Python800 roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh index 1313bae..9be9b07 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-classification-POJ104" "" roberta microsoft/codebert-base +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Code-classification-POJ104" "" roberta microsoft/codebert-base diff --git a/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh index 441c9bb..782ba59 100755 --- a/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh +++ b/experiments_downstream/Code-classification-POJ104/cls-poj104_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-classification-POJ104" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-POJ104" "" roberta microsoft/graphcodebert-base +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Code-classification-POJ104" "" roberta microsoft/graphcodebert-base diff --git a/experiments_downstream/Code-translation/translation_inv-codebert.sh b/experiments_downstream/Code-translation/translation_inv-codebert.sh index f227b4f..4528b08 100755 --- a/experiments_downstream/Code-translation/translation_inv-codebert.sh +++ b/experiments_downstream/Code-translation/translation_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-translation" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Code-translation" +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Code-translation" diff --git a/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh b/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh index 34725a7..c0801e6 100755 --- a/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh +++ b/experiments_downstream/Code-translation/translation_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Code-translation" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Code-translation" +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Code-translation" diff --git a/experiments_downstream/Defect-detection/defect_inv-codebert.sh b/experiments_downstream/Defect-detection/defect_inv-codebert.sh index a32de11..16e7d3d 100755 --- a/experiments_downstream/Defect-detection/defect_inv-codebert.sh +++ b/experiments_downstream/Defect-detection/defect_inv-codebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Defect-detection" -./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon" "$ROOT_DIR/results/inv-codebert/Defect-detection" +./run.sh "$ROOT_DIR/saved_models/InvCodeBERT-supcon/final" "$ROOT_DIR/results/inv-codebert/Defect-detection" diff --git a/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh b/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh index 8c15850..80d5266 100755 --- a/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh +++ b/experiments_downstream/Defect-detection/defect_inv-graphcodebert.sh @@ -11,4 +11,4 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" export CUDA_VISIBLE_DEVICES="$CUDA_DEVICE" cd "$ROOT_DIR/downstream/Defect-detection" -./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon" "$ROOT_DIR/results/inv-graphcodebert/Defect-detection" +./run.sh "$ROOT_DIR/saved_models/InvGraphCodeBERT-supcon/final" "$ROOT_DIR/results/inv-graphcodebert/Defect-detection" diff --git a/experiments_downstream/gen_all.py b/experiments_downstream/gen_all.py index b3970a2..4471370 100644 --- a/experiments_downstream/gen_all.py +++ b/experiments_downstream/gen_all.py @@ -31,13 +31,13 @@ # Our trained models ( "inv-codebert", - "./saved_models/InvCodeBERT-supcon", + "./saved_models/InvCodeBERT-supcon/final", "microsoft/codebert-base", "roberta", ), ( "inv-graphcodebert", - "./saved_models/InvGraphCodeBERT-supcon", + "./saved_models/InvGraphCodeBERT-supcon/final", "microsoft/graphcodebert-base", "roberta", ), From 8782e3ea50015c983eb97310a879975cf14e149a Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 23:01:50 -0800 Subject: [PATCH 23/24] restore AGENTS.md --- AGENTS.md | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 173 insertions(+), 4 deletions(-) mode change 100644 => 100755 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md old mode 100644 new mode 100755 index bba8f44..3c3be48 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,175 @@ -# Claude Notes +# AGENTS.md -## Scripts +## Project Overview -- `python experiments_downstream/parse_results.py --results-root results` - parses downstream evaluation logs into a table with regular vs augmented scores. +**InvPT** (Invariant Pre-training) is a research project for robust code representation learning. +It continues pre-training encoder-based code models (GraphCodeBERT, ContraBERT) using +semantic-preserving code transformations combined with contrastive learning and curriculum learning. +The goal is to improve both downstream task performance and robustness against syntactically +different but semantically equivalent programs (invariant programs). + +Paper: *Invariant Pre-training for Robust Code Representation Learning* (ICSE 2026) + +## Repository Structure + +``` +InvPT/ +├── modeling/ # Core training pipeline +│ ├── cli.py # Typer CLI entry point (run / pretrain subcommands) +│ ├── config.py # PretrainConfig dataclass, YAML config loading +│ ├── pretrain.py # Pre-training logic (main function) +│ ├── model.py # ContrastiveTrainer (MLM + InfoNCE loss) +│ ├── dataloader.py # Data collation, AugType enum, CodeSearchNetExample +│ └── common.py # Device setup, seed utilities +├── python_transform/ # Python AST-based code transformations +│ ├── transform.py # Transformation orchestrator +│ ├── augment_pretrain.py# Batch augmentation for pre-training data +│ ├── src/ # Individual transformers (NodeTransformer subclasses) +│ └── tests/ # Unit tests for transformations +├── java_transform/ # Java code transformations via SPAT +│ ├── transform.py # Transformation orchestrator +│ ├── augment_pretrain.py# Batch augmentation for pre-training data +│ ├── utils.py # SPAT JAR interface +│ └── SPAT-linux.jar # External Java transformation tool +├── cpp_transforms/ # C/C++ transformations via libclang +│ ├── transform.py # Transformation orchestrator +│ └── transformations/ # Individual transformation modules +├── data/ # Pre-training dataset scripts +│ └── get_code_search_net.py # Downloads CodeSearchNet from HuggingFace +├── downstream/ # Fine-tuning & evaluation (7 tasks from CodeXGLUE) +│ ├── Clone-detection-POJ-104/ +│ ├── Clone-detection-CodeNet/ +│ ├── Clone-detection-BigCloneBench/ +│ ├── Code-classification-POJ104/ +│ ├── Code-classification-CodeNet/ +│ ├── Defect-detection/ +│ └── Code-translation/ +├── plot/ # t-SNE visualization of embeddings +│ └── visualize.py +├── experiments/ # YAML experiment configurations +│ ├── base.yaml # Base supcon config (matches original run_pretrain.sh) +│ ├── grouped_example.yaml # Grouped contrastive mode example +│ └── modernbert_base.yaml # ModernBERT-base config (mean pooling) +├── saved_models/ # Pre-trained model checkpoints +├── run_pretrain.sh # Pre-training launch script +├── clang.sh # LLVM 14 installation script +├── pyproject.toml # Dependencies (managed by uv) +└── .envrc # Environment variables (direnv) +``` + +## Key Concepts + +- **Invariant programs**: Semantically equivalent code with different syntax (variable names, loop structures, branching). These occur naturally in real codebases. +- **Training loss**: `L = L_MLM(X) + L_MLM(X_inv) + alpha * L_InfoNCE(X, X_inv)` where alpha=0.7. +- **Curriculum learning**: Self-contrast (easy, same code with different MLM masks) and invariant-contrast (hard, transformed code) are trained simultaneously with low learning rate. +- **PL-only**: Unlike prior work (CodeBERT, ContraBERT), InvPT removes natural language docstrings during pre-training. +- **No MoCo**: Uses a single shared encoder for original and transformed code, unlike ContraBERT which uses momentum contrast. +- **Contrastive modes**: `info_nce` (diagonal positives), `supcon` (multi-positive by function_id mask), `grouped` (grouped multi-key contrast with explicit aug grouping via `--max_num_augs`). +- **Model types**: `roberta` (RoBERTa/CodeBERT/ContraBERT, default) and `modernbert` (ModernBERT with RoPE, Flash Attention, 8K context). Configured via `model_type` in YAML configs. +- **Pooling strategies**: `cls` (CLS token, default for RoBERTa) and `mean` (mean pooling over non-padding tokens, recommended for ModernBERT). + +## Transformation Operators + +| Operator | Python | Java | C/C++ | Description | +|----------|--------|------|-------|-------------| +| VarRe | yes | yes | yes | Rename local variables to random strings | +| F2W | no | yes | yes | Convert for-loop to while-loop | +| W2F | no | yes | yes | Convert while-loop to for-loop | +| PP2AA | no | yes | yes | Convert `x++` to `x += 1` | +| AA2EA | yes | yes | yes | Convert `x += 1` to `x = x + 1` | +| RevIf | yes | yes | yes | Negate condition, swap if/else branches | + +## Development Setup + +```sh +uv sync # Install Python dependencies +source .envrc # Load environment variables +./clang.sh # Install LLVM 14 (for C/C++ transforms) +``` + +Requires: Python 3.11+, JDK 11+ (for Java transforms), LLVM 14 (for C/C++ transforms), transformers >= 4.48 (for ModernBERT support). + +## Running Tests + +```sh +pytest python_transform/tests/ +``` + +## Pre-training Pipeline + +1. Download data: `cd data && python get_code_search_net.py` +2. Augment Python: `python python_transform/augment_pretrain.py -i data/raw_csn_py.jsonl -o data/aug_csn_py.jsonl` +3. Augment Java: `python java_transform/augment_pretrain.py -i data/raw_csn_java.jsonl -o data/aug_csn_java.jsonl` +4. Combine: `cat data/raw_csn.jsonl data/aug_csn_py.jsonl data/aug_csn_java.jsonl > data/csn.jsonl` +5. Train: `./run_pretrain.sh` or `python modeling/cli.py run experiments/base.yaml` + +Pre-training runs for 50k steps on 4 GPUs with batch size 256, learning rate 5e-5, and 5000 warmup steps. + +### Experiment Configuration + +The CLI (`modeling/cli.py`) has two subcommands: + +- **`run`** — load a YAML config from `experiments/` (no CLI overrides; edit the YAML to change parameters) +- **`pretrain`** — pass all parameters directly as CLI options (backward compatible) + +```sh +# From a YAML config (recommended) +python modeling/cli.py run experiments/base.yaml + +# Direct CLI options (backward compatible) +python modeling/cli.py pretrain --batch-size 64 --num-epochs 3 --model-name ./saved_models/ContraBERT_G + +# See available subcommands / options +python modeling/cli.py --help +python modeling/cli.py run --help +python modeling/cli.py pretrain --help +``` + +To create a new experiment, copy an existing YAML file in `experiments/` and modify the parameters. + +## Downstream Evaluation + +Each task in `downstream/` has a `run.sh` script: + +```sh +cd downstream/Clone-detection-POJ-104 +./run.sh +``` + +Pre-generated per-model evaluation scripts live in `experiments_downstream/`, including +ModernBERT variants. Regenerate them with `python3 experiments_downstream/gen_all.py`. + +Metrics: MAP@R for clone detection, accuracy for defect detection and code classification. + +## Code Conventions + +- Type annotations are used throughout; checked with mypy (strict mode, see `mypy.ini`). +- Functional error handling via `returns` library (`Maybe`, `Some`, `Nothing`). +- Parallel processing via `pathos` (serializable lambdas). +- CLI interfaces use `typer`. Pre-training uses YAML configs via `modeling/config.py`. +- Experiment tracking via Weights & Biases (`wandb`). + +## Development Guidelines + +### Developing + +- Before start working, refresh your knowledge from contents in `.agents` first. +- Always update `README.md` and `CLAUDE.md` when you introduce new features or libraries. +- Always write unit tests for integration testing and functional testing of new features. +- Always test your code after your implementation. +- Use `pre-commit install --install-hooks` (and optionally `--hook-type pre-push`) to enable local git hooks. +- You should not commit anything and create pull request, let human do them. However, please suggest commit messages after implementation. + +1. Use `.agents/sandbox/` for throwaway exploration that will not be committed. +2. Use `.agents/notes/` for longer-term notes that may be useful later. +Always write down your plans and reasoning for future reference when encountering major tasks, +like adding a feature. +3. Use `.agents/accomplished/` for recording completed tasks and the summary of what we did, +this may be useful for future reference. + + +## Common Tasks + +- **Add a new transformation operator**: Implement it in the relevant `*_transform/` directory. For Python, subclass `ast.NodeTransformer`; for Java, use a SPAT rule ID; for C/C++, use libclang AST traversal. Register it in the corresponding `TRANSFORMATION_MAP`. +- **Change the contrastive loss**: Modify `ContrastiveTrainer.compute_loss()` in `modeling/model.py`. Alternative loss functions (e.g., Barlow Twins) are already stubbed there. +- **Add a new downstream task**: Follow the CodeXGLUE structure in `downstream/`. Each task needs a `code/` directory with training scripts, a `dataset/` directory, and a `run.sh` entry point. From 08eee6207a5b965715f1c162461ee74e20be4290 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 15 Feb 2026 23:08:46 -0800 Subject: [PATCH 24/24] fix unittest --- tests/test_model_wrapper.py | 1 + tests/test_parse_results.py | 73 ++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/tests/test_model_wrapper.py b/tests/test_model_wrapper.py index bcd23fc..174b8f6 100644 --- a/tests/test_model_wrapper.py +++ b/tests/test_model_wrapper.py @@ -93,6 +93,7 @@ def _make_modernbert_wrapper( num_attention_heads=num_attention_heads, intermediate_size=intermediate_size, max_position_embeddings=max_position_embeddings, + pad_token_id=0, ) mlm = ModernBertForMaskedLM(config) return SplitHeadWrapper(mlm) diff --git a/tests/test_parse_results.py b/tests/test_parse_results.py index 67aa07c..01646e4 100644 --- a/tests/test_parse_results.py +++ b/tests/test_parse_results.py @@ -2,7 +2,13 @@ from pathlib import Path -from experiments_downstream.parse_results import collect_results, render_table +from experiments_downstream.parse_results import ( + _collect_clone_row, + _collect_cls_row, + build_table, + parse_classification_score, + parse_clone_score, +) def _write(path: Path, content: str) -> None: @@ -10,9 +16,33 @@ def _write(path: Path, content: str) -> None: path.write_text(content) -def test_collect_results_clone_and_classification(tmp_path: Path) -> None: +def test_parse_clone_score_float64(tmp_path: Path) -> None: + log = tmp_path / "test.log" + log.write_text("{'MAP@R': np.float64(0.5621)}\n") + assert parse_clone_score(log) == 0.5621 + + +def test_parse_clone_score_missing(tmp_path: Path) -> None: + assert parse_clone_score(tmp_path / "nonexistent.log") is None + + +def test_parse_classification_score(tmp_path: Path) -> None: + log = tmp_path / "test_train.log" + log.write_text( + "02/16/2026 00:00:00 - INFO - __main__ - ***** Test results *****\n" + "02/16/2026 00:00:00 - INFO - __main__ - test_acc = 0.3992\n" + ) + assert parse_classification_score(log) == 0.3992 + + +def test_parse_classification_score_missing(tmp_path: Path) -> None: + assert parse_classification_score(tmp_path / "nonexistent.log") is None + + +def test_build_table_clone_and_classification(tmp_path: Path) -> None: results_root = tmp_path / "results" + # Clone detection – POJ104 (files directly in task dir) _write( results_root / "inv-codebert" / "Clone-detection-POJ104" / "test.log", "{'MAP@R': np.float64(0.5621)}\n", @@ -22,10 +52,11 @@ def test_collect_results_clone_and_classification(tmp_path: Path) -> None: "{'MAP@R': np.float64(0.4321)}\n", ) - test_train_log = """ - 02/16/2026 00:00:00 - INFO - __main__ - ***** Test results ***** - 02/16/2026 00:00:00 - INFO - __main__ - test_acc = 0.3992 - """ + # Classification – CodeNet / Java250 + test_train_log = ( + "02/16/2026 00:00:00 - INFO - __main__ - ***** Test results *****\n" + "02/16/2026 00:00:00 - INFO - __main__ - test_acc = 0.3992\n" + ) _write( results_root / "inv-codebert" @@ -43,23 +74,31 @@ def test_collect_results_clone_and_classification(tmp_path: Path) -> None: test_train_log.replace("0.3992", "0.2777"), ) - results = collect_results(results_root) - assert len(results) == 2 - clone = next(r for r in results if r.task == "Clone-detection-POJ104") - cls = next(r for r in results if r.task == "Code-classification-CodeNet") + clone_df = build_table(results_root, _collect_clone_row, 4) + assert len(clone_df) == 1 + row = clone_df.iloc[0] + assert row["Model"] == "inv-codebert" + assert row["POJ104"] == "56.2100" + assert row["POJ104 aug"] == "43.2100" - assert clone.scores.regular == 0.5621 - assert clone.scores.augmented == 0.4321 - assert cls.scores.regular == 0.3992 - assert cls.scores.augmented == 0.2777 + cls_df = build_table(results_root, _collect_cls_row, 4) + assert len(cls_df) == 1 + row = cls_df.iloc[0] + assert row["Model"] == "inv-codebert" + assert row["Java250"] == "39.9200" + assert row["Java250 aug"] == "27.7700" -def test_render_table_placeholder_for_missing(tmp_path: Path) -> None: +def test_build_table_placeholder_for_missing(tmp_path: Path) -> None: results_root = tmp_path / "results" _write( results_root / "inv-codebert" / "Clone-detection-POJ104" / "test.log", "{'MAP@R': np.float64(0.5621)}\n", ) - table = render_table(collect_results(results_root), 4) - assert "-" in table + clone_df = build_table(results_root, _collect_clone_row, 4) + row = clone_df.iloc[0] + # POJ104 regular is present, but aug and CodeNet subsets should be "-" + assert row["POJ104"] == "56.2100" + assert row["POJ104 aug"] == "-" + assert row["Java250"] == "-"