Skip to content

Fix loading of palettizer state dict with no indices into prepared model - #147

Merged
crowbat merged 1 commit into
apple:mainfrom
crowbat:u/k_hsieh/fix_palettizer_loading_sd_centroids_only
Oct 27, 2026
Merged

crowbat merged 1 commit into
apple:mainfrom
crowbat:u/k_hsieh/fix_palettizer_loading_sd_centroids_only

Conversation

@crowbat

@crowbat crowbat commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

In existing code, there is logic to handle loading a KMeansPalettizer state dict with no indices (which would occur when the indices were stale at the time of saving out the state dict).

Existing unit tests only tested loading of this state dict into 1) a bare uninitialized KMeansPalettizer standalone module, or 2) via prepare()'s dedicated state_dict path which skips module initialization when preparing.

However, when loading the state dict into a prepared model with some indices already, I ran into an error due to strict mode flagging the state dict as missing a key. This PR updates the load_from_state_dict override to allow strict loading to succeed. When indices are missing, the indices_stale flag is still marked as True, so new indices would be recomputed at the next forward pass.

@crowbat
crowbat merged commit 8983cac into apple:main Oct 27, 2026
14 checks passed
@crowbat
crowbat deleted the u/k_hsieh/fix_palettizer_loading_sd_centroids_only branch October 27, 2026 22:20
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.

3 participants