Composing AI Inference pipelines based on OSCAR services with Elyra in EGI Notebooks

../../../_images/elyra_icon.png

In this documentation, we provide a hands-on guide to using Elyra , an AI-centric extension for Jupyter Notebooks , within EGI Notebooks.

This tutorial will focus on:

  • how to use Elyra in EGI Notebooks

  • how to clone repositories using Elyra

  • how to interact with OSCAR, using the EGI Notebook Token.

  • how to deploy a pipeline to utilize inference services using OSCAR.

../../../_images/cowsay_example.png

We will walk through the entire process, from setting up the initial environment to running specific OSCAR services like the Cowsay and others.

1. Setting up the environment

1.1 Accessing EGI notebooks

The first step is to access the EGI Notebooks service. Then choose the preferred server option. We will select Default EGI environment:

../../../_images/egi_notebooks_server_options.png

For additional information on using EGI Notebooks, refer to the official documentation.

1.2 Importing OSCAR Elyra from Github

To get started, you will need to clone the repository that contains the example files for Elyra and OSCAR services: https://github.com/ai4os/ai4-compose

You can use the Elyra git tool on the left side panel to clone the repository in the EGI Notebooks environment. This repository contains various examples, including those for Elyra, such as Cowsay, Grayify, and Plants-Theano.

../../../_images/elyra-git.png ../../../_images/cloning_repo_elyra.png

2. Prerequisites for all the examples

2.1 Types of recipes

To use the nodes that employ OSCAR, it is necessary to invoke a service. This service has two recipes:

  1. The first recipe solely uses an EGI Check-in token. This is the best option if you use the AI4EOSC OSCAR cluster authenticating with your EGI account.

  2. The second recipe uses our own credentials: node ID, endpoint, username, and password. This is an alternative for when you want to use your own OSCAR clusters.

2.2 How to use the EGI Token

If you wish to use the EGI token, there’s no need to use or create a script that saves credentials. To access your token:

  1. Open the notebook node named oscar_cowsay.ipynb.

  2. Add a new cell immediately after the library import cell.

../../../_images/get_egi_token.png
  1. Enter the following code into the new cell:

with open("/var/run/secrets/egi.eu/access_token") as f:
    access_token = f.read()

2.3 How to create our own credentials

Before running any example, we need to create a credentials node in Elyra, required to invoke a service in an OSCAR cluster. For this example, we already have a node that assists in generating credentials, named generate_credentials.py. This node will handle the environment variables necessary to interact with your OSCAR cluster.

Here’s how to use it:

  1. Open the cowsay example, searching it in the left panel, inside the ai4-compose folder that we have previously cloned.

    The path is: ai4-compose/elyra/examples/cowsay/cowsay.pipeline

  2. Right click on the node Generate Credentials, and select the Open Properties option. This opens a right side panel.

  3. In this panel, you need to set up the environment variables: ID, ENDPOINT, USERNAME, and PASSWORD.

../../../_images/creating_credentials_1.png
  1. Save these as a JSON file and name it credentials.json.

../../../_images/creating_credentials_2.png

This JSON file will be sent as an environment variable to the subsequent nodes in your workflow.

3. Deploying a pipeline

3.1 Running the Cowsay Example

Now let’s get our cow to talk! Follow these steps to set up the workflow in Elyra:

  1. Use the cowsay service node and connect it to the previous node (if the node is not already connected).

  2. Pass the credentials.json and the text for the cow (eg. moo) as environment variables.

../../../_images/cowsay_variables.png
  1. Use the start button to execute the pipeline

../../../_images/how_to_start_elyra_pipeline.png
  1. After setting up the environment variables, proceed to the notebook within this node. Once executed, the notebook should display the cow uttering the text you provided.

../../../_images/cowsay_output.png

3.2 Additional Examples: Grayify and Plants-Theano

../../../_images/others_examples.png

You have more examples available in the Github repo to test the composing of functions for inference with OSCAR.

For all the examples, you’ll again need the credentials node to send the necessary variables. Additionally, other nodes will be involved to perform tasks like converting images to and from Base64 format.