Skip to content

Fix CFG denoising: use unconditional sample for unconditional branch#387

Open
hobostay wants to merge 1 commit into
microsoft:mainfrom
hobostay:fix/cfg-denoising-unconditional
Open

Fix CFG denoising: use unconditional sample for unconditional branch#387
hobostay wants to merge 1 commit into
microsoft:mainfrom
hobostay:fix/cfg-denoising-unconditional

Conversation

@hobostay

@hobostay hobostay commented May 4, 2026

Copy link
Copy Markdown

Summary

  • Fix Classifier-Free Guidance (CFG) denoising in sample_speech_tokens to use the actual unconditional sample instead of duplicating the conditional sample
  • The unconditional half of the speech tensor was being replaced with a copy of the conditional half before prediction, making CFG mathematically incorrect

Details

Affected file: vibevoice/modular/modeling_vibevoice_streaming_inference.py (lines 887-899)

The original code:

half = speech[: len(speech) // 2]
combined = torch.cat([half, half], dim=0)  # ← duplicates conditional half

The fix:

half = speech[: len(speech) // 2]
other_half = speech[len(speech) // 2:]
combined = torch.cat([half, other_half], dim=0)  # ← uses both halves

In standard CFG, the model receives both the conditional sample (with the conditioning) and the unconditional sample (without). By duplicating the conditional half for both inputs, the unconditional noise prediction was computed from the wrong sample, producing incorrect CFG scaling. Only the conditional half is returned as output, but the unconditional branch still needs proper evolution through the denoising steps for CFG to work correctly.

Test plan

  • Run streaming TTS inference with cfg_scale > 1.0 and verify output quality
  • Compare output quality before and after the fix with the same seed

🤖 Generated with Claude Code

In sample_speech_tokens, the unconditional half of the speech tensor
was being replaced with a copy of the conditional half before being
passed to the prediction head. This means the unconditional noise
prediction was computed from the conditional sample, not the actual
unconditional sample, making CFG mathematically incorrect.

Use the actual unconditional sample (other_half) in the combined
input to the prediction head so that both conditional and
unconditional predictions use their respective samples.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@rickthomasjr rickthomasjr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: Approve — fix CFG denoising unconditional branch

Correctness: In classifier-free guidance, the unconditional branch should use a null/unconditional prompt, not duplicate the conditional prompt. Using the conditional input for the unconditional branch defeats CFG and produces degraded generation quality.

Verdict: Approve. Corrects a fundamental CFG implementation issue.

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.

2 participants