Skip to content

Commit

Permalink
refactor: Added an extra condition to avoid unneccesary ivy.astype ca…
Browse files Browse the repository at this point in the history
…ll in ivy.dropout's backends
  • Loading branch information
AnnaTz committed Nov 8, 2023
1 parent 2d95392 commit 567093e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ivy/functional/backends/tensorflow/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def dropout(
noise_shape: Optional[Sequence[int]] = None,
out: Optional[Union[tf.Tensor, tf.Variable]] = None,
) -> Union[tf.Tensor, tf.Variable]:
x = ivy.astype(x, dtype) if dtype else x
x = ivy.astype(x, dtype) if dtype and x.dtype != dtype else x
res = tf.nn.dropout(x, prob, noise_shape=noise_shape, seed=seed) if training else x
res = res if scale else tf.multiply(res, (1.0 - prob))
return res
Expand Down
2 changes: 1 addition & 1 deletion ivy/functional/backends/torch/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def dropout(
noise_shape: Optional[Sequence[int]] = None,
out: Optional[torch.Tensor] = None,
) -> torch.Tensor:
x = ivy.astype(x, dtype) if dtype else x
x = ivy.astype(x, dtype) if dtype and x.dtype != dtype else x
res = torch.nn.functional.dropout(x, prob, training=training)
res = res if scale else torch.multiply(res, (1.0 - prob))
return res
Expand Down

0 comments on commit 567093e

Please sign in to comment.