Skip to content

Commit

Permalink
auto-lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
ivy-dev-bot committed Sep 8, 2024
1 parent 372006e commit bd31086
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
12 changes: 7 additions & 5 deletions ivy/functional/backends/jax/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ def stop_gradient(
) -> JaxArray:
return jlax.stop_gradient(x)


def requires_gradient(
x: JaxArray,
) -> bool:
if isinstance(x, jax.core.Tracer):
# JAX tracers indicate whether a value is being traced for gradients
return True
return False
) -> bool:
if isinstance(x, jax.core.Tracer):
# JAX tracers indicate whether a value is being traced for gradients
return True
return False


def jac(func: Callable):
def grad_fn(x_in):
Expand Down
5 changes: 4 additions & 1 deletion ivy/functional/backends/numpy/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ def is_variable(x, /, *, exclusive=False):
return False


def requires_gradient(x,) -> bool:
def requires_gradient(
x,
) -> bool:
return False


def variable_data(x, /):
return x

Expand Down
3 changes: 2 additions & 1 deletion ivy/functional/backends/tensorflow/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ def stop_gradient(
return variable(x)
return x


def requires_gradient(
x: Union[tf.Tensor, tf.Variable],
) -> bool:
) -> bool:
is_var = is_variable(x)
if is_var:
return x.trainable
Expand Down
3 changes: 2 additions & 1 deletion ivy/functional/backends/torch/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ def stop_gradient(
return x
return x.detach()


def requires_gradient(
x: Optional[torch.Tensor],
) -> bool:
) -> bool:
is_var = is_variable(x)
if is_var:
return x.requires_grad
Expand Down
3 changes: 2 additions & 1 deletion ivy/functional/ivy/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,10 @@ def requires_gradient(
-------
ret
A boolean indicating whether gradient computation is enabled for the input array.
"""
return current_backend(x).requires_gradient(x)


# AutoGrad #


Expand Down

0 comments on commit bd31086

Please sign in to comment.