hustvl / hustvl/ControlAR

Potential Bug in RoPE Frequency Computation

Open
#18 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
328
Forks
12
PR merge metrics
No merged PRs in 30d

Description

There appears to be a mismatch between the RoPE frequency table initialization and its usage during training in gpt.py.

Current Behavior

In Transformer.__init__():
self.freqs_cis = precompute_freqs_cis_2d(
    grid_size, 
    self.config.dim // self.config.n_head, 
    self.config.rope_base, 
    self.cls_token_num + self.condition_token_num  # = 1 + 256 = 257
)

The precompute_freqs_cis_2d function creates a frequency table with 257 zero-frequency positions at the beginning, followed by actual RoPE frequencies for the image tokens.

During training in forward():

token_embeddings = torch.cat((cond_embeddings, token_embeddings), dim=1)
# Shape: (bs, 1 + 255, dim) = (bs, 256, dim)

if self.training:
    freqs_cis = self.freqs_cis[:token_embeddings.shape[1]]  # Takes first 256 positions

Problem
Since token_embeddings.shape[1] = 256 and the first 257 positions of freqs_cis are zeros, the sliced freqs_cis[:256] contains all zeros. This means the entire training sequence effectively has no positional encoding from RoPE.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in gpt.py by reading Transformer.init, precompute_freqs_cis_2d, and forward together. Trace the sequence lengths and the freqs_cis slice, then verify that the training sequence receives the intended positional frequencies rather than an all-zero slice.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.