Getting Started

Table of Contents

Get an account

SciLifeLab Serve is available for life science researchers that are affiliated with a Swedish university. It can also be accessed via SciLifeLab infrastructure units for use in life science research. Others may be granted access under specific circumstances. For example, collaborators may be granted access in order to allow them to work on apps/models.

Users are able to log in to SciLifeLab Serve using a Life Science Login (LS-login) (it is possible to use your Swedish university credentials with this service). If it is not possible for you to gain appropriate access credentials through LS-login, but you believe that you should have access to SciLifeLab Serve, you can request an account.

In the following subsection, we describe the steps that users should take to log in to SciLifeLab Serve using an LS-login.

Step-by-step guide

Users should obtain a Life Science Login (LS-login) to access SciLifeLab Serve. Users that have previously registered for an LS-login should be able to use their existing credentials, but may be asked to become a member of ELIXIR or to perform other confirmatory steps.

The below instructions describe the entire process of logging into SciLifeLab Serve, including obtaining an LS-login. Users that have previously registered for an LS-login may therefore be able to skip certain steps:

  1. Click 'Sign in' in the top right of the SciLifeLab Serve homepage.
  2. Click 'Life Science Login' in the subsequent page.
  3. Type the name of your institution in the 'Choose Your Identity Provider' box. Click on the appropriate option in the dropdown list.
  4. Use your institutional credentials (SWAMID) to log in when redirected to your institution's page.
  5. Click 'Proceed to register on the Life Science Login'. Users with an existing LS-login will not see this option and can skip to step 8.
  6. Click Submit after completing the registration form.
  7. Verify your email by clicking on the link/button in the verification email you received.
  8. If you have not done so previously, you will be asked to register with ELIXIR. Click 'Submit' after completing the registration form.
  9. Click 'Continue' on the subsequent page indicating that you are a member of ELIXIR.
  10. The next page will summarise the information to be shared with SciLifeLab Serve. Click 'Consent' to proceed.
  11. Early access users of SciLifeLab Serve will be given the option to add the information to their exiting account. Click 'Add to existing account' to do so. Otherwise, complete the subsequent form to get an account.
  12. Verify your email address (following instructions in the verification email you received) to link your account with ELIXIR-broker.
  13. You will be redirected to your SciLifeLab Serve account.
  14. You will receive an email regarding an access consent for your LS-login that you can review.

Projects

Users are able to host apps and models. Every app and model has to be located within a project. Projects that you have created/been granted access to can be found under the Projects tab in the sidebar.

Creating a project

Users need to be logged in to create a project. Users can create a new Project by following the steps below:

  1. Click on the Projects tab shown on the sidebar (only visible if you are logged in).
  2. Click the New Project button in the top right corner of the window.
  3. Select the project template that you want to use (currently there is only one template available).
  4. Enter project name (mandatory) and description (optional).
  5. Click the Create Project button to create the new project.

This will take you to the project Dashboard. Here, users will be able to see an overview of the whole project. Different project component options will now appear as tabs in the sidebar. A description of what each project component is can be found below:

  • Dashboard: Overview of the project.
  • Objects: Model objects created in the current project.
  • Compute: A list of pre-configured data science environments for experimentation and training ML models. (Currently, this tab will only have a pre-installed JupyterLab instance available for the user. Using this instance, users can e.g. can run experiments and also create model objects mentioned above. The tutorials below will elaborate on this.)
  • Serve: A list of the most common applications used for deploying Machine Learning models, as well as options to create R Shiny and Dash apps. All options are available as ‘cards’, and you can use the ‘Create’ button to use these applications. Custom applications can be added to this list, if requested.
  • Settings: Users can access and change the current project settings. Here one can, for example, add other project members.

Hosting apps and resources

Users can create resources by going into the Serve tab. Here, the following options are available:

  • R Shiny App
  • Dash App
  • Tensorflow Serve
  • PyTorch Serve
  • Python Model Serve (Using FastApi)

R Shiny

This is a resource to deploy R Shiny apps. Currently, only apps that have been packaged as a Docker container and made available on DockerHub are supported.

