-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying to main from @ ivy-llc/ivy@ace8434 🚀
- Loading branch information
1 parent
7c0287d
commit dd8865e
Showing
134 changed files
with
49,899 additions
and
66 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+50.5 KB
.doctrees/demos/examples_and_demos/image_segmentation_with_ivy_unet_cpu.doctree
Binary file not shown.
Binary file added
BIN
+37.8 KB
.doctrees/demos/examples_and_demos/lstm_tensorflow_to_torch_cpu.doctree
Binary file not shown.
Binary file added
BIN
+28.8 KB
.doctrees/demos/examples_and_demos/lstm_torch_to_tensorflow_cpu.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ees/docs/functional/ivy/experimental/ivy.functional.ivy.experimental.manipulation.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...experimental/manipulation/ivy.functional.ivy.experimental.manipulation.as_strided.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...mental/manipulation/ivy.functional.ivy.experimental.manipulation.associative_scan.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ivy/experimental/manipulation/ivy.functional.ivy.experimental.manipulation.choose.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...perimental/manipulation/ivy.functional.ivy.experimental.manipulation.column_stack.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...al/manipulation/ivy.functional.ivy.experimental.manipulation.concat_from_sequence.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...erimental/manipulation/ivy.functional.ivy.experimental.manipulation.fill_diagonal.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...l/ivy/experimental/manipulation/ivy.functional.ivy.experimental.manipulation.fold.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.../experimental/manipulation/ivy.functional.ivy.experimental.manipulation.matricize.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...perimental/manipulation/ivy.functional.ivy.experimental.manipulation.partial_fold.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...l/manipulation/ivy.functional.ivy.experimental.manipulation.partial_tensor_to_vec.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...rimental/manipulation/ivy.functional.ivy.experimental.manipulation.partial_unfold.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...l/manipulation/ivy.functional.ivy.experimental.manipulation.partial_vec_to_tensor.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...rimental/manipulation/ivy.functional.ivy.experimental.manipulation.put_along_axis.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ental/manipulation/ivy.functional.ivy.experimental.manipulation.soft_thresholding.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...l/ivy/experimental/manipulation/ivy.functional.ivy.experimental.manipulation.take.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...experimental/manipulation/ivy.functional.ivy.experimental.manipulation.trim_zeros.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.../experimental/manipulation/ivy.functional.ivy.experimental.manipulation.unflatten.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ivy/experimental/manipulation/ivy.functional.ivy.experimental.manipulation.unfold.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ntal/manipulation/ivy.functional.ivy.experimental.manipulation.unique_consecutive.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.doctrees/docs/functional/ivy/ivy.functional.ivy.meta.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.doctrees/docs/functional/ivy/meta/ivy.functional.ivy.meta.fomaml_step.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.doctrees/docs/functional/ivy/meta/ivy.functional.ivy.meta.maml_step.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.doctrees/docs/functional/ivy/meta/ivy.functional.ivy.meta.reptile_step.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.doctrees/docs/functional/ivy/nest/ivy.functional.ivy.nest.set_nest_at_index.doctree
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
.doctrees/docs/helpers/ivy_tests.test_ivy.helpers.globals.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
893 changes: 893 additions & 0 deletions
893
.doctrees/nbsphinx/demos/examples_and_demos/alexnet_demo_cpu.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
603 changes: 603 additions & 0 deletions
603
.doctrees/nbsphinx/demos/examples_and_demos/bert_demo_cpu.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
540 changes: 540 additions & 0 deletions
540
.doctrees/nbsphinx/demos/examples_and_demos/convnext_to_torch_cpu.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
1,680 changes: 1,680 additions & 0 deletions
1,680
.doctrees/nbsphinx/demos/examples_and_demos/dinov2_to_paddle_cpu.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
787 changes: 787 additions & 0 deletions
787
.doctrees/nbsphinx/demos/examples_and_demos/image_segmentation_with_ivy_unet_cpu.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
250 changes: 250 additions & 0 deletions
250
.doctrees/nbsphinx/demos/examples_and_demos/lstm_tensorflow_to_torch_cpu.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "nZlFgbLdA9lK" | ||
}, | ||
"source": [ | ||
"First, lets install Ivy via pip and import it alongside the other frameworks we'll be using." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "vmN-gYwICZjy", | ||
"outputId": "2e969212-08bf-443d-86d2-fe171d593628" | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.4/16.4 MB\u001b[0m \u001b[31m15.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.6/44.6 kB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.5/45.5 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m143.8/143.8 kB\u001b[0m \u001b[31m17.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m756.0/756.0 kB\u001b[0m \u001b[31m20.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m15.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m21.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25h" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"!pip install -q ivy" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "3TfqvcChjoE5" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import ivy\n", | ||
"import torch\n", | ||
"import tensorflow as tf\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "8pt3dWIjBXM2" | ||
}, | ||
"source": [ | ||
"Here we create a basic TensorFlow Keras model containing a single LSTM layer as an example.\n", | ||
"\n", | ||
"We can then convert this model to PyTorch by transpiling with ivy.transpile and providing some input arguments for the model." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "5UPdMybhjd5G", | ||
"outputId": "2105d54f-7e6a-4b14-8f57-bdff4f860f64" | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"WARNING:root:can not set PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU') to dynamically allocate memory. Physical devices cannot be modified after being initialized\n", | ||
"/usr/local/lib/python3.10/dist-packages/ivy/utils/exceptions.py:383: UserWarning: The current backend: 'tensorflow' does not support inplace updates natively. Ivy would quietly create new arrays when using inplace updates with this backend, leading to memory overhead (same applies for views). If you want to control your memory management, consider doing ivy.set_inplace_mode('strict') which should raise an error whenever an inplace update is attempted with this backend.\n", | ||
" warnings.warn(\n", | ||
"WARNING:root:can not set PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU') to dynamically allocate memory. Physical devices cannot be modified after being initialized\n", | ||
"/usr/local/lib/python3.10/dist-packages/ivy/compiler/compiler.py:164: UserWarning: `Model.state_updates` will be removed in a future version. This property should not be used in TensorFlow 2.0, as `updates` are applied automatically.\n", | ||
" return _transpile(\n", | ||
"/usr/local/lib/python3.10/dist-packages/ivy/compiler/compiler.py:164: UserWarning: `layer.updates` will be removed in a future version. This property should not be used in TensorFlow 2.0, as `updates` are applied automatically.\n", | ||
" return _transpile(\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"with tf.device(\"/CPU:0\"):\n", | ||
" sample_input = tf.random.uniform((5, 2, 40))\n", | ||
"\n", | ||
" # build the lstm keras model\n", | ||
" tf_lstm = tf.keras.Sequential([tf.keras.layers.LSTM(40)])\n", | ||
" tf_lstm.build(sample_input.shape)\n", | ||
"\n", | ||
" # transpile to torch\n", | ||
" torch_lstm = ivy.transpile(tf_lstm, source=\"tensorflow\", to=\"torch\", args=(sample_input,))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "cL_5ZJ7tCEJb" | ||
}, | ||
"source": [ | ||
"Now we've transpiling the model to PyTorch, lets verify that the results produced by the new PyTorch model are identical to those produced by the original Keras model.\n", | ||
"\n", | ||
"We'll use an input tensor with different shape to the input the model was transpiled with, to verify that the transpiled model is compatible with dynamic input shapes." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "8LlLeYU6kAdy", | ||
"outputId": "5d019e2e-e379-4acd-ae46-5ff0951dffd5" | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# identical input tensors for torch and tf\n", | ||
"torch_input = torch.rand((10, 100, 40))\n", | ||
"tf_input = tf.constant(torch_input.cpu().detach().numpy())\n", | ||
"\n", | ||
"# compile the original tensorflow model\n", | ||
"tf_lstm = tf.function(tf_lstm)\n", | ||
"\n", | ||
"# get output of the original and transpiled models\n", | ||
"tf_output = tf_lstm(tf_input)\n", | ||
"torch_output = torch_lstm(torch_input)\n", | ||
"\n", | ||
"# verify the outputs are the same (with some tolerance)\n", | ||
"np.allclose(tf_output[0].numpy(), torch_output[0].cpu().detach().numpy(), atol=1e-6)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "a8Z8HYfVCR5V" | ||
}, | ||
"source": [ | ||
"Finally, lets benchmark the transpiled torch model compared to the original. Here we benchmark on both CPU and GPU over 1000 inference runs." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "GwIxkmwGkIiT", | ||
"outputId": "dd74861f-d304-4d04-ad1b-20d2b48e14e4" | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"(CPU) tensorflow lstm time: 5.5017 seconds transpiled torch lstm time: 2.1101 seconds\n", | ||
"(GPU) tensorflow lstm time: 1.7519 seconds transpiled torch lstm time: 0.901 seconds\n", | ||
"\n", | ||
"transpiled torch lstm is 2.607x faster than tensorflow's lstm on CPU\n", | ||
"transpiled torch lstm is 1.944x faster than tensorflow's lstm on GPU\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# run some benchmarks\n", | ||
"\n", | ||
"from time import perf_counter\n", | ||
"\n", | ||
"N_RUNS = 1000\n", | ||
"\n", | ||
"tf_inputs = tf.random.normal([10, 100, 40])\n", | ||
"torch_inputs = torch.from_numpy(tf_inputs.numpy())\n", | ||
"\n", | ||
"\n", | ||
"# benchmark on CPU\n", | ||
"with tf.device(\"/CPU:0\"):\n", | ||
" torch_lstm = torch_lstm.to(\"cpu\")\n", | ||
"\n", | ||
" tf_inputs = tf.random.normal([10, 100, 40])\n", | ||
" torch_inputs = torch.from_numpy(tf_inputs.numpy()).to(\"cpu\")\n", | ||
"\n", | ||
" # time the tf lstm\n", | ||
" s = perf_counter()\n", | ||
" for _ in range(N_RUNS):\n", | ||
" tf_lstm(tf_inputs)\n", | ||
" tf_time = round(perf_counter() - s, 4)\n", | ||
"\n", | ||
" # time the transpiled torch lstm\n", | ||
" s = perf_counter()\n", | ||
" for _ in range(N_RUNS):\n", | ||
" torch_lstm(torch_inputs)\n", | ||
" torch_time = round(perf_counter() - s, 4)\n", | ||
"\n", | ||
" print(f'(CPU) tensorflow lstm time: {tf_time} seconds transpiled torch lstm time: {torch_time} seconds')\n", | ||
"\n", | ||
" cpu_speedup = round(tf_time / torch_time, 3)\n", | ||
"\n", | ||
"\n", | ||
"print(f'\\ntranspiled torch lstm is {cpu_speedup}x faster than tensorflow\\'s lstm on CPU')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "8o02WQqpDlyS" | ||
}, | ||
"source": [ | ||
"We can see that the results of the transpiled PyTorch model are significantly faster than the original Keras model on both CPU and GPU :)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"accelerator": "GPU", | ||
"colab": { | ||
"gpuType": "T4", | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Oops, something went wrong.