Files
EnragedAntelope-ComfyUI_Eas…/js
Claude c6a0d6a49e FEATURE: Implement proper attention masking + update defaults
This commit implements proper cross-attention masking for Flux/DiT models
to ensure regions appear exactly where users place them, and updates
defaults to match the user's workflow for easier testing.

## Attention Masking Implementation

**Problem:** Simple spatial masks don't provide enough control for Flux
to generate content in the exact regions specified by users.

**Solution:** Implemented full cross-attention masking that controls:
1. Text-to-image attention (which image tokens text attends to)
2. Image-to-text attention (which text tokens images attend from)
3. Image-to-image attention (which image tokens attend to each other)

**Technical Details:**
- Format: [batch, (txt_tokens + h*w), (txt_tokens + h*w)]
- Uses -10000.0 as practical -inf to block unwanted attention
- Enables 0.0 for allowed attention paths
- Only tokens within a region can interact with that region's text prompt
- Prevents "bird center-frame" when region is upper-right corner

**Reference:**
Based on ComfyUI PR #5942 and research into ComfyUI-FluxRegionAttention,
RES4LYF, and other working implementations.

## Default Values Update

Updated to match user's 1344x768 Flux workflow:
- Width: 1344, Height: 768 (was 1024x1024)
- Region 1: "red sports car" at [0, 320, 368, 462]
- Region 2: "closeup full body giraffe wearing sunglasses" at [448, 64, 384, 704]
- Region 3: "blue bird flying" at [945, 0, 378, 256]
- Background: "photo of empty city street at night, high quality"

## Files Changed

- RegionalPrompting.py: Attention mask implementation + default prompts/regions
- RegionalPrompting.js: Updated JavaScript defaults to match

## Testing Needed

Test with Flux model to verify:
1. Regions appear in correct locations (no more center-drift)
2. No einops errors or shape mismatches
3. Quality improvement over simple mask approach

## References

- ComfyUI PR #5942: https://github.com/comfyanonymous/ComfyUI/pull/5942
- ComfyUI model_base.py extra_conds method
- ComfyUI utils.py upscale_dit_mask function
- ComfyUI-FluxRegionAttention: https://github.com/attashe/ComfyUI-FluxRegionAttention
2025-11-23 03:38:02 +00:00
..