To deploy a R Shiny App click the Create button on the R Shiny App card in the Serve Tab. Then enter the following information in the form:

  • Name: Name of the app, specified by the user (e.g., 'Shiny Example')
  • Description: Provide a brief description of the app.
  • Subdomain: This is the subdomain that the deployed app will be available at (e.g., a subdomain of r46b61563 would mean that the app would be available at r46b61563.serve.scilifelab.se). If no subdomain name is entered, a random name will be genrated by default. By clicking on New you can specify the custom subdomain name of your choice (provided that it is not already taken). This subdomain will then appear in the Subdomain options and the subdomain will appear in the format 'name-you-chose.serve.scilifelab.se'.
  • Permissions: The permissions for the project. There are 3 levels of permissions for an app:
    • Private: The app can only be accessed by the user that created the app. (Sign In required)
    • Project: All members of the project will be able to access the app. (Sign In required)
    • Public: Anyone with the URL can access the app.
  • Path to folder:This is the path to the folder (inside the docker container) in which the main Shiny application file is located (usually app.R).
  • App Port: The port that the Shiny server runs on (usually 3838).
  • DockerHub Image: Name of the image on DockerHub.

When you deploy your app, you'll be taken to the serve page again, and should see your app in a list on the top of the screen. The state will initially show as 'Pending' (shown in an orange label), but should change to 'Running' (shown in a green label)

To update a Shiny App after a new image has been published on DockerHub, click the pencil icon next to the app and press on the Update button on the bottom of the form. To delete the app, press the bin icon beside the pencil icon.

Dash

This is a resource to deploy Dash apps. Currently, only apps that have been packaged as a Docker container and made available on DockerHub are supported.

To deploy a Dash App click the Create button on the Dash App card in the Serve Tab. Then Enter the following information in the form:

  • Name: Name of the app, specified by the user (e.g., 'Dash Example')
  • Description: Provide a brief description of the app.
  • Subdomain: This is the subdomain that the deployed app will be available at (e.g., a subdomain of r46b61563 would mean that the app would be available at r46b61563.serve.scilifelab.se). If no subdomain name is entered, a random name will be genrated by default. By clicking on New you can specify the custom subdomain name of your choice (provided that it is not already taken). This subdomain will then appear in the Subdomain options and the subdomain will appear in the format 'name-you-chose.serve.scilifelab.se'.
  • Permissions: The permissions for the project. There are 3 levels of permissions for an app:
    • Private: The app can only be accessed by the user that created the app. (Sign In required)
    • Project: All members of the project will be able to access the app. (Sign In required)
    • Public: Anyone with the URL can access the app.
  • Path to folder:This is the path to the folder (inside the docker container) in which the main Dash application file is located (usually app.py).
  • App Port: The port that the Dash app runs on (usually 8050).
  • DockerHub Image: Name of the image on DockerHub.

When you deploy your app, you'll be taken to the serve page again, and should see your app in a list on the top of the screen. The state will initially show as 'Pending' (shown in an orange label), but should change to 'Running' (shown in a green label)

To update a Dash App after a new image has been published on DockerHub, click the pencil icon next to the app and press on the Update button on the bottom of the form. To delete the app, press the bin icon beside the pencil icon.

Tutorials for serving machine learning models

These tutorials are intended as quick examples to get started with working on ML model deployment and serving using Scilifelab Serve.

When a project is created, users also get a Jupyter lab instance. This can be found in the Compute tab on the Sidebar (which is visible when you open a project). Click on Open to go to the Jupyter Lab instance. On the home screen, click on Terminal. This will open a terminal tab inside the Jupyter lab. Clone the tutorials repository serve-tutorials. You will now see the serve-tutorials folder.

Tensorflow

Go to serve-tutorials/Tensorflow/AML folder. Open the aml.ipynb notebook file. This notebook contains the code to create a ML Model and save it as an object on Scilifelab Serve. Run all the cells in the notebook. This may take some time (around 20 mins) as the model is trained.

