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

tf.keras.mixed_precision.experimental.Policy #2005

Closed
ydshieh opened this issue Nov 30, 2019 · 1 comment
Closed

tf.keras.mixed_precision.experimental.Policy #2005

ydshieh opened this issue Nov 30, 2019 · 1 comment

Comments

@ydshieh
Copy link
Collaborator

ydshieh commented Nov 30, 2019

❓ Questions & Help

I want to use mixed_precision, and I found tf.keras.mixed_precision.experimental.Policy.

So I put tf.keras.mixed_precision.experimental.set_policy("mixed_float16") before TFBertModel.from_pretrained(pretrained_weights). When I run the code, I got the following error:

InvalidArgumentError: cannot compute AddV2 as input #1(zero-based) was expected to be a half tensor but is a float tensor [Op:AddV2] name: tf_bert_model_1/bert/embeddings/add/

which happened at ret = model(model.dummy_inputs, training=False) # build the network with dummy inputs.

I am not sure if I used it correctly. I think tf.keras.mixed_precision.experimental.set_policy is supposed to be used before constructing / build the model, as the tf page says Policies can be passed to the 'dtype' argument of layer constructors, or a global policy can be set with 'tf.keras.mixed_precision.experimental.set_policy'.

I wonder if I can use AMP with tf based transformer models and how. Thanks.

error.txt

@ydshieh ydshieh closed this as completed Nov 30, 2019
@ydshieh
Copy link
Collaborator Author

ydshieh commented Nov 30, 2019

Sorry, I created this duplicated issue as the previous one. Please delete this one, thank you.

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

No branches or pull requests

1 participant