When Does Margin Clamping Affect Training Variance? Dataset-Dependent Effects in Contrastive Forward-Forward Learning
Organizations: Independent Researcher
Abstract
Contrastive Forward-Forward (CFF) learning trains Vision Transformers layer by layer against supervised contrastive objectives. CFF training can be sensitive to random seed, but the sources of this instability are poorly understood. We focus on one implementation detail: the positive-pair margin in the contrastive loss is applied through saturating similarity clamping, . We prove that an alternative formulation, subtracting the margin after the log-probability, is gradient-neutral under the mean-over-positives reduction. On CIFAR-10 ( factorial, seeds per cell), clamping produces higher pooled test-accuracy variance () with no difference in mean accuracy. Analyses of clamp activation rates, layerwise gradient norms, and a reduced-margin probe point to saturation-driven gradient truncation at early layers. The effect does not transfer cleanly to other datasets: on CIFAR-100, SVHN, and Fashion-MNIST, clamping produces equal or lower variance. Two factors account for the discrepancy. First, positive-pair density per batch controls how often saturation occurs. Second, task difficulty compresses seed-to-seed spread when accuracy is high. An SVHN difficulty sweep confirms the interaction on a single dataset, with the variance ratio moving from at high accuracy to under aggressive augmentation. In moderate-accuracy regimes with many same-class pairs per batch, switching to the gradient-neutral subtraction reference removes this variance inflation at no cost to mean accuracy. Measuring the layer-0 clamp activation rate serves as a simple check for whether the problem applies.
Figures & tables
| Symbol | Definition |
|---|---|
| Labeled dataset with . | |
| Minibatch size (number of images per iteration). | |
| Two stochastic augmentations of image . | |
| , | Number of transformer layers; layer index . |
| -normalized mean-pooled representation of view at layer (Eq. ( 3 )). | |
| Indices over the concatenated view set (Definition 4.1 ). |
| Parameter | Value |
|---|---|
| Architecture | ViT ( , , ) |
| Patch size | |
| Batch size | 512 |
| Stage 1 (repr. learning) | 600 epochs, AdamW ( , , wd ) |
| Stage 2 (linear probe) | 50 epochs, AdamW ( ) |
| Temperature | 0.15 |
| Margin type | Stability | Mean (%) | Std (%) | Var |
|---|---|---|---|---|
| clamp | detach | 78.52 | 0.927 | 0.8590 |
| clamp | direct | 78.44 | 1.158 | 1.3408 |
| subtract | detach | 78.73 | 0.467 | 0.2178 |
| subtract | direct | 78.30 | 0.224 | 0.0500 |
| Test | Margin type | Stability mode | Interaction |
|---|---|---|---|
| Levene | 0.061 | 0.824 | 0.058 |
| Brown-Forsythe | 0.058 | 0.856 | 0.137 |
| Condition | n | Mean (%) | Std (%) | Var |
|---|---|---|---|---|
| Clamp (pooled) | 14 | 78.48 | 1.008 | 1.0170 |
| Subtract (pooled) | 14 | 78.51 | 0.415 | 0.1724 |
| Schedule | Clamp var | Subtract var | VR | F-test |
|---|---|---|---|---|
| (standard) | 1.0170 | 0.1724 | 0.003 | |
| (low) | 0.6498 | 0.2178 | 0.19 |
| Layer | Margin (std / low) | CAR (std) | CAR (low) | Reduction |
|---|---|---|---|---|
| 0 | 0.40 / 0.20 | 60.7% | 40.3% | 33.7% |
| 1 | 0.36 / 0.19 | 58.3% | 43.7% | 24.9% |
| 2 | 0.31 / 0.17 | 54.0% | 42.5% | 21.3% |
| 3 | 0.27 / 0.16 | 49.6% | 40.5% | 18.3% |
| 4 | 0.23 / 0.14 | 45.8% | 38.6% | 15.6% |
| 5 | 0.19 / 0.13 | 41.6% | 36.6% | 12.0% |
| Layer | Clamp | Subtract | Ratio (subtract / clamp) |
|---|---|---|---|
| L0 | |||
| L1 | |||
| L2 | |||
| L3 |
| Dataset | Pos. pairs | L0 CAR | Acc. (%) | VR | |
|---|---|---|---|---|---|
| CIFAR-10 | 10 | 60.7% | 78.5 | ||
| CIFAR-100 | 100 | 29.0% | 51.8 | ||
| SVHN | 10 | 51.0% | 96.7 | ||
| Fash-MNIST | 10 | — | 92.6 |
| Condition | n | Mean (%) | Std (%) | Var |
|---|---|---|---|---|
| Clamp (pooled) | 10 | 51.82 | 0.505 | 0.255 |
| Subtract (pooled) | 10 | 51.38 | 0.814 | 0.663 |
| Layer | CAR (CIFAR-10) | CAR (CIFAR-100) | Difference |
|---|---|---|---|
| 0 | 60.7% | 29.0% | pp |
| 1 | 58.3% | 27.8% | pp |
| 2 | 54.0% | 24.2% | pp |
| 3 | 49.6% | 21.4% | pp |
| 4 | 45.8% | 18.4% | pp |
| 5 | 41.6% | 15.5% | pp |
| Layer | Margin | Clamp | Subtract | Ratio (C/S) |
|---|---|---|---|---|
| L0 | 0.400 | |||
| L1 | 0.357 | |||
| L2 | 0.314 | |||
| L3 | 0.271 |
| Condition | n | Mean (%) | Std (%) | Var |
|---|---|---|---|---|
| Clamp | 5 | 96.70 | 0.430 | 0.185 |
| Subtract | 5 | 95.29 | 0.853 | 0.727 |
| Condition | n | Mean (%) | Std (%) | Var |
|---|---|---|---|---|
| Clamp | 5 | 92.57 | 0.113 | 0.0127 |
| Subtract | 5 | 91.87 | 0.406 | 0.1645 |
| Difficulty | Acc. (%) | Clamp var | Subtract var | VR | Pattern | |
|---|---|---|---|---|---|---|
| Easy (standard) | 5 | 96.7 | 0.185 | 0.727 | Inverted | |
| Medium | 5 | 26.8 | 37.57 | 17.23 | Elevated | |
| Hard | 5 | 25.0 | 85.45 | 5.11 | Extreme |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Condition | S1 | S2 | S3 | S4 | S5 | S6 | S7 |
|---|---|---|---|---|---|---|---|
| clamp_detach | 78.49 | 78.27 | 78.43 | 76.96 | 78.81 | 78.59 | 80.12 |
| clamp_direct | 78.07 | 77.91 | 79.42 | 76.23 | 79.24 | 78.79 | 79.45 |
| subtract_detach | 78.82 | 79.29 | 78.87 | 79.02 | 77.87 | 78.37 | 78.84 |
| subtract_direct | 78.27 | 78.31 | 78.68 | 78.23 | 78.37 | 78.32 | 77.92 |
| Condition | S1 | S2 | S3 | S4 | S5 | S6 | S7 |
|---|---|---|---|---|---|---|---|
| clamp_detach | 78.97 | 78.49 | 79.04 | 78.15 | 78.46 | 78.49 | 77.99 |
| clamp_direct | 80.16 | 77.36 | 78.33 | 77.74 | 76.88 | 77.55 | 78.35 |
| subtract_detach | 78.82 | 79.29 | 78.87 | 79.02 | 77.87 | 78.37 | 78.84 |
| Layer | CAR (CIFAR-10) | CAR (SVHN) | Difference |
|---|---|---|---|
| 0 | 60.7% | 51.0% | pp |
| 1 | 58.3% | 65.3% | pp |
| 2 | 54.0% | 75.0% | pp |
| 3 | 49.6% | 78.3% | pp |
| Mean (L0–L7) | 47.5% | 70.6% | pp |
| Condition | S1 | S2 | S3 | S4 | S5 |
|---|---|---|---|---|---|
| clamp_detach | 51.98 | 52.06 | 52.32 | 51.62 | 52.36 |
| clamp_direct | 50.84 | 51.60 | 51.62 | 52.43 | 51.36 |
| subtract_detach | 50.85 | 52.25 | 52.31 | 50.17 | 50.90 |
| subtract_direct | 50.78 | 52.52 | 51.98 | 50.81 | 51.23 |
| Condition | S1 | S2 | S3 | S4 | S5 |
|---|---|---|---|---|---|
| clamp | 97.16 | 96.42 | 97.11 | 96.17 | 96.66 |
| subtract | 95.09 | 96.11 | 95.36 | 93.95 | 95.92 |
| Condition | S1 | S2 | S3 | S4 | S5 |
|---|---|---|---|---|---|
| clamp | 92.39 | 92.69 | 92.63 | 92.55 | 92.57 |
| subtract | 92.00 | 91.32 | 92.06 | 92.36 | 91.62 |
| Difficulty | Condition | S1 | S2 | S3 | S4 | S5 |
|---|---|---|---|---|---|---|
| Medium | clamp | 28.71 | 21.05 | 36.37 | 23.89 | 23.92 |
| subtract | 22.01 | 30.19 | 28.50 | 21.22 | 28.02 | |
| Hard | clamp | 18.11 | 35.75 | 19.02 | 34.41 | 17.62 |
| subtract | 23.67 | 25.93 | 21.98 | 21.65 | 19.97 |
| Group | n | W | p-value |
|---|---|---|---|
| Clamp (standard margin) | 14 | 0.9513 | 0.5816 |
| Subtract (standard margin) | 14 | 0.9516 | 0.5853 |
| Clamp (low margin) | 14 | 0.9608 | 0.7355 |
| Subtract (low margin) | 7 | 0.9074 | 0.3780 |
Neural Network Training Dynamics
Neural network training dynamics studies how parameters and representations change during optimization and how those changes shape learning, stability, and generalization.
See all 511 papers