unixcoder baseline script
Browse files- baselines/run.py +50 -0
baselines/run.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""UniXcoder-base on MTEB(Code, v1), CoIR and CoREB(v1) with code-embed-v2's official harness settings.
|
| 2 |
+
|
| 3 |
+
Same mteb / sentence-transformers / transformers versions as v2's merged results, fp32, 1,024 tokens, mean
|
| 4 |
+
pooling (sentence-transformers' default for a plain encoder), encode batch 64. Results go to the private src
|
| 5 |
+
repo under baselines/unixcoder-base/.
|
| 6 |
+
"""
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import mteb
|
| 12 |
+
import torch
|
| 13 |
+
from huggingface_hub import HfApi
|
| 14 |
+
from mteb.cache import ResultCache
|
| 15 |
+
from mteb.models.sentence_transformer_wrapper import SentenceTransformerEncoderWrapper
|
| 16 |
+
from sentence_transformers import SentenceTransformer
|
| 17 |
+
|
| 18 |
+
OUT = Path("/workspace/results")
|
| 19 |
+
OUT.mkdir(parents=True, exist_ok=True)
|
| 20 |
+
BENCHMARKS = ("MTEB(Code, v1)", "CoIR", "CoREB(v1)")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def upload(note: str) -> None:
|
| 24 |
+
(OUT / "progress.json").write_text(json.dumps({"note": note, "time": time.strftime("%H:%M:%S")}))
|
| 25 |
+
try:
|
| 26 |
+
HfApi().upload_folder(folder_path=str(OUT), repo_id="divakantpandey/code-embed-v3-src",
|
| 27 |
+
path_in_repo="baselines/unixcoder-base", commit_message=f"unixcoder baseline: {note}")
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print("upload failed", e, flush=True)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
model = SentenceTransformer("microsoft/unixcoder-base", device="cuda")
|
| 33 |
+
model.max_seq_length = 1024
|
| 34 |
+
print(model, flush=True)
|
| 35 |
+
wrapper = SentenceTransformerEncoderWrapper(model)
|
| 36 |
+
tasks, seen = [], set()
|
| 37 |
+
for b in BENCHMARKS:
|
| 38 |
+
for t in mteb.get_benchmark(b).tasks:
|
| 39 |
+
if t.metadata.name not in seen:
|
| 40 |
+
seen.add(t.metadata.name)
|
| 41 |
+
tasks.append(t)
|
| 42 |
+
print(f"{len(tasks)} tasks; torch {torch.__version__}; mteb {mteb.__version__}", flush=True)
|
| 43 |
+
upload("started")
|
| 44 |
+
for t in tasks:
|
| 45 |
+
t0 = time.time()
|
| 46 |
+
mteb.evaluate(wrapper, [t], encode_kwargs={"batch_size": 64}, cache=ResultCache(str(OUT / "cache")))
|
| 47 |
+
print(f"done {t.metadata.name} in {(time.time() - t0) / 60:.1f} min", flush=True)
|
| 48 |
+
upload(f"done {t.metadata.name}")
|
| 49 |
+
(OUT / "DONE").write_text("ok")
|
| 50 |
+
upload("all done")
|