How AWS can help you jump start your AI journey?

The Hype is real!!! If you still think AI is the future then you are mistaken, AI is the present.

Amazon Web Services (AWS) SageMaker Studio

ChatGPTGenerative AI– you might have heard these words pop-up in many online articles, social media trends, news articles etc.,

Generative AI describes AI algorithms which can learn from vast amounts of existing data points and create new data. It can generate text, images, video and audio. One application of Generative AI algorithms is ChatGPT.

ChatGPT is a Generative AI based platform (subset of AI) trained on terabytes of data to generate new and close to original content, it works so well that it becomes hard to distinguish whether the content created or conversation you are having is coming from a person or machine. While this article is not about ChatGPT but it definitely shows the benefits that businesses and individuals can reap from Generative AI. You can learn more about Generative AI from these articles by McKinseyBCG & Gartner.

Usecases of Generative AI are growing at fast pace and it is important that you step into the waters to try this technology and see how it can help you or your business grow.

Usecases of Generative AI

  1. Improved chatbots or virtual assistants.
  2. Create code for your applications, code review, bug fixes.
  3. Create summarized content for marketing campaigns, webpages etc.
  4. Generate media (Audio, Video or Images).
  5. Brainstorming product ideas or designs.

The usecases are growing each day. Check this post written by Cem Dilmegani for more use cases based on Generative AI.

How to get started with Generative AI using AWS SageMaker

To build sophisticated AI products such as ChatGPT, data is crucial and we need a lot, I mean massive amounts of data to train our programs. Cost is also a big factor as the amount of compute power you would need to train your ML program is really expensive.

AWS SageMaker JumpStart provides public or proprietary Foundation Models (pre trained ML models on vast amounts of data) and you can tune them to fit your use case at a lower cost.

AWS SageMaker Studio Setup

1. To get started, create your Amazon Web Services account here. If you already have one, login to continue with next steps.

Amazon Web Services (AWS) Sign in Page

2. Search for SageMaker and go to the service.

Amazon Web Services (AWS) Console Home
Amazon Web Services (AWS) SageMaker Service Page

3. To setup SageMaker environment, we should first create a “Domain”. To create domain, Click Domain -> Create Domain.

SageMaker Domain — A domain includes an associated Amazon Elastic File System (EFS) volume; a list of authorized users; and a variety of security, application, policy, and Amazon Virtual Private Cloud (VPC) configurations. Each user in a domain receives a personal and private home directory within the EFS for notebooks, Git repositories, and data files.

4. In the Setup SageMaker Domain page, Select Quick Setup option, Give the domain a name (ex: sagemakerdomain) and a name for user profile (ex: SageMakerUser). Select “create a new role” option under execution role, this role will be utilized by the users in this domain.

Amazon Web Services (AWS) SageMaker Domain

5. In the “Create an I AM role” pop-up, select “Any S3 bucket” and click “Create role”.

Amazon Web Services (AWS) SageMaker Domain

6. A new execution role will be created and click create domain (it will take few minutes for domain to be created and ready for use).

Amazon Web Services (AWS) SageMaker Domain

7. Once domain is ready, you can find it in the domains section. Click on the newly created domain.

Amazon Web Services (AWS) SageMaker Domain

8. In the domain, go to “User Profile” tab and click on “Launch -> Studio” with the new user created during domain setup.

Amazon Web Services (AWS) SageMaker Domain

9. It may take a while for SageMaker Studio to initialize. (If you see any error screen asking to clear workspaces, closing any other tabs like Jupiter notebooks, SageMaker studio labs etc., and reload- that did work for me ;)

Amazon Web Services (AWS) SageMaker Studio

10. Once SageMaker Studio is ready for use, you land into it’s home screen. Select “SageMaker JumpStart -> Models” option.

Amazon Web Services (AWS) SageMaker Studio

11. You can see multiple ML options from end-to-end solutions, foundation models, vision models etc., For this demo we are going to use a foundation model to (text2text generation) generate text responses based on our input and (text2image generation) image generation based on text input.

Amazon Web Services (AWS) SageMaker JumpStart

Generate Text Responses based on Text Input (TEXT To TEXT Generation)

1. There are hundreds of options to select from but for the sake of this demo and to get you familiar with JumpStart service, search for “Flan-T5 XL” and click view model.

Generative AI Text Generation using Amazon Web Services (AWS) SageMaker JumpStart

2. On model tab you can read the details about how the model works, deployment configuration, security configuration. You can leave the defaults as is for the demo purpose. Click “Deploy”.

Generative AI Text Generation using Amazon Web Services (AWS) SageMaker JumpStart

3. It may take a while for SageMaker to deploy the model and setup the endpoint for inference.

Generative AI Text Generation using Amazon Web Services (AWS) SageMaker JumpStart

4. Once the endpoint is ready, you can access to use the endpoint from a notebook inside studio itself. To start querying your endpoint, click on “Open Notebook”.

Generative AI Text Generation using Amazon Web Services (AWS) SageMaker JumpStart

5. It should open a new notebook with details on how to run inference on the endpoint we just created. For a quick trial you can run the cells (select the cell and click on play button above to execute the code from the selected cell).

Generative AI Text Generation using Amazon Web Services (AWS) SageMaker JumpStart
Generative AI Text Generation using Amazon Web Services (AWS) SageMaker JumpStart

6. You can replace the input text text1 & text2 to any other text query and run it again with endpoint.

Generate Image based on Text Input (TEXT To IMAGE Generation)

1. Go back to SageMaker JumpStart or click on the models, notebooks and Solutions option under SageMaker JumpStart On left pane of the screen.

Generative AI Image Generation using Amazon Web Services (AWS) SageMaker JumpStart

2. Search for “Stable Diffusion 2.1 base” model and click view model.

Generative AI Image Generation using Amazon Web Services (AWS) SageMaker JumpStart

3. Once again repeat the steps 2–4 as mentioned in the text 2 text generation endpoint deployment above.

4. Open notebook once the endpoint is ready. Run cells (select the cell and click on play button above to execute the code from the selected cell).

Generative AI Image Generation using Amazon Web Services (AWS) SageMaker JumpStart

5. You can replace the input text/argument for “query_endpoint” function to any other text and run it again with endpoint.

Embedding into your application

1. Go to “Inference -> Endpoints” and select endpoint to get the API for the model we just deployed. Using the API you can run the inference programmatically.

Resource Cleanup

1. Go back to respective model tabs where we created endpoints. Select “delete” the endpoint.

Amazon Web Services (AWS)

2. If you have closed that tab, go back to the SageMaker dashboard in AWS, click “endpoints” under “Inference” option. select the endpoint and click “Actions -> Delete”.

Amazon Web Services (AWS)

3. Repeat the same steps for models under “Inference -> Models”.

4. To delete the domain we must first the delete the user profile & any apps associated with the user profile. Go to “Domains -> select the created domain -> select User profile tab -> select the created user -> delete the apps”.

Amazon Web Services (AWS)

5. Once all apps are deleted, click edit on the bottom right side and go ahead with deleting the user.

6. After deleting the user, go to edit option on the domain and delete the domain.

7. You can continue to remove other artifacts like S3 buckets, roles, policies, EFS volume created by SageMaker.

Conclusion

Hope this demo helped you start your Generative AI or AI journey in general using Amazon Web Services (AWS). Foundation models in AWS also provides option to train the model using your data sets to fit to your business cases.

Written by Sai Sameer Syed, Senior Software Engineer at Ness Digital Engineering