Centralize setup optimizations#1623
Open
dxqb wants to merge 3 commits into
Open
Conversation
…()/evict() API
Replaces the per-model `{part}_to(device)` methods across all model classes,
plus scattered call sites in dataLoader/modelSetup/modelSampler/GenericTrainer,
with generic BaseModel methods driven by the existing ModelType.model_parts()
registry: materialize(*parts), evict(*parts), and materialize_only(*parts)
(evict everything else, then materialize the given parts - the swap-in/swap-out
pattern used throughout the Samplers and text-caching setup). eval() and
adapters() are likewise made concrete on BaseModel instead of hand-written per
model. Models whose component names diverge (Wuerstchen) or that have
components outside model_parts() (SD's depth_estimator, Anima's
text_conditioner) override the relevant methods directly.
Also fixes multi-TE samplers (Flux/SD3/SDXL/HiDream/HunyuanVideo) that
previously evicted all but the first text encoder and ran encode_text with
the rest still on temp_device.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…elper into BaseModelSetup
hameerabbasi
suggested changes
Jul 16, 2026
hameerabbasi
left a comment
Contributor
There was a problem hiding this comment.
Bunch of torch_gcs removed. They should be in evict and/or materialize.
| model.text_encoder_to(self.train_device) | ||
| model.materialize_only("text_encoder") | ||
| model.eval() | ||
| torch_gc() |
Contributor
There was a problem hiding this comment.
Careful here, do the materialise functions have GC built-in?
Collaborator
Author
There was a problem hiding this comment.
the meaning of materialize_only() is evict everything except this
evict() contains torch_gc()
note that this is introduced by #1617 not here
unfortunately github doesn't have an easy feature to only show the changes of PR B when it builds on top of PR A
Collaborator
Author
There was a problem hiding this comment.
here is the commit that is this PR 5f2caab
hameerabbasi
approved these changes
Jul 16, 2026
hameerabbasi
left a comment
Contributor
There was a problem hiding this comment.
Thanks; the once concern I had is resolved.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is another refactor PR that does not change any behaviour, but is necessary to implement future PRs without having to copy their wiring code across all ~ 15 models
Contains #1617
Test plan
pre-commit run --all-filespassesAI assistance