Skip to content

Commit

Permalink
Merge branch 'unifyai:main' into refactor-decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyanshBardia authored Sep 25, 2023
2 parents 5033955 + b65c842 commit 248f084
Show file tree
Hide file tree
Showing 76 changed files with 2,488 additions and 840 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr-lint-bot.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Trigger lint format

on:
issue_comment:
types: [created]
pull_request:
types: [opened, edited, synchronize, labeled, unlabeled, ready_for_review, reopened]

permissions:
contents: write

jobs:
fix-linting:
name: PR Lint Bot
uses: unifyai/workflows/.github/workflows/pr-lint-bot.yml@main
uses: unifyai/workflows/.github/workflows/pr-lint-bot.yml@automatic-lint-pr
secrets: inherit
43 changes: 43 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cff-version: 1.2.0
title: >-
Ivy: Templated deep learning for inter-framework
portability
message: >-
If you are using Ivy, we would really appreciate it if you
cite it in your work!
authors:
- given-names: Daniel
family-names: Lenton
- given-names: Fabio
family-names: Pardo
- given-names: Fabian
family-names: Falck
- given-names: Stephen
family-names: James
- given-names: Ronald
family-names: Clark
identifiers:
- type: doi
value: 10.48550/arXiv.2102.02886
description: 'arXiv preprint '
repository-code: 'https://github.com/unifyai/ivy'
url: 'https://unify.ai/'
repository: 'https://github.com/unifyai/'
abstract: 'We introduce Ivy, a templated Deep Learning (DL) framework which abstracts existing DL frameworks. Ivy unifies the core functions of these frameworks to exhibit consistent call signatures, syntax and input-output behaviour. New high-level framework-agnostic functions and classes, which are usable alongside framework-specific code, can then be implemented as compositions of the unified low-level Ivy functions. Ivy currently supports TensorFlow, PyTorch, MXNet, Jax and NumPy. We also release four pure-Ivy libraries for mechanics, 3D vision, robotics, and differentiable environments. Through our evaluations, we show that Ivy can significantly reduce lines of code with a runtime overhead of less than 1% in most cases. We welcome developers to join the Ivy community by writing their own functions, layers and libraries in Ivy, maximizing their audience and helping to accelerate DL research through inter-framework codebases.'
license: Apache-2.0
preferred-citation:
type: article
authors:
- given-names: Daniel
family-names: Lenton
- given-names: Fabio
family-names: Pardo
- given-names: Fabian
family-names: Falck
- given-names: Stephen
family-names: James
- given-names: Ronald
family-names: Clark
doi: 10.48550/arXiv.2102.02886
title: "Ivy: Templated deep learning for inter-framework
portability"
2 changes: 1 addition & 1 deletion docker/requirement_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"paddle": ["paddlepaddle"],
"mxnet": ["mxnet"],
"torch": ["torchvision"]
}
}
2 changes: 1 addition & 1 deletion docker/requirement_mappings_gpu.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"numpy": ["numpy"],
"mxnet": ["mxnet"],
"torch": ["torch-scatter", "torchvision"]
}
}
2 changes: 1 addition & 1 deletion docs/demos
Submodule demos updated from aa57ad to aaef6c
6 changes: 2 additions & 4 deletions ivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,13 +1222,11 @@ def dynamic_backend_as(value):
set_sub_backend,
unset_sub_backend,
clear_sub_backends,
available_sub_backends,
available_sub_backend_implementations,
)


def current_sub_backends():
return []
available_sub_backends = []
current_sub_backends = []


