Skip to content

Add Subseed/Variation Seed System for Enhanced Generation Control#994

Open
Gunther-Schulz wants to merge 81 commits intodeepbeepmeep:mainfrom
Gunther-Schulz:seedvariations
Open

Add Subseed/Variation Seed System for Enhanced Generation Control#994
Gunther-Schulz wants to merge 81 commits intodeepbeepmeep:mainfrom
Gunther-Schulz:seedvariations

Conversation

@Gunther-Schulz
Copy link

@Gunther-Schulz Gunther-Schulz commented Oct 2, 2025

All code is AI generated.

I use this a lot in Forge and it is invaluable for me for image generation. I basically copied the functionality.

Overview

This PR introduces a comprehensive subseed (variation seed) system that enables fine-grained control over generation variations while maintaining reproducibility.

Features Added

1. Subseed/Variation Seed UI

  • Extra Seed Options checkbox to reveal subseed controls
  • Variation Seed slider (-1 for random, or fixed value)
  • Variation Strength slider (0.0-1.0) to control interpolation
  • Dedicated dice (🎲) and reuse (♻️) buttons for subseed
  • Clean UI layout integrated with existing seed controls

2. Independent Subseed Randomization

  • Subseed generates independently from main seed
  • Each generation with subseed=-1 gets a truly random value
  • Fixed critical bug where subseed was deterministic based on main seed
  • Proper ordering: subseed randomization happens BEFORE set_seed() call

3. Comprehensive Metadata System

  • Saves both subseed=-1 (randomization flag) and subseed_used (actual value)
  • Only saves subseed data when subseed_strength > 0
  • Video info panel shows actual subseed value used
  • Prevents showing variation info when not applicable

4. Full Reproducibility

  • Loading settings from video/image files restores the actual subseed used
  • Enables exact reproduction of any generated content
  • Auto-checks Extra checkbox when loading files with subseed data
  • Works for both drag-and-drop and explicit settings load

5. Centralized Seed Management Module

  • Created shared/utils/seed_management.py for all seed operations
  • Consolidated duplicate seed logic from multiple files
  • Functions: set_seed(), initialize_subseed(), regenerate_subseed()
  • PyTorch generator helpers: create_generator(), create_subseed_generator()
  • Variation application: apply_subseed_variation()

Technical Implementation

Subseed Variation Algorithm

latents = main_latents * (1.0 - subseed_strength) + sub_latents * subseed_strength
  • Linear interpolation between main and variation noise
  • subseed_strength=0.0: no variation (pure main seed)
  • subseed_strength=1.0: full variation (pure subseed)
  • subseed_strength=0.1-0.3: subtle variations (recommended range)

Files Modified

  • Wan2GP/wgp.py: UI, metadata handling, subseed integration
  • Wan2GP/models/wan/any2video.py: PyTorch generator creation and latent variation
  • Wan2GP/shared/radial_attention/utils.py: Import centralized set_seed
  • Wan2GP/shared/utils/seed_management.py: New centralized module

Use Cases

  1. Exploration: Set subseed=-1, strength=0.15 to explore variations around a good generation
  2. Reproducibility: Load settings from saved video to recreate exact output
  3. Animation: Interpolate between seeds by varying subseed_strength
  4. Fine-tuning: Fix main seed, vary subseed to find optimal result

Testing

  • ✅ Subseed randomizes independently for each generation
  • ✅ Metadata correctly saves and displays subseed values
  • ✅ Settings load from videos enables exact reproduction
  • ✅ Queue processing preserves subseed independence
  • ✅ Extra checkbox auto-checks when appropriate
  • ✅ Works with repeat generation feature

Compatibility

  • Fully backward compatible with existing generations
  • No breaking changes to existing APIs or workflows
  • Subseed is optional (defaults to disabled)

Architecture Improvements

  • Reduced code duplication by centralizing seed management
  • Improved maintainability with dedicated seed module
  • Better separation of concerns (UI, logic, metadata)
  • Consistent seed handling across all generation paths

deepbeepmeep and others added 22 commits September 27, 2025 16:30
- Implement LCMScheduler with RectifiedFlow (LTX) dynamics
- Combine Latent Consistency Model with rectified flow scheduling
- Optimize for 2-8 step ultra-fast inference with Lightning LoRAs
- Add proper flow matching dynamics with shift parameter support
- Update UI to show 'lcm + ltx' option in sampler dropdown
- Add subseed and subseed_strength parameters to any2video.py generation
- Implement noise mixing algorithm (blend main seed and subseed based on strength)
- Add UI controls: Extra checkbox reveals subseed slider and strength slider
- Add random (🎲) and reuse (♻️) buttons for both seed and subseed
- Auto-randomize subseed when set to -1 (like main seed)
- Full metadata support: save/load subseed parameters
- Display variation seed info in video info panel when used
- Works with all Wan models (2.2, i2v, t2v, etc.)

