Skip to content

Commit

Permalink
Fix StochasticDepth layer error in training mixed_float16 (#2450)
Browse files Browse the repository at this point in the history
* Update stochastic_depth_test.py

* Update stochastic_depth.py

* Update stochastic_depth.py

* Update stochastic_depth.py
  • Loading branch information
leondgarse authored Jul 27, 2021
1 parent 3e87219 commit e9846e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tensorflow_addons/layers/stochastic_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def call(self, x, training=None):
shortcut, residual = x

# Random bernoulli variable indicating whether the branch should be kept or not or not
b_l = tf.keras.backend.random_bernoulli([], p=self.survival_probability)
b_l = tf.keras.backend.random_bernoulli(
[], p=self.survival_probability, dtype=self._compute_dtype_object
)

def _call_train():
return shortcut + b_l * residual
Expand Down
2 changes: 2 additions & 0 deletions tensorflow_addons/layers/tests/stochastic_depth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def test_with_mixed_precision_policy():
residual = np.asarray([[0.2, 0.4, 0.5]])

output = StochasticDepth()([shortcut, residual])
assert output.dtype == policy.compute_dtype

output = StochasticDepth()([shortcut, residual], training=True)
assert output.dtype == policy.compute_dtype


Expand Down

0 comments on commit e9846e8

Please sign in to comment.