Skip to content

fix KeyError in VAE cache disabling - #2997

Merged
bghira merged 1 commit into
mainfrom
bugfix/vae-keyerror
Aug 4, 2026
Merged

fix KeyError in VAE cache disabling#2997
bghira merged 1 commit into
mainfrom
bugfix/vae-keyerror

Conversation

@bghira

@bghira bghira commented Aug 4, 2026

Copy link
Copy Markdown
Owner

This pull request refactors how VAE cache configuration is normalized and accessed throughout the codebase, ensuring consistent handling of related config flags and improving test coverage for edge cases. The main changes introduce a helper function to centralize normalization logic, update all relevant usages, and enhance test cases to cover missing config keys.

VAE Cache Configuration Normalization:

  • Added a new helper function _normalise_vae_cache_config in factory.py to consistently interpret and update the vae_cache_disable and vae_cache_ondemand flags, ensuring that disabling the cache implies on-demand mode.
  • Updated usages in _configure_vae_cache and _count_entries to use the new normalization function instead of directly accessing the config dictionary. [1] [2]

Test Improvements:

  • Enhanced test_dataset_vae_cache_modes_use_dataset_ondemand_mode to include cases with missing config keys, ensuring robust behavior when certain flags are absent. [1] [2]

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 addresses a KeyError risk around VAE cache configuration by centralizing normalization of vae_cache_disable / vae_cache_ondemand flags in the data backend factory, and extends edge-case tests to cover scenarios where config keys are absent.

Changes:

  • Add _normalise_vae_cache_config to coerce optional VAE cache flags and enforce “disable implies on-demand”.
  • Update factory logic to use the normalization helper instead of direct config indexing when configuring/counting cache behavior.
  • Expand the edge-case test matrix to include scenarios with missing VAE cache config keys.

Reviewed changes

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

File Description
simpletuner/helpers/data_backend/factory.py Adds and applies a VAE cache config normalization helper to avoid missing-key access and keep flag semantics consistent.
tests/test_factory_edge_cases.py Extends the VAE cache mode tests to exercise behavior when specific config keys are removed.

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

Comment on lines +268 to +269
for key in missing_config_keys:
init_backend["config"].pop(key)
@bghira
bghira merged commit eb70ba3 into main Aug 4, 2026
3 checks passed
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