Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions qmp/networks/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ def forward(
similarity = torch.nn.functional.softmax(x @ self.centroid.t(), dim=-1)
# top_k_indices: batch * site * selected
_, top_k_indices = torch.topk(similarity + self.bias, self.selected_num, dim=-1)
# gate_prime, gate: batch * site * routed
gate_prime = torch.zeros_like(similarity).scatter_(-1, top_k_indices, similarity.gather(-1, top_k_indices))
gate = gate_prime / gate_prime.sum(dim=-1).unsqueeze(-1)
# gate, gate: batch * site * routed

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment is now inaccurate/typoed after removing gate_prime (it reads gate, gate: ...). Please update it to describe the single gate tensor to avoid confusion when reading the routing logic.

Suggested change
# gate, gate: batch * site * routed
# gate: batch * site * routed (top-k routed gating weights)

Copilot uses AI. Check for mistakes.
gate = torch.zeros_like(similarity).scatter_(-1, top_k_indices, similarity.gather(-1, top_k_indices))
for i, expert in enumerate(self.feed_forward_routed):
y = y + expert(x) * gate[:, :, i].unsqueeze(-1)
x = self.norm2(y)
Expand Down
Loading