Skip to content

materialize() / evict() API#1617

Open
dxqb wants to merge 2 commits into
Nerogar:masterfrom
dxqb:materialize-evict-api
Open

materialize() / evict() API#1617
dxqb wants to merge 2 commits into
Nerogar:masterfrom
dxqb:materialize-evict-api

Conversation

@dxqb

@dxqb dxqb commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

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

Doesn't do anything except refactor, but it's the basis to implement future functionality without duplicating it for each model

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: ____)

AI assistance

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

…()/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>
Comment thread modules/dataLoader/ChromaBaseDataLoader.py Outdated
@dxqb dxqb mentioned this pull request Jul 15, 2026
2 tasks
@dxqb dxqb added the preview merged in the preview branch label Jul 22, 2026
@dxqb dxqb mentioned this pull request Jul 23, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview merged in the preview branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant