MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / keep_weights

Method keep_weights

tensorflow/python/ops/variable_scope.py:3008–3030  ·  view source on GitHub ↗

Scope class for bfloat16 variables so that the model uses custom getter. This enables variables to be read as bfloat16 type when using get_variable. ```python import tensorflow as tf from tensorflow.contrib import layers with tf.variable_scope(...).keep_weights(dtype=tf.float3

(self, dtype=dtypes.float32)

Source from the content-addressed store, hash-verified

3006 return inner_custom_getter
3007
3008 def keep_weights(self, dtype=dtypes.float32):
3009 """Scope class for bfloat16 variables so that the model uses custom getter.
3010
3011 This enables variables to be read as bfloat16 type when using get_variable.
3012
3013 ```python
3014 import tensorflow as tf
3015 from tensorflow.contrib import layers
3016
3017 with tf.variable_scope(...).keep_weights(dtype=tf.float32):
3018 data_bf16 = tf.cast(data, dtype=tf.bfloat16)
3019
3020 matmul_0 = tf.layers.dense(data_bf16, 64, activation=tf.nn.relu)
3021 matmul_0 = tf.layers.batch_normalization(matmul_0, training=True)
3022 matmul_0 = tf.cast(matmul_0, dtype=tf.float32)
3023
3024 matmul_1 = layers.fully_connected(data_bf16, 128,
3025 activation_fn=tf.nn.leaky_relu)
3026 matmul_1 = tf.cast(matmul_1, dtype=tf.float32)
3027 ```
3028 """
3029 self._custom_getter = self._get_custom_getter(dtype=dtype)
3030 return self
3031
3032 def __enter__(self):
3033 # If the default graph is building a function, then we should not replace it

Callers 15

_create_modelMethod · 0.80
_make_scopeMethod · 0.80
_create_modelMethod · 0.80
_create_modelMethod · 0.80
_create_modelMethod · 0.80
_create_modelMethod · 0.80
_create_modelMethod · 0.80
_create_modelMethod · 0.80
_make_scopeMethod · 0.80
_create_modelMethod · 0.80
build_fcn_net_bf16Method · 0.80
__init__Method · 0.80

Calls 1

_get_custom_getterMethod · 0.95

Tested by

no test coverage detected