-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the Keras set_random_seed in tests #30504
Conversation
from transformers.pipelines import SUPPORTED_TASKS | ||
|
||
set_seed_fn = lambda: tf.random.set_seed(0) # noqa: E731 | ||
set_seed_fn = lambda: keras.utils.set_random_seed(0) # noqa: E731 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So tf.random.set_seed doesn't actually set the seed for the whole TF environment?
Does keras.utils.set_random_seed control just keras objects, or the whole TF env too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, keras.utils.set_random_seed()
basically setstf.random.set_seed()
as before, but also sets the Python and Numpy random seeds. It's the currently recommended approach for reproducible initialization in the Keras docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope there is no other tests having the same init issue but no failure by luck 🤞 .
(otherwise we might get different results for them after this PR 😅 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not surprised it's the recommended one in the keras docs ;)
OK, well I just we just shrug and put it in the list of other TF quirks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @Rocketknight1
(is this a API changes causing the problem?)
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing!
Some tests load checkpoints where weights are missing (e.g. the
pooler
weights forViT
). To get reproducible results, we need to ensure that seeds are set consistently. This PR useskeras.set_random_seed()
instead oftf.set_seed()
, which fixes some issues the CI was seeing where models mismatched because of differing weight inits.