Skip to content
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

Add a mixed precision test and fix mixed precision errors for layers #1242

Merged

Conversation

mattdangerw
Copy link
Member

No description provided.

@mattdangerw
Copy link
Member Author

/gcbrun

@mattdangerw
Copy link
Member Author

Ah I think this needs a keras-core release to pass. Will sync with Francois.

@mattdangerw mattdangerw force-pushed the mixed-precision-layer-fixes branch from 44b1005 to fc4f0f5 Compare September 14, 2023 19:29
)
intermediate_shape = list(decoder_sequence_shape)
intermediate_shape[-1] = self.intermediate_dim
self._feedforward_output_dense.build(tuple(intermediate_shape))
self._feedforward_layer_norm = keras.layers.LayerNormalization(
epsilon=self.layer_norm_epsilon,
name="output_layer_norm",
dtype=self.dtype_policy,
name="feedforward_layer_norm",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a random thought while I saw these

With the new distribution API, we're going to need to be careful about changing layer names moving forward!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Trying to get us in a nice consistent state before we do.

This will always be done in full precision, regardless of dtype, and
scale by `temperature`.
"""
dtype = logits.dtype
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe logits_dtype? (For consistency of style with inputs_dtype a few files up)

output_data = layer(input_data)
for tensor in tree.flatten(output_data):
dtype = standardize_dtype(tensor.dtype)
if "float" in dtype:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like assertDType should be good here no?

@mattdangerw mattdangerw force-pushed the mixed-precision-layer-fixes branch from 03c1c85 to 79c0219 Compare September 18, 2023 19:19
@jbischof
Copy link
Contributor

Is mixed precision working in Keras Core now?

@mattdangerw mattdangerw force-pushed the mixed-precision-layer-fixes branch from aefe4ed to 926a737 Compare September 19, 2023 02:43
@mattdangerw
Copy link
Member Author

Is mixed precision working in Keras Core now?

Yes, or at least it should be largely with the latest release. Landed the loss scaling optimizer, which was the main piece we were missing, as well as a few other fixes.

@mattdangerw
Copy link
Member Author

/gcbrun

5 similar comments
@mattdangerw
Copy link
Member Author

/gcbrun

@mattdangerw
Copy link
Member Author

/gcbrun

@mattdangerw
Copy link
Member Author

/gcbrun

@mattdangerw
Copy link
Member Author

/gcbrun

@mattdangerw
Copy link
Member Author

/gcbrun

@mattdangerw
Copy link
Member Author

Merging, last breakage unrelated #1251

@mattdangerw mattdangerw merged commit 5cf2c5e into keras-team:master Sep 21, 2023
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