CCCCyx commited on
Commit
e0aa38d
·
verified ·
1 Parent(s): 1694c7f

per-sample media budgets in processor; per-sample MRoPE position ids for batched vision inputs

Browse files
Files changed (1) hide show
  1. modeling_moss_vl.py +21 -0
modeling_moss_vl.py CHANGED
@@ -1742,6 +1742,27 @@ class MossVLModel(MossVLPreTrainedModel):
1742
  rope_deltas: (batch_size,) - position offset due to vision tokens
1743
  """
1744
  batch_size, max_vision_seq_len, _ = cross_attention_states.shape
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1745
  device = cross_attention_states.device
1746
  image_token_id = self.config.image_token_id
1747
  merge_size = self.visual.spatial_merge_size
 
1742
  rope_deltas: (batch_size,) - position offset due to vision tokens
1743
  """
1744
  batch_size, max_vision_seq_len, _ = cross_attention_states.shape
1745
+ if batch_size > 1:
1746
+ # Match frames to text markers within each sample. Blank images and
1747
+ # right-truncated media may have no corresponding marker; flattening
1748
+ # across the batch would assign their metadata to the next sample.
1749
+ # Keep the original single-sample computation, including in-place
1750
+ # text position updates and generation's per-sample rope_deltas.
1751
+ results = [
1752
+ self.compute_vision_position_ids(
1753
+ input_ids[i:i + 1],
1754
+ position_ids[:, i:i + 1],
1755
+ [vision_token_info[i]],
1756
+ cross_attention_states[i:i + 1],
1757
+ None if attention_mask is None else attention_mask[i:i + 1],
1758
+ )
1759
+ for i in range(batch_size)
1760
+ ]
1761
+ return (
1762
+ torch.cat([result[0] for result in results], dim=1),
1763
+ position_ids,
1764
+ torch.cat([result[2] for result in results], dim=0),
1765
+ )
1766
  device = cross_attention_states.device
1767
  image_token_id = self.config.image_token_id
1768
  merge_size = self.visual.spatial_merge_size