# casting modes
Expand Down
40 changes: 40 additions & 0 deletions ivy/data_classes/array/experimental/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,43 @@ def elu(
ivy.array([ 0.39, -0.57])
"""
return ivy.elu(self._data, alpha=alpha, out=out)

def hardtanh(
self: ivy.Array,
/,
*,
max_val: float = 1,
min_val: float = -1,
out: Optional[ivy.Array] = None,
) -> ivy.Array:
"""
ivy.Array instance method variant of ivy.hardtanh. This method simply wraps the
function, and so the docstring for ivy.hardtanh also applies to this method with
minimal changes.
Parameters
----------
self
input array.
min_val
minimum value of the linear region range. Default: -1.
max_val
maximum value of the linear region range. Default: 1.
out
optional output array, for writing the result to. It must have a shape
that the inputs broadcast to.
Returns
-------
ret
an array with the hardtanh activation function applied element-wise
with custom linear region range.
Examples
--------
>>> x = ivy.array([-1., .2, 1.])
>>> y = x.hardtanh()
>>> print(y)
ivy.array([-1., 1., 1.])
"""
return ivy.hardtanh(self._data, min_val=min_val, max_val=max_val, out=out)
44 changes: 44 additions & 0 deletions ivy/data_classes/array/experimental/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,3 +1228,47 @@ def sliding_window(
dilation=dilation,
padding=padding,
)

def max_unpool1d(
self: ivy.Array,
indices: ivy.Array,
kernel_size: Union[Tuple[int], int],
/,
*,
strides: Union[int, Tuple[int]] = None,
padding: Union[int, Tuple[int]] = 0,
data_format: Optional[str] = "NCW",
) -> ivy.Array:
"""
Compute a 1-D max unpooling given the 1-D pooled input x and its indices.
Parameters
----------
self
Pooled input image *[batch_size, w, d_in]*.
indices
Indices obtained from the corresponding max pooling operation.
kernel_size
Size of the kernel i.e., the sliding window for each
dimension of input. *[w]*.
strides
The stride of the sliding window for each dimension of input.
padding
SAME" or "VALID" indicating the algorithm, or list
indicating the per-dimension paddings.
data_format
NWC" or "NCW". Defaults to "NWC".
Returns
-------
ret
The result of the unpooling operation.
"""
return ivy.max_unpool1d(
self._data,
indices,
kernel_size,
strides=strides,
padding=padding,
data_format=data_format,
)
16 changes: 16 additions & 0 deletions ivy/data_classes/container/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,13 @@ def _cont_get_shape(self):
def _cont_get_shapes(self):
return self.cont_map(lambda x, kc: x.shape if hasattr(x, "shape") else None)

def _cont_get_dtype(self):
sub_dtypes = [
v for k, v in self.cont_map(lambda x, kc: x.dtype).cont_to_iterator() if v
]
unique_dtypes = list(set(sub_dtypes))
return sub_dtypes[0] if len(unique_dtypes) == 1 else None

def _cont_get_dev(self, as_native=False):
sub_devs = [
v
Expand Down Expand Up @@ -4260,6 +4267,15 @@ def cont_shape(self):
"""
return self._cont_get_shape()

@property
def cont_dtype(self):
"""
The dtype of the arrays in the container.
None is returned if the dtypes are not consistent.
"""
return self._cont_get_dtype()

@property
def cont_shapes(self):
"""
Expand Down
134 changes: 134 additions & 0 deletions ivy/data_classes/container/experimental/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,3 +933,137 @@ def elu(
map_sequences=map_sequences,
out=out,
)

@staticmethod
def _static_hardtaanh(
x: Union[ivy.Array, ivy.NativeArray, ivy.Container],
/,
*,
min_val: ivy.Container = -1.0,
max_val: ivy.Container = 1.0,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
map_sequences: Union[bool, ivy.Container] = False,
out: Optional[ivy.Container] = None,
) -> ivy.Container:
"""
ivy.Container static method variant of ivy.hardtanh.This method simply wrap the
function,the docstring for ivy.hardtanh also applies to this method with minimal
changes.
Parameters
----------
x
input container.
min_val
minimum value of the linear region range. Default: -1.
max_val
maximum value of the linear region range. Default: 1.
key_chains
The key-chains to apply or not apply the method to. Default is ``None``.
to_apply
If True, the method will be applied to key_chains, otherwise key_chains
will be skipped. Default is ``True``.
prune_unapplied
Whether to prune key_chains for which the function was not applied.
Default is ``False``.
map_sequences
Whether to also map method to sequences (lists, tuples).
Default is ``False``.
out
optional output container, for writing the result to. It must have a shape
that the inputs broadcast to.
Returns
-------
ret
a container with the hardtanh unit function applied element-wise.
Examples
--------
>>> x = x = ivy.Container(a=ivy.array([0.39, -2.0]), b=ivy.array([2., -0.2]))
>>> y = ivy.Container.static_hardtanh(x)
>>> print(y)
{
a: ivy.array([0.39, -1.]),
b: ivy.array([1., -0.2])
}
"""
return ContainerBase.cont_multi_map_in_function(
"hardtanh",
x,
min_val=min_val,
max_val=max_val,
key_chains=key_chains,
to_apply=to_apply,
prune_unapplied=prune_unapplied,
map_sequences=map_sequences,
out=out,
)

def hardtanh(
self: ivy.Container,
/,
*,
min_val: ivy.Container = -1.0,
max_val: ivy.Container = 1.0,
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None,
to_apply: Union[bool, ivy.Container] = True,
prune_unapplied: Union[bool, ivy.Container] = False,
map_sequences: Union[bool, ivy.Container] = False,
out: Optional[ivy.Container] = None,
) -> ivy.Container:
"""
ivy.Container instance method variant of ivy.hardtanh.This method simply wraps
the function, so the docstring for ivy.elu also applies to this method with
minimal changes.
Parameters
----------
self
input container.
min_val
minimum value of the linear region range. Default: -1.
max_val
maximum value of the linear region range. Default: 1.
key_chains
The key-chains to apply or not apply the method to. Default is ``None``.
to_apply
If True, the method will be applied to key_chains, otherwise key_chains
will be skipped. Default is ``True``.
prune_unapplied
Whether to prune key_chains for which the function was not applied.
Default is ``False``.
map_sequences
Whether to also map method to sequences (lists, tuples).
Default is ``False``.
out
optional output container, for writing the result to. It must have a shape
that the inputs broadcast to.
Returns
-------
ret
a container with the hardtanh unit function applied element-wise.
Examples
--------
>>> x = x = ivy.Container(a=ivy.array([0.39, -2.0]), b=ivy.array([2., -0.2]))
>>> y = ivy.Container.static_hardtanh(x)
>>> print(y)
{
a: ivy.array([0.39, -1.]),
b: ivy.array([1., -0.2])
}
"""
return self._static_hardtaanh(
self,
max_val=max_val,
min_val=min_val,
key_chains=key_chains,
to_apply=to_apply,
prune_unapplied=prune_unapplied,
map_sequences=map_sequences,
out=out,
)
Loading

0 comments on commit 248f084

Please sign in to comment.