jiang-cc commited on
Commit
0081f93
·
verified ·
1 Parent(s): 3ddf3a2

Use diagonal spatial positions for comparison tokens

Browse files

Replace repeated h/w position indices with the evaluated diagonal layout. Keep checkpoint tensors unchanged and document the previous revision for reproducibility.

Files changed (2) hide show
  1. README.md +7 -0
  2. modeling_ad_copilot.py +11 -4
README.md CHANGED
@@ -82,3 +82,10 @@ print(processor.batch_decode(trimmed, skip_special_tokens=True)[0])
82
  year={2025}
83
  }
84
  ```
 
 
 
 
 
 
 
 
82
  year={2025}
83
  }
84
  ```
85
+
86
+
87
+ ## Comparison-token positional encoding update
88
+
89
+ The inference code uses diagonal spatial positions for comparison tokens: their height and width indices advance from 0 to `compare_token_size - 1`, while their temporal coordinate remains fixed. This update changes position indices, including downstream position offsets; checkpoint tensors are unchanged.
90
+
91
+ To reproduce the previous shared-position inference behavior, pin `revision="3ddf3a219e5c95223b8c13da18c7b8e53479c5a0"` when loading the model and processor.
modeling_ad_copilot.py CHANGED
@@ -712,10 +712,17 @@ class ADCopilotVLModel(Qwen2_5_VLModel):
712
  if ed_image < ed_video:
713
  # 如果当前是图片,则需要插入 compare_token_size 个图像对比的token的position
714
  compare_t_index = t_index[-1].repeat(self.compare_token_size)
715
- # compare_h_index = torch.arange(self.compare_token_size)
716
- # compare_w_index = torch.arange(self.compare_token_size)
717
- compare_h_index = compare_t_index
718
- compare_w_index = compare_t_index
 
 
 
 
 
 
 
719
  llm_pos_ids_list.append(torch.stack([compare_t_index, compare_h_index, compare_w_index]) + text_len + st_idx)
720
  st = st + self.compare_token_size
721
 
 
712
  if ed_image < ed_video:
713
  # 如果当前是图片,则需要插入 compare_token_size 个图像对比的token的position
714
  compare_t_index = t_index[-1].repeat(self.compare_token_size)
715
+ # Comparison tokens use diagonal spatial positions.
716
+ compare_h_index = torch.arange(
717
+ self.compare_token_size,
718
+ device=t_index.device,
719
+ dtype=t_index.dtype,
720
+ )
721
+ compare_w_index = torch.arange(
722
+ self.compare_token_size,
723
+ device=t_index.device,
724
+ dtype=t_index.dtype,
725
+ )
726
  llm_pos_ids_list.append(torch.stack([compare_t_index, compare_h_index, compare_w_index]) + text_len + st_idx)
727
  st = st + self.compare_token_size
728