Publish measure_vlm.py from marimo
Browse files- measure_vlm.py +40 -5
measure_vlm.py
CHANGED
|
@@ -20,7 +20,9 @@ from pathlib import Path
|
|
| 20 |
from tiny_computer_agent import (
|
| 21 |
DecisionMenu, GrabScreen, ImageScreen, IndexedScreen, make_detector,
|
| 22 |
)
|
| 23 |
-
from tiny_computer_agent.models import
|
|
|
|
|
|
|
| 24 |
|
| 25 |
GOAL = "click 'Save' to save the document"
|
| 26 |
OUT = Path("preview")
|
|
@@ -119,9 +121,14 @@ def main(argv=None) -> int:
|
|
| 119 |
"tree first, so only real widgets are offered")
|
| 120 |
parser.add_argument("--open-gtk", action="store_true",
|
| 121 |
help="open the GTK window (with a session bus) and index that")
|
| 122 |
-
parser.add_argument("--
|
|
|
|
|
|
|
| 123 |
parser.add_argument("--goal", default=GOAL)
|
| 124 |
parser.add_argument("--modes", default="json,choice,scan,rank")
|
|
|
|
|
|
|
|
|
|
| 125 |
parser.add_argument("--max-new-tokens", type=int, default=64)
|
| 126 |
args = parser.parse_args(argv)
|
| 127 |
|
|
@@ -142,15 +149,43 @@ def main(argv=None) -> int:
|
|
| 142 |
if gtk is not None:
|
| 143 |
gtk.terminate()
|
| 144 |
menu = DecisionMenu(observation)
|
| 145 |
-
print(f"screen: {args.screen} ({image.width}x{image.height})
|
|
|
|
| 146 |
print(f"index: {len(observation.elements)} elements -> menu of {len(menu)}")
|
| 147 |
print(menu.render())
|
| 148 |
print()
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
results = []
|
| 151 |
for mode in args.modes.split(","):
|
| 152 |
-
brain =
|
| 153 |
-
|
| 154 |
start = time.time()
|
| 155 |
try:
|
| 156 |
action = brain.decide(args.goal, observation)
|
|
|
|
| 20 |
from tiny_computer_agent import (
|
| 21 |
DecisionMenu, GrabScreen, ImageScreen, IndexedScreen, make_detector,
|
| 22 |
)
|
| 23 |
+
from tiny_computer_agent.models import (
|
| 24 |
+
DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL, TextPlannerBrain, VLMBrain,
|
| 25 |
+
)
|
| 26 |
|
| 27 |
GOAL = "click 'Save' to save the document"
|
| 28 |
OUT = Path("preview")
|
|
|
|
| 121 |
"tree first, so only real widgets are offered")
|
| 122 |
parser.add_argument("--open-gtk", action="store_true",
|
| 123 |
help="open the GTK window (with a session bus) and index that")
|
| 124 |
+
parser.add_argument("--brain", default="vlm", choices=("vlm", "text-planner"),
|
| 125 |
+
help="which tiny model to ask; text-planner reads the index only")
|
| 126 |
+
parser.add_argument("--model", default=None)
|
| 127 |
parser.add_argument("--goal", default=GOAL)
|
| 128 |
parser.add_argument("--modes", default="json,choice,scan,rank")
|
| 129 |
+
parser.add_argument("--sweep", action="store_true",
|
| 130 |
+
help="ask the same four items about four different goals, and "
|
| 131 |
+
"count how often each mode gets it right")
|
| 132 |
parser.add_argument("--max-new-tokens", type=int, default=64)
|
| 133 |
args = parser.parse_args(argv)
|
| 134 |
|
|
|
|
| 149 |
if gtk is not None:
|
| 150 |
gtk.terminate()
|
| 151 |
menu = DecisionMenu(observation)
|
| 152 |
+
print(f"brain: {args.brain} | screen: {args.screen} ({image.width}x{image.height}) "
|
| 153 |
+
f"| detector: {args.detector}")
|
| 154 |
print(f"index: {len(observation.elements)} elements -> menu of {len(menu)}")
|
| 155 |
print(menu.render())
|
| 156 |
print()
|
| 157 |
|
| 158 |
+
brain_class = VLMBrain if args.brain == "vlm" else TextPlannerBrain
|
| 159 |
+
model_id = args.model or (DEFAULT_VISION_MODEL if args.brain == "vlm" else DEFAULT_TEXT_MODEL)
|
| 160 |
+
|
| 161 |
+
if args.sweep:
|
| 162 |
+
# every item, asked about every goal: the same shot, the same weights,
|
| 163 |
+
# only the question changes - which is the whole point of the item
|
| 164 |
+
labels = [element.label for element in observation.elements][:4]
|
| 165 |
+
print(f"sweep: {len(labels)} items, {len(labels)} goals, brain {args.brain}")
|
| 166 |
+
print()
|
| 167 |
+
print(f"{'mode':8} {'right':>7} seconds what it chose")
|
| 168 |
+
for mode in args.modes.split(","):
|
| 169 |
+
brain = brain_class(model_id, decision_mode=mode, retries=3, votes=1,
|
| 170 |
+
max_new_tokens=args.max_new_tokens)
|
| 171 |
+
right, chosen, start = 0, [], time.time()
|
| 172 |
+
for label in labels:
|
| 173 |
+
goal = f"click '{label}' to do that"
|
| 174 |
+
try:
|
| 175 |
+
action = brain.decide(goal, observation)
|
| 176 |
+
got = action.label if action.kind == "click" else action.kind
|
| 177 |
+
except Exception as exc:
|
| 178 |
+
got = f"<{type(exc).__name__}>"
|
| 179 |
+
chosen.append(got)
|
| 180 |
+
right += int(got == label)
|
| 181 |
+
print(f"{mode:8} {right}/{len(labels):<5} "
|
| 182 |
+
f"{round(time.time() - start, 1):8} {chosen}")
|
| 183 |
+
return 0
|
| 184 |
+
|
| 185 |
results = []
|
| 186 |
for mode in args.modes.split(","):
|
| 187 |
+
brain = brain_class(model_id, decision_mode=mode, retries=3, votes=1,
|
| 188 |
+
max_new_tokens=args.max_new_tokens)
|
| 189 |
start = time.time()
|
| 190 |
try:
|
| 191 |
action = brain.decide(args.goal, observation)
|