Skip to content

Add Flux.2 segmented checkpointing support - #2941

Merged
bghira merged 2 commits into
agent/segmented-checkpointing-fluxfrom
agent/segmented-checkpointing-flux2
Aug 3, 2026
Merged

Add Flux.2 segmented checkpointing support#2941
bghira merged 2 commits into
agent/segmented-checkpointing-fluxfrom
agent/segmented-checkpointing-flux2

Conversation

@bghira

@bghira bghira commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Splits the Flux.2 segmented checkpointing support model integration out of #2925.

  • applies the model-family checkpointing hooks and support flags
  • adds this family to the relevant safety-check allow-lists
  • keeps the shared runtime/docs in the base PR so this diff stays model-specific

Stack

Base branch: agent/segmented-checkpointing-flux

Validation

  • .venv/bin/python -m unittest tests.test_segmented_checkpointing_model_support -v
  • commit hooks: Black, isort, flake8, whitespace checks

@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch from 7a70b79 to 0477572 Compare August 3, 2026 08:50
@bghira
bghira requested a review from Copilot August 3, 2026 08:53
@bghira
bghira marked this pull request as ready for review August 3, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Flux.2 model-family integration for the segmented gradient-checkpointing controls introduced in the stacked base branch, wiring Flux.2’s transformer forward pass into the shared checkpointing/offload infrastructure and ensuring the safety-check allow-lists recognize Flux.2.

Changes:

  • Add a Flux.2 model-support test ensuring required checkpointing control hooks/flags are present.
  • Extend safety-check allow-lists to permit Flux.2 usage of gradient-checkpointing interval/segment-stride and attention activation offload.
  • Implement Flux.2 transformer support for segmented checkpointing (interval + segment stride) and attention activation offload plumbing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_segmented_checkpointing_model_support.py Adds Flux.2 to the model-support coverage checks for segmented checkpointing controls.
simpletuner/helpers/training/default_settings/safety_check.py Allows Flux.2 in the relevant safety-check lists for checkpointing interval/stride and attention activation offload.
simpletuner/helpers/models/flux2/transformer.py Adds Flux.2 runtime support for segmented checkpointing and threads offload_attention through attention processors/blocks.
Suppressed comments (1)

simpletuner/helpers/models/flux2/transformer.py:439

  • Same as above for Flux2ParallelSelfAttnProcessor: the maybe_metal_flash_rope_attention(...) path executes outside activation_offload_context, so offload_attention=True won’t offload saved tensors when this backend is used. Wrap that call in activation_offload_context too.
                getattr(attn, "to_qkv_mlp_proj", None) and attn.to_qkv_mlp_proj.weight,
            )

        if hidden_states is None:
            with activation_offload_context(offload_attention, label=f"{attn.__class__.__qualname__}:attention"):

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 257 to +261
getattr(attn, "to_q", None) and attn.to_q.weight,
getattr(attn, "to_k", None) and getattr(attn, "to_k", None).weight,
)

if hidden_states is None and self._packed_attention_backend is not None and not cp_active:
hidden_states = _run_packed_qkv_attention(query, key, value, attention_mask, self._packed_attention_backend)
elif hidden_states is None:
hidden_states = dispatch_attention_fn(
query,
key,
value,
attn_mask=attention_mask,
backend=self._attention_backend,
parallel_config=parallel_config,
)
if hidden_states is None:
@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch 2 times, most recently from 61955d3 to 900af3a Compare August 3, 2026 09:49
@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch from 900af3a to 0b50f28 Compare August 3, 2026 10:45
@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch from 0b50f28 to 99a2506 Compare August 3, 2026 15:30
@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch from 99a2506 to 764620d Compare August 3, 2026 15:32
@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch from 764620d to d743b25 Compare August 3, 2026 15:33
@bghira
bghira force-pushed the agent/segmented-checkpointing-flux2 branch from d743b25 to 485b02d Compare August 3, 2026 15:35
@bghira
bghira merged commit 3504e55 into main Aug 3, 2026
4 checks passed
@bghira
bghira deleted the agent/segmented-checkpointing-flux2 branch August 3, 2026 15:37
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