This feature allows users to create controlled variations of a generation
by mixing noise from two seeds, useful for exploring variations while
maintaining overall structure and composition.
- Move 'Extra' checkbox to its own row below seed controls for cleaner layout
- Fix subseed randomization to only occur when subseed_strength > 0
- Fix subseed to regenerate for each repeat generation when set to -1 (like main seed)
- Prevent unnecessary subseed randomization when variation strength is 0
Extract all seed and subseed management logic from scattered locations into a
new shared/utils/seed_management.py module for better maintainability and reusability.

New module (shared/utils/seed_management.py):
- set_seed(): Unified seed setting for Python, NumPy, PyTorch
- initialize_subseed(): Handle initial subseed randomization
- regenerate_subseed(): Generate new subseed for repeat generations
- create_generator(): Create PyTorch Generator with seed
- create_subseed_generator(): Create subseed Generator conditionally
- apply_subseed_variation(): Apply subseed variation to latents

Changes:
- Eliminated duplicate set_seed() implementations (was in 2 files)
- Consolidated subseed randomization logic (was scattered)
- Unified Generator creation pattern
- Reduced wgp.py by ~8 lines of seed logic
- Reduced any2video.py by ~6 lines
- Reduced radial_attention/utils.py by ~15 lines
- Added comprehensive docstrings for all functions
- Improved testability and reusability

Benefits:
- Single source of truth for seed management
- Testable individual functions
- Reusable across all models
- Clear separation of concerns (UI vs business logic)
- Follows existing refactoring pattern (like source_image_embedding.py)
UI improvements:
- Group seed controls (slider, buttons, Extra checkbox) in visual container
- Extra checkbox now visually part of Seed section with gr.Group()
- Renamed to 'Extra Seed Options' for clarity
- Buttons remain on same row as seed slider

Bug fix:
- Fix subseed not randomizing between queued tasks
- Changed params = task['params'] to params = task['params'].copy()
- Prevents param pollution when multiple tasks share same params dict
- Now each queued task gets fresh subseed randomization

This fixes the issue where variation seed would use same value across
all queued generations even when set to -1 (random)
…ucibility

This commit addresses all subseed-related issues with a comprehensive solution:

1. **Independent subseed randomization**
   - Subseed now generates BEFORE set_seed() to ensure independence from main seed
   - Each generation gets truly random subseed when set to -1
   - Fixed deterministic subseed bug caused by random module seeding

2. **Metadata handling**
   - Saves both subseed=-1 (for randomization behavior) and subseed_used (actual value)
   - Only saves subseed_used when subseed_strength > 0 (variation actually applied)
   - Prevents showing variation info when checkbox unchecked/strength=0

3. **Reproducibility**
   - When loading from video/image file, uses subseed_used (actual value) not -1
   - Allows exact reproduction of generated content
   - Applied to both use_video_settings and get_settings_from_file paths

4. **UI consistency**
   - Extra checkbox auto-checks only when subseed_strength > 0
   - Display shows actual used subseed value (not 'random')
   - Simplified checkbox condition to match actual usage

All subseed workflows now work correctly:
✓ Random subseed generates unique values each time
✓ Metadata displays actual used values
✓ Loading from file enables exact reproduction
✓ Checkbox only appears when variation was used
@Gunther-Schulz Gunther-Schulz marked this pull request as draft October 2, 2025 19:12
Critical bug fix:
- Unchecking Extra checkbox now sets subseed_strength to 0.0
- This ensures no variation is applied when checkbox is unchecked
- Previously, subseed was still being applied even with checkbox unchecked

The checkbox now properly controls subseed behavior:
- Checked: subseed_strength retains its value, variation applied
- Unchecked: subseed_strength reset to 0, no variation applied
@Gunther-Schulz Gunther-Schulz marked this pull request as ready for review October 2, 2025 19:19
@Gunther-Schulz Gunther-Schulz marked this pull request as draft October 2, 2025 23:17
@Gunther-Schulz Gunther-Schulz marked this pull request as ready for review October 2, 2025 23:34
@Gunther-Schulz Gunther-Schulz marked this pull request as draft October 2, 2025 23:49
@Gunther-Schulz Gunther-Schulz marked this pull request as ready for review October 2, 2025 23:53
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.

4 participants