paint-brush
How to Run a Flask application with free GPU acceleration for students, using PyCharmby@dilrukshi-perera
1,938 reads
1,938 reads

How to Run a Flask application with free GPU acceleration for students, using PyCharm

by Dilrukshi PereraSeptember 19th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Many Deep learning or Machine Learning projects require GPU acceleration, and getting access to external GPUs or using GPU services by different cloud services can be costly, especially for students.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How to Run a Flask application with free GPU acceleration for students, using PyCharm
Dilrukshi Perera HackerNoon profile picture

Many Deep learning or Machine Learning projects require GPU acceleration, and getting access to external GPUs or using GPU services by different cloud services can be costly, especially for students.

The very reason to write this article is the difficulties most of the students including me, face or have faced when it comes to necessitating GPU acceleration based on the general-purpose GPU library NVIDIA CUDA for Deep learning projects and with the computer not having physical CUDA enabled GPU.

Should say that there are plenty of free cloud services which grant free GPU when it comes to Training a Deep Learning models for example, Googles Colab, Paperspace Gradient and so on. But accessing the above said free cloud GPU, to develop REST APIs which consume GPU acceleration because it deals with operations related with tensors (matrix operations) remained to be a problem. 

So I was considering and searching of ways how to run my flask app on a free cloud GPU and found this article for the rescue: 

https://mc.ai/getting-free-access-to-aws-gpu-instances-for-deep-learning/

With the help of that article, I was able to get registered for Github EducationStudent Developer Pack , after following the steps mentioned there, with the email id of my current higher educational institute.

For the development and running of the application, we will be needing ‘PyCharm Professional’ edition and a GPU accelerated Virtual machine or a server.

With the help of the Student Developer pack I was able to install ‘PyCharm Professional’ for free.

There are many options to go for when it comes to choosing a free GPU accelerated Virtual machine or a server using many cloud services for example; Microsoft Azure cloud services, AWS cloud, DigitalOcean, Google Cloud GPUs and so on. But some of them may require credit cards at signup for verification even if it’s for the free trial.

With minimum trouble, and not having to enter any credit card info, I was able to use Azure DSVM (Data Science Virtual Machine), to develop, host and run my flask app on, which grants free $100 credit for students (GPU enabled).

Any of the GPU accelerated VM or a server can be used, it could be either a paid subscription or free, all we need is the IP address and the credentials to connect over.

The concept of ‘Running Flask with an SSH Remote Python Interpreter’ will be used and the steps are shown below.

You can always use an existing project, or the development can be started from scratch in the virtual machine that has been configured itself. 

Steps for setting up Azure DSVM free using GIT hub student pack 

1. After signing in with the free subscription for students in Azure, go to the Azure portal and type, data science virtual machine and choose Ubuntu version.

2. Then before reviewing and creating the DSVM with the default settings, select 

3. After the DSVM has been created successfully, go to the ‘Networking’ tab, and click ‘Add inbound port rule’ and enable the port 5000 as given below and assign a priority value.

After adding the new inbound port rule, it should look like the diagram given below

4. Now start or re-start your VM with the newly added network configuration.

Note: Always remember to stop your VM, if not being used, in order to make the maximum use of the free credit allowed.

For more info. On setting up DSVM: https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/provision-vm

Steps for setting up the IDE for remote development

1. Configuring remote Python interpreter via SSH credentials https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html#135862

2. Tools -> Deployment -> Configuration

3. Enter server/ VM IP and credentials and test connection.

At this point if it shows the SSH Security Warning dialog box, you can always ‘Yes’ Accept it if you are sure that it is your connection and get connected successfully.

4. Choose the path to the folder where you need to create or run an already existing flask application project using the “Mappings” tab.

For running a locally existing project in the VM newly, you need to upload the project to the remote VM first.

And the option to sync the files with the remote VM is also possible, if you haven’t auto enabled it, for every edit.

And After uploading and syncing your project with the remote VM, you can use the IDEs’ Run button to run the project in your VM.

Go to Run -> Edit Configurations and make sure you have already set the python interpreter to be from the VM you use, as we have approached in the beginning, in the documentation provided by JetBrains.

Now that all the configurations are done, utilizing the IP of your VM, The API endpoints in the Flask app can be accessed from anywhere, and Postman is another tool that can be used to test the APIs as unit tests.