tf.keras.mixed_precision.set_global_policy
Stay organized with collections
Save and categorize content based on your preferences.
Sets the global dtype policy.
tf.keras.mixed_precision.set_global_policy(
policy
)
The global policy is the default tf.keras.mixed_precision.Policy
used for
layers, if no policy is passed to the layer constructor.
tf.keras.mixed_precision.set_global_policy('mixed_float16')
tf.keras.mixed_precision.global_policy()
<Policy "mixed_float16">
tf.keras.layers.Dense(10).dtype_policy
<Policy "mixed_float16">
# Global policy is not used if a policy
# is directly passed to constructor
tf.keras.layers.Dense(10, dtype='float64').dtype_policy
<Policy "float64">
tf.keras.mixed_precision.set_global_policy('float32')
If no global policy is set, layers will instead default to a Policy
constructed from tf.keras.backend.floatx()
.
To use mixed precision, the global policy should be set to 'mixed_float16'
or 'mixed_bfloat16'
, so that every layer uses a 16-bit compute dtype and
float32 variable dtype by default.
Only floating point policies can be set as the global policy, such as
'float32'
and 'mixed_float16'
. Non-floating point policies such as
'int32'
and 'complex64'
cannot be set as the global policy because most
layers do not support such policies.
See tf.keras.mixed_precision.Policy
for more information.
Args |
policy
|
A Policy, or a string that will be converted to a Policy. Can also
be None, in which case the global policy will be constructed from
tf.keras.backend.floatx()
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.keras.mixed_precision.set_global_policy\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/mixed_precision/policy.py#L383-L446) |\n\nSets the global dtype policy. \n\n tf.keras.mixed_precision.set_global_policy(\n policy\n )\n\nThe global policy is the default [`tf.keras.mixed_precision.Policy`](../../../tf/keras/mixed_precision/Policy) used for\nlayers, if no policy is passed to the layer constructor. \n\n tf.keras.mixed_precision.set_global_policy('mixed_float16')\n tf.keras.mixed_precision.global_policy()\n \u003cPolicy \"mixed_float16\"\u003e\n tf.keras.layers.Dense(10).dtype_policy\n \u003cPolicy \"mixed_float16\"\u003e\n # Global policy is not used if a policy\n # is directly passed to constructor\n tf.keras.layers.Dense(10, dtype='float64').dtype_policy\n \u003cPolicy \"float64\"\u003e\n tf.keras.mixed_precision.set_global_policy('float32')\n\nIf no global policy is set, layers will instead default to a Policy\nconstructed from [`tf.keras.backend.floatx()`](../../../tf/keras/backend/floatx).\n\nTo use mixed precision, the global policy should be set to `'mixed_float16'`\nor `'mixed_bfloat16'`, so that every layer uses a 16-bit compute dtype and\nfloat32 variable dtype by default.\n\nOnly floating point policies can be set as the global policy, such as\n`'float32'` and `'mixed_float16'`. Non-floating point policies such as\n`'int32'` and `'complex64'` cannot be set as the global policy because most\nlayers do not support such policies.\n\nSee [`tf.keras.mixed_precision.Policy`](../../../tf/keras/mixed_precision/Policy) for more information.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `policy` | A Policy, or a string that will be converted to a Policy. Can also be None, in which case the global policy will be constructed from [`tf.keras.backend.floatx()`](../../../tf/keras/backend/floatx) |\n\n\u003cbr /\u003e"]]