Spaces:
Sleeping
Sleeping
Align config.use_frame_special_tokens with the processor (checkpoint mismatch)
Browse files
app.py
CHANGED
|
@@ -37,7 +37,8 @@ SAMPLING_FPS = 2
|
|
| 37 |
|
| 38 |
TRACK_STYLE = "video_point_track_per_frame"
|
| 39 |
DEFAULT_PROMPT = "track all fish"
|
| 40 |
-
IM_END_TOKEN_ID = 151937
|
|
|
|
| 41 |
|
| 42 |
# html-v2 pointing format, exactly as in olmo/preprocessing/point_formatter.py
|
| 43 |
COORD_RE = re.compile(r"<(?:points|tracks).*? coords=\"([0-9\t:;, .]+)\"/?>")
|
|
@@ -62,6 +63,17 @@ processor = AutoProcessor.from_pretrained(
|
|
| 62 |
model = AutoModelForImageTextToText.from_pretrained(
|
| 63 |
MODEL_ID, trust_remote_code=True, dtype=torch.bfloat16
|
| 64 |
).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
model.eval()
|
| 66 |
print("Model ready.", flush=True)
|
| 67 |
|
|
@@ -193,6 +205,7 @@ def run_model(video_path: str, turns: list, max_new_tokens: int) -> str:
|
|
| 193 |
print(
|
| 194 |
f"[molmo2fish] input_ids={tuple(ids.shape)} "
|
| 195 |
f"im_end={int((ids == IM_END_TOKEN_ID).sum())} "
|
|
|
|
| 196 |
f"keys={sorted(inputs.keys())}",
|
| 197 |
flush=True,
|
| 198 |
)
|
|
|
|
| 37 |
|
| 38 |
TRACK_STYLE = "video_point_track_per_frame"
|
| 39 |
DEFAULT_PROMPT = "track all fish"
|
| 40 |
+
IM_END_TOKEN_ID = 151937 # <im_end> (config.image_end_token_id)
|
| 41 |
+
FRAME_END_TOKEN_ID = 151944 # <frame_end> (config.frame_end_token_id)
|
| 42 |
|
| 43 |
# html-v2 pointing format, exactly as in olmo/preprocessing/point_formatter.py
|
| 44 |
COORD_RE = re.compile(r"<(?:points|tracks).*? coords=\"([0-9\t:;, .]+)\"/?>")
|
|
|
|
| 63 |
model = AutoModelForImageTextToText.from_pretrained(
|
| 64 |
MODEL_ID, trust_remote_code=True, dtype=torch.bfloat16
|
| 65 |
).to("cuda")
|
| 66 |
+
|
| 67 |
+
# The released checkpoint ships a mismatch: processor_config.json has
|
| 68 |
+
# use_frame_special_tokens=true (so the prompt gets <frame_start>/<frame_end>
|
| 69 |
+
# around every frame, matching training — see olmo/models/molmo2/molmo2.py,
|
| 70 |
+
# which asserts it), but config.json has it false, so the model counts
|
| 71 |
+
# <im_end> instead and asserts "Expected 0 videos, but got 1". Align them.
|
| 72 |
+
if processor.use_frame_special_tokens and not model.config.use_frame_special_tokens:
|
| 73 |
+
print("[molmo2fish] aligning config.use_frame_special_tokens -> True", flush=True)
|
| 74 |
+
model.config.use_frame_special_tokens = True
|
| 75 |
+
model.model.config.use_frame_special_tokens = True
|
| 76 |
+
|
| 77 |
model.eval()
|
| 78 |
print("Model ready.", flush=True)
|
| 79 |
|
|
|
|
| 205 |
print(
|
| 206 |
f"[molmo2fish] input_ids={tuple(ids.shape)} "
|
| 207 |
f"im_end={int((ids == IM_END_TOKEN_ID).sum())} "
|
| 208 |
+
f"frame_end={int((ids == FRAME_END_TOKEN_ID).sum())} "
|
| 209 |
f"keys={sorted(inputs.keys())}",
|
| 210 |
flush=True,
|
| 211 |
)
|