Skip to content

Sync the model state before callbacks read it - #60

Merged
hertschuh merged 5 commits into
mainfrom
state-sync
Oct 8, 2026
Merged

hertschuh merged 5 commits into
mainfrom
state-sync

Conversation

@MarcosAsh

Copy link
Copy Markdown
Collaborator

Implements the _backend_state_sync hook from keras#23620 so that callbacks reading model state in the middle of an epoch get the current weights instead of the stale ones. Three lines in the trainer, it just calls mlx_state_sync.

Retires the seven exclusions that were there for this: callback state on epoch end, callbacks updating state at a batch boundary, backup and restore, model checkpoint options and the three orbax tests. All seven pass with the keras hook and fail without it. Needs keras#23620 first.

@MarcosAsh
MarcosAsh marked this pull request as draft September 16, 2026 18:53
Comment thread keras_mlx/src/trainer.py Resolved
@MarcosAsh
MarcosAsh requested a review from hertschuh September 26, 2026 16:44
@hertschuh

Copy link
Copy Markdown
Contributor

Do you understand why the tests are failing?

@MarcosAsh

Copy link
Copy Markdown
Collaborator Author

Yes. CI checks out keras pluggable_backend, and #23620 only landed on master, so the callback there never calls the plugin's state_sync. The rest of the red is the branch being behind main. It stays a draft until the repoint to master.

@MarcosAsh
MarcosAsh marked this pull request as ready for review October 7, 2026 11:25
@hertschuh

Copy link
Copy Markdown
Contributor

Do you understand the weird failure on this one? Is the Linux image corrupted?

@MarcosAsh

Copy link
Copy Markdown
Collaborator Author

not the image, it's an mlx compile cache race between the xdist workers. fixed in ml-explore/mlx#4638 but not released yet, #90 works around it

@hertschuh hertschuh 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.

Thanks!

@hertschuh
hertschuh merged commit ddc3a2a into main Oct 8, 2026
9 of 10 checks passed
@hertschuh
hertschuh deleted the state-sync branch October 8, 2026 19:26
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