After running this file, go to the Serve tab on the portal and create a Tensorflow Serve App with the follwing entries:

  • Name: AML Tensorflow
  • Subdomain: This is automatically generated. A custom subdomain can be created by filling out the form below ("Add Subdomain"), this domain will then show up as an option.
  • Permissions: Set the permission to project.
  • Model: Select the model, in this case the model is named aml.
  • Flavor: This indicates the resources given to the app. Currently on the Medium option is availble on the platform.

This should create the app and it will be visible in the Serve Tab. Copy the link for the service (you can do this by right clicking Open and selecting copy link address). Then, go back to the Jupyter lab instance and open the predict.ipynb notebook. Replace the endpoint with the URL that you copied. Run the cells in the notebook. If you see a prediction, this means that the service is running successfully.

PyTorch

To serve a PyTorch model, we will use a pytorch model archive (VGG11) already prepared. You can read more about the model here.

Go to the project-vol folder inside the Jupyter lab. Right-click to create a new folder and give it a name (e.g., pytorch-deployment). Go to the terminal (you can also launch a new terminal through File > New > Terminal). Change directory to the newly created folder, so in this case by cd project-vol/pytorch-deployment/. Once inside this folder run the command curl -O -J https://nextcloud.dckube.scilifelab.se/s/TSNxFJCYrpJZAnz/download. This will download the vgg11_scripted.mar archive to this folder. Now that we have the model archive, we need to launch the Pytorch Serve App. On the Scilifelab Serve portal, go to the Serve tab. Then create the Pytorch Serve App with the following values:

  • Name: VGG11 Serve
  • Subdomain: This is automatically generated, if not selected. You can create a subdomain to choose using the Add Subdomain form located at the bottom.
  • Permissions: Set the permission to public. (Currently, public permissions are required to access the serve URL for pytorch apps).
  • Flavor: This indicates the resources given to the app. Currently on the Medium option is availble on the platform.
  • Persistent Volume: The volume that needs to be attached to the instance. In this case it is important to select project-vol as that is where we dowloaded the vgg11_scripted.mar file.
  • Path to Model Store: This is the path to the folder where the model is located (relative to the mounted volume). As the model was downloaded in the pytorch-deployment folder inside the project-vol, the value for this will be pytorch-deployment.
  • Comma-separeted list of models (model1,model2,model3): This can be left empty. Here, model names from the model archive can be listed to deploy only those models.

Create the app and wait for the status to turn to Running. Right click on Open and copy the link address for the app. To check if it is working properly you can go to the Jupyter lab instance and open the terminal. Go to the serve-tutorials/PyTorch/ folder using cd serve-tutorials/PyTorch/ and run the command curl copied-url/vgg11_scripted -T kitten.jpg (inplace of copied-url add the URL you copied earlier). You should get a JSON response if the deployment is working properly.

Python Model Deployment

Launch a new terminal from within your Jupyter instance and go to the Python-Model-Deployment folder:

cd serve-tutorials/Python-Model-Deployment folder

Install the required packages:

pip install -r requirements.txt

Go to serve-tutorials/Python-Model-Deployment folder. Open the getting_started_with_swebert.ipynb notebook file. Follow the notebook's instructions.

Once you have run all the cells in the above notebook, open up again the terminal and execute the following commands within the repository directory (inside the Python-Model-Deployment folder):

stackn create object afbert -r minor

stackn get objects

(Check that the model is listed; you should be able to see the newly created model object in your Scilifelab Serve UI, under the "Objects" tab)

Deploy the newly created model object with the "Python Model Deployment" component (under the "Serve" tab). Name can be anything, Model should match the name of the newly created model (e.g., "afbert:v0.1.0"); leave the rest as defaults.

Note: It could take some time for this model to initialize, so keep checking the logs until it is available and wait until it is running successfully.

Once the above serving app is up and running, copy the endpoint URL by right-clicking on the Open link.

Go back to your Jupyter Lab and open the predict.ipynb notebook under the notebooks folder. Paste the copied URL in place of the URL in order to use the correct endpoint for the prediction.

It is time to test the prediction! Run all the cells and check the results.

You can play around by changing the values of the example and msk_ind variables. The latter will mask (or "hide") one of the words in the example sentence; then the prediction will shown the possible candidates for such "missing" word.