The Hype is real!!! If you still think AI is the future then you are mistaken, AI is the present.
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 McKinsey, BCG & 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
- Improved chatbots or virtual assistants.
- Create code for your applications, code review, bug fixes.
- Create summarized content for marketing campaigns, webpages etc.
- Generate media (Audio, Video or Images).
- Brainstorming product ideas or designs.
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 Studio Setup
1. To get started, create your Amazon Web Services account here. If you already have one, login to continue with next steps.
2. Search for SageMaker and go to the service.
3. To setup SageMaker environment, we should first create a “Domain”. To create domain, Click Domain -> Create Domain.
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.
5. In the “Create an I AM role” pop-up, select “Any S3 bucket” and click “Create role”.
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).
7. Once domain is ready, you can find it in the domains section. Click on the newly created domain.
8. In the domain, go to “User Profile” tab and click on “Launch -> Studio” with the new user created during domain setup.
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 ;)
10. Once SageMaker Studio is ready for use, you land into it’s home screen. Select “SageMaker JumpStart -> Models” option.
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.
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.
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”.
3. It may take a while for SageMaker to deploy the model and setup the endpoint for inference.
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”.
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).
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.
2. Search for “Stable Diffusion 2.1 base” model and click view model.
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).
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.
1. Go back to respective model tabs where we created endpoints. Select “delete” the endpoint.
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”.
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”.
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.
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