Skip to content

Commit

Permalink
add simple source_to_source demo for nightly tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Armstrong committed Aug 7, 2024
1 parent ea71fcd commit 150f0fa
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 9 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test-nightly-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ on:
push:

jobs:
tests:
notebook-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module: [
alexnet_demo_cpu,
# bert_demo, # tests disabled until the OOM issue is resolved
#image_segmentation_with_ivy_unet_cpu, # tests disabled until we get cuda installation working in the docker image
# mmpretrain_to_jax, # tests disabled until we get cuda installation working in the docker image
resnet_demo_cpu,
#torch_to_jax_cpu, # tests disabled until we get cuda installation working in the docker image
lstm_tensorflow_to_torch_cpu,
lstm_torch_to_tensorflow_cpu,
# dinov2_to_paddle, # tests disabled until we get cuda installation working in the docker image
#convnext_to_torch_cpu, # tests disabled until we get cuda installation working in the docker image
# xgboost_demo, # tests disabled until we get the csv files uploaded to drive for being used in the tests
kornia_demo,
]

steps:
Expand Down
94 changes: 94 additions & 0 deletions examples_and_demos/kornia_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install -q ivy kornia"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import ivy\n",
"import torch\n",
"import tensorflow as tf\n",
"import kornia\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cache database created at /Users/samuelarmstrong/Documents/ivy/demos/examples_and_demos/.ivy/cache.sqlite.\n",
"Graph cache table created.\n",
"Autotune cache table created.\n"
]
},
{
"ename": "IvyException",
"evalue": "Unable to find an api key in the IVY_KEY env var, or ivy-key.pem file.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIvyException\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m tf_rgb_to_grayscale \u001b[38;5;241m=\u001b[39m \u001b[43mivy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msource_to_source\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkornia\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolor\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrgb_to_grayscale\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msource\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtorch\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtensorflow\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m/opt/homebrew/lib/python3.10/site-packages/ivy/compiler/compiler.py:44\u001b[0m, in \u001b[0;36msource_to_source\u001b[0;34m(object, source, target, profiling)\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Converts a given object (class/function) from one framework to another.\u001b[39;00m\n\u001b[1;32m 26\u001b[0m \n\u001b[1;32m 27\u001b[0m \u001b[38;5;124;03mThis function performs source-to-source translation of a given object from the source framework\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[38;5;124;03mReturns:\u001b[39;00m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;124;03m The translated object.\"\"\"\u001b[39;00m\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_compiler\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m source_to_source \u001b[38;5;28;01mas\u001b[39;00m _source_to_source\n\u001b[0;32m---> 44\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_source_to_source\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 45\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mobject\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mobject\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 46\u001b[0m \u001b[43m \u001b[49m\u001b[43msource\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msource\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 47\u001b[0m \u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtarget\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 48\u001b[0m \u001b[43m \u001b[49m\u001b[43mprofiling\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprofiling\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 49\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32mVLL.pyx:15\u001b[0m, in \u001b[0;36mVLL.source_to_source\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mIvyException\u001b[0m: Unable to find an api key in the IVY_KEY env var, or ivy-key.pem file."
]
}
],
"source": [
"tf_rgb_to_grayscale = ivy.source_to_source(kornia.color.rgb_to_grayscale, source=\"torch\", target=\"tensorflow\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"torch_input = torch.rand(5, 3, 4, 4)\n",
"tf_input = tf.convert_to_tensor(torch_input.numpy())\n",
"\n",
"torch_output = kornia.color.rgb_to_grayscale(torch_input)\n",
"tf_output = tf_rgb_to_grayscale(tf_input)\n",
"\n",
"assert np.allclose(torch_output.numpy(), tf_output.numpy(), atol=1e-3)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion tests/test_demos.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [ $2 == true ]; then
export VERSION=main
export VERSION=nightly
fi

cd ivy
Expand Down

0 comments on commit 150f0fa

Please sign in to comment.