Skip to content

Fix/Improve: Batch paired inputs to remove BatchNorm order dependence and speed up training - #33

Open
Kaminyou wants to merge 1 commit into
IsoNet-cryoET:mainfrom
Kaminyou:fix/batchnorm_stats
Open

Fix/Improve: Batch paired inputs to remove BatchNorm order dependence and speed up training#33
Kaminyou wants to merge 1 commit into
IsoNet-cryoET:mainfrom
Kaminyou:fix/batchnorm_stats

Conversation

@Kaminyou

@Kaminyou Kaminyou commented Aug 6, 2026

Copy link
Copy Markdown

The paired x1/x2 and net_input1/net_input2 tensors should be concatenated along the batch dimension and each pair should be processed in a shared forward pass.

This change:

  • Ensures that paired inputs use the same BatchNorm batch statistics.
  • Removes order-dependent BatchNorm running-statistic updates.
  • Reduces the number of U-Net forward passes from four to two per iteration.
  • Reduces per-iteration runtime by approximately 15%.

Motivation

Previously, paired inputs were processed sequentially:

preds_x1 = model(x1)
preds_x2 = model(x2)

In training mode, x1 and x2 therefore used independently computed BatchNorm statistics. Their running statistics were also updated sequentially.

With the default BatchNorm momentum of 0.1:

r1 = 0.9 * r0 + 0.1 * statistic_x1
r2 = 0.9 * r1 + 0.1 * statistic_x2
= 0.81 * r0 + 0.09 * statistic_x1 + 0.10 * statistic_x2

Consequently, the second input contributes 10% to the final running statistic, while the first contributes only 9%. Reversing the input order therefore produces different running means and variances.

Because x1 and x2 are paired even/odd observations of the same underlying volume, this order-dependent behavior is undesirable.

Changes

The paired inputs are now concatenated and processed together:

preds_x1, preds_x2 = model(
    torch.cat([x1, x2], dim=0)
).chunk(2, dim=0)

The same change is applied to net_input1 and net_input2. This gives both halves the same BatchNorm statistics, removes ordering bias, and improves GPU utilization.

Concatenate x1/x2 to remove order-dependent running-stat updates and reduce per-iteration runtime by approximately 15%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant