ProgressLM: bypass broken prompts/__init__, inline score parser
Browse files
vanilla_baseline_code/Experiment/RMBench/Vanilla_Baseline/ProgressLM/run_prediction.py
CHANGED
|
@@ -68,12 +68,39 @@ if "CUDA_VISIBLE_DEVICES" not in os.environ:
|
|
| 68 |
except Exception:
|
| 69 |
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
import numpy as np
|
| 73 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 74 |
from core.model import Qwen2VLChat
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
OUT = Path(ARGS.out_root)
|
| 79 |
REFS = OUT / "progresslm_refs"
|
|
|
|
| 68 |
except Exception:
|
| 69 |
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
| 70 |
|
| 71 |
+
_CODE = str(Path(ARGS.progresslm_code).resolve())
|
| 72 |
+
sys.path.insert(0, _CODE)
|
| 73 |
+
import re
|
| 74 |
import numpy as np
|
| 75 |
from PIL import Image
|
| 76 |
+
import importlib.util as _ilu
|
| 77 |
+
|
| 78 |
+
# core is a healthy package -> normal import
|
| 79 |
from core.model import Qwen2VLChat
|
| 80 |
+
# prompts/__init__ imports deleted modules and crashes -> load the file directly
|
| 81 |
+
_spec = _ilu.spec_from_file_location("plm_vdp", os.path.join(_CODE, "prompts/visual_demo_prompt.py"))
|
| 82 |
+
_vdp = _ilu.module_from_spec(_spec); sys.modules["plm_vdp"] = _vdp; _spec.loader.exec_module(_vdp)
|
| 83 |
+
build_visual_demo_prompt_from_item = _vdp.build_visual_demo_prompt_from_item
|
| 84 |
+
VISUAL_DEMO_SYSTEM_PROMPT = _vdp.VISUAL_DEMO_SYSTEM_PROMPT
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def parse_visual_demo_response(response: str):
|
| 88 |
+
"""Extract <score> as 0..1 (or 'n/a'/None). Mirrors ProgressLM's parser."""
|
| 89 |
+
if not response:
|
| 90 |
+
return {"score": None}
|
| 91 |
+
m = re.search(r"<score>(.*?)</score>", response, re.DOTALL)
|
| 92 |
+
if not m:
|
| 93 |
+
return {"score": None}
|
| 94 |
+
s = m.group(1).strip()
|
| 95 |
+
if s.lower() in ("n/a", "na"):
|
| 96 |
+
return {"score": "n/a"}
|
| 97 |
+
try:
|
| 98 |
+
v = float(s[:-1]) / 100.0 if s.endswith("%") else float(s)
|
| 99 |
+
if v > 1.0:
|
| 100 |
+
v = v / 100.0
|
| 101 |
+
return {"score": max(0.0, min(1.0, v))}
|
| 102 |
+
except ValueError:
|
| 103 |
+
return {"score": None}
|
| 104 |
|
| 105 |
OUT = Path(ARGS.out_root)
|
| 106 |
REFS = OUT / "progresslm_refs"
|