Skip to content

Commit

Permalink
test dummy ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarsh2001 committed Aug 9, 2023
1 parent 5f89622 commit 957e279
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 5 deletions.
5 changes: 1 addition & 4 deletions learn_the_basics/03_compile_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install ivy\n",
"!pip install torch\n",
"!pip install jax\n",
"!pip intall jaxlib"
"!pip install ivy"
]
},
{
Expand Down
107 changes: 107 additions & 0 deletions learn_the_basics/_compile_code_test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"Turn your Ivy code into an efficient fully-functional graph, removing wrappers and unused parts of the code."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"⚠️ If you are running this notebook in Colab, you will have to install `Ivy` and some dependencies manually. You can do so by running the cell below ⬇️\n",
"\n",
"If you want to run the notebook locally but don't have Ivy installed just yet, you can check out the [Get Started section of the docs.](https://unify.ai/docs/ivy/overview/get_started.html)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"!pip install ivy"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Firstly, let's pick up where we left off in the [last notebook](), with our unified `normalize` function:"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"import torch\n",
"import ivy\n",
"\n",
"def normalize(x):\n",
" mean = torch.mean(x)\n",
" std = torch.std(x)\n",
" return torch.div(torch.sub(x, mean), std)\n",
"\n",
"normalize = ivy.unify(normalize, source=\"torch\")\n",
"\n",
"# set ivy's backend to jax\n",
"ivy.set_backend(\"jax\")\n",
"\n",
"# Import jax\n",
"import jax\n",
"\n",
"# create random jax arrays for testing\n",
"key = jax.random.PRNGKey(42)\n",
"x = jax.random.uniform(key, shape=(10,))\n",
"\n",
"normalize(x)\n",
"\n",
"ivy.set_backend(\"jax\")\n",
"comp = ivy.compile(normalize) # compiles to jax, due to ivy.set_backend\n",
"\n",
"comp(x)\n",
"\n",
"%%timeit\n",
"normalize(x)\n",
"\n",
"%%timeit\n",
"comp(x)"
],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
2 changes: 1 addition & 1 deletion tests/notebook_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_notebook(nb):


if __name__ == "__main__":
for ipynb in ["learn_the_basics/03_compile_code.ipynb"]: # sys.argv[1:]:
for ipynb in ["learn_the_basics/_compile_code_test.ipynb"]: # sys.argv[1:]:
print("testing %s" % ipynb)
with open(ipynb) as f:
nb = nbformat.reads(f.read(), nbformat.current_nbformat)
Expand Down

0 comments on commit 957e279

Please sign in to comment.