Skip to content

Fix full-finetune save crash when checkpointing + layer offloading are enabled + diffusers output format - #1574

Merged
dxqb merged 2 commits into
Nerogar:mergefrom
dxqb:fix-offload-deepcopy-save
Jul 4, 2026
Merged

Fix full-finetune save crash when checkpointing + layer offloading are enabled + diffusers output format#1574
dxqb merged 2 commits into
Nerogar:mergefrom
dxqb:fix-offload-deepcopy-save

Conversation

@dxqb

@dxqb dxqb commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • full finetunes create a deepcopy of the entire model before saving, so they can modify the output dtype
  • this is an issue with offloading because it attempts to copy OffloadingCheckpointerLayers which refer to an OffloadConductor - cannot be copied
  • prevent that

Test plan

  • pre-commit run --all-files passes
  • Launched the affected UI or script and exercised the change
  • Tested with at least one real preset / config when relevant (note which: Krea2)

AI assistance

  • AI-assisted — I have read every line in this diff and can defend each change

dxqb and others added 2 commits July 3, 2026 18:17
…e enabled

copy.deepcopy(pipeline) in DtypeModelSaverMixin._copy_pipeline_to_dtype
reaches the shared LayerOffloadConductor via the checkpoint layers, and the
conductor holds torch.cuda.Stream/Event objects that cannot be pickled,
raising "TypeError: cannot pickle 'Stream' object".

Give LayerOffloadConductor a __deepcopy__ that shares the existing instance
instead of copying it. deepcopy is only used at save time to build a
dtype-converted CPU copy of the pipeline, where the conductor is never
invoked, so sharing it is safe.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
LayerOffloadConductor has no reason to know about save-time deepcopy
semantics. The actual problem is that OffloadCheckpointLayer holds a
reference into the conductor (directly as a submodule attribute in the
compile path, or via the layer's bound forward method monkey-patched onto
the wrapped module in the non-compile path), so it is the layer, not the
conductor, that should own the "don't deepcopy the conductor" behavior.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dxqb
dxqb changed the base branch from master to merge July 4, 2026 03:47
@dxqb dxqb changed the title Fix full-finetune save crash when checkpointing + layer offloading are enabled Fix full-finetune save crash when checkpointing + layer offloading are enabled + diffusers output format Jul 4, 2026
@dxqb
dxqb merged commit 41ee4da into Nerogar:merge Jul 4, 2026
1 check passed
@dxqb
dxqb deleted the fix-offload-deepcopy-save branch July 4, 2026 04:02
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.

1 participant