Skip to content

feat: Add support for Safetensors format in caching strategies#2290

Draft
kohya-ss wants to merge 1 commit intosd3from
feat-safetensors-cache
Draft

feat: Add support for Safetensors format in caching strategies#2290
kohya-ss wants to merge 1 commit intosd3from
feat-safetensors-cache

Conversation

@kohya-ss
Copy link
Copy Markdown
Owner

  • Introduced Safetensors output format for various caching strategies including FLUX, Hunyuan, Lumina, SD, SDXL, and SD3.
  • Updated methods to handle loading and saving of tensors in Safetensors format.
  • Enhanced output validation to check for required tensors in both NPZ and Safetensors formats.
  • Modified dataset argument parser to include --cache_format option for selecting between NPZ and Safetensors formats.
  • Updated caching logic to accommodate partial loading and merging of existing Safetensors files.

- Introduced Safetensors output format for various caching strategies including Hunyuan, Lumina, SD, SDXL, and SD3.
- Updated methods to handle loading and saving of tensors in Safetensors format.
- Enhanced output validation to check for required tensors in both NPZ and Safetensors formats.
- Modified dataset argument parser to include `--cache_format` option for selecting between NPZ and Safetensors formats.
- Updated caching logic to accommodate partial loading and merging of existing Safetensors files.
@kohya-ss kohya-ss marked this pull request as draft March 22, 2026 12:21
duongve13112002 added a commit to duongve13112002/sd-scripts that referenced this pull request Apr 15, 2026
… support

Merges kohya-ss#2290 (safetensors cache format) and resolves
conflicts with multi-caption caching feature. Both features now work
together in all 6 model strategies:

- load_outputs_npz(): safetensors/npz branch + ndim-based multi-caption
  random selection applied after loading from either format
- cache_batch_outputs(): per-image loop (multi-caption) with
  safetensors/npz format branching for disk cache
- _save_outputs_safetensors(): per-image safetensors save with stacked
  arrays support for multi-caption

Affected strategies: Lumina, Flux, Anima, SDXL, SD3, HunyuanImage
Also includes PR kohya-ss#2290 changes to strategy_base.py, strategy_sd.py,
train_util.py, and tools/*.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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