"""Pinned attention chunk RoPE oracle, with independent per-row controls.""" import hashlib import json from pathlib import Path import subprocess import sys checkout, output = map(Path, sys.argv[1:3]) assert subprocess.check_output(['git', '-C', str(checkout), 'rev-parse', 'HEAD'], text=True).strip() == '9882703f3105363ddc37eca9f97aa09a1d387112' sys.path.insert(0, str(checkout)) import mlx.core as mx import numpy as np from mtplx.models.qwen4_exp import _vision_chunk_cos_sin, _apply_partial_rope, _build_mrope_axes, _rope_cos_sin, _rope_inv_freq_and_scaling, TextArgs output.mkdir(parents=True, exist_ok=True) manifest = [] for dim, rotary, sections, heads in [(8, 8, [2,1,1], 2), (256,64,[11,11,10],24)]: axes = mx.array(_build_mrope_axes(sections, True), dtype=mx.int32) freq, _ = _rope_inv_freq_and_scaling(TextArgs(head_dim=dim, rope_parameters=dict(rope_type="default", rope_theta=10000000, partial_rotary_factor=rotary/dim))) short = [[0,1,2,2],[0,1,3,3],[0,1,4,4]] full = [r + [3,4,5,6] for r in short] equal = [list(range(4))] * 3 for mode, table, start, rows, delta in [ ('inside',short,0,4,-1), ('outside',short,4,2,-1), ('straddle',short,2,4,-1), ('full_text_tail',full,6,4,-1), ('equal',equal,2,4,0), ('none',None,4,2,-1), ('empty',[[],[],[]],4,2,-1), ]: for scaling in [1.,1.25]: t = None if table is None else mx.array(table,dtype=mx.int32) cos, sin = _vision_chunk_cos_sin(t,delta,start,rows,freq,axes,scaling) # Independent row-position construction; no chunk helper is used. pos3 = np.stack([np.array(table)[:,p] if table is not None and p