Skip to content

fix: add missing style_encoder optimizer step in reference-guided training#181

Open
Mukller wants to merge 1 commit into
clovaai:masterfrom
Mukller:fix/style-encoder-optimizer-step
Open

fix: add missing style_encoder optimizer step in reference-guided training#181
Mukller wants to merge 1 commit into
clovaai:masterfrom
Mukller:fix/style-encoder-optimizer-step

Conversation

@Mukller

@Mukller Mukller commented Jul 9, 2026

Copy link
Copy Markdown

Bug Fix: Style encoder not updated during reference-guided generator training

During the training loop, the style encoder optimizer step is called after
latent-guided generator training but is missing from reference-guided training.

This means the style encoder never learns from reference images during the
alternating training procedure, which contradicts the StarGAN v2 training algorithm.

Before (missing style_encoder.step for ref-guided training):

# Latent-guided:
optims.generator.step()
optims.mapping_network.step()
optims.style_encoder.step()    # ← present

# Reference-guided:
optims.generator.step()
# optims.style_encoder.step() ← MISSING

After (fixed):

# Reference-guided:
optims.generator.step()
optims.style_encoder.step()    # ← added

Closes #179

@Mukller Mukller left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Code Review: fix missing style_encoder optimizer step in reference-guided training

Summary

Adds the missing optims.style_encoder.step() call in the reference-guided training branch. Without it, the style encoder's parameters would not be updated during gradient descent, causing the style encoder to remain frozen while the generator trains against it — leading to suboptimal style transfer quality and silent incorrect behavior.

Critical Issues

# File Line Issue Severity
1 core/solver.py ~135 optims.style_encoder.step() was missing after g_loss.backward(), leaving the style encoder's weights frozen during reference-guided training 🔴 Critical

What the Fix Does

# Before (bug) — style encoder never updated
self._reset_grad()
g_loss.backward()
optims.generator.step()
# ← style encoder step missing

# After (correct)
self._reset_grad()
g_loss.backward()
optims.generator.step()
optims.style_encoder.step()  # ← style encoder now correctly updated

What Looks Good

  • Single-line addition, no side effects
  • Consistent with the latent-guided training path, which correctly updates both generator and mapping network

Verdict

Request Changes → now fixed. This is a silent training bug: no crash, no obvious error, but the style encoder would not learn during reference-guided training, producing degraded results.

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.

Style Encoder Not Updated & Generator Gradients Leak During Discriminator Training

1 participant