DEV Community

Cover image for Amazon Bedrock on EC2 Visual Studio LLM Project
Enrique Aguilar Martinez
Enrique Aguilar Martinez

Posted on

Amazon Bedrock on EC2 Visual Studio LLM Project

Amazon Bedrock is a service offered by Amazon Web Services (AWS) to facilitate the development of Generative AI applications.
Context.
Generative artificial intelligence (Generative AI) plays a critical role in Amazon Bedrock, enabling developers to create applications with breakthrough capabilities that were previously impossible. But what is generative AI? Generative AI is a type of artificial intelligence that can create new content and ideas, including conversations, stories, images, videos and music, and helps us innovate.

Like all artificial intelligence, this one works with machine learning or ML models. However, Generative AI is powered by very, very large models that are pre-trained on large collections of data and are known as base models or fundamental models (FM). Recent advances in machine learning have led to the emergence of fundamental models containing billions of parameters or variables. Recent advances in generative artificial intelligence (generative AI) have been largely driven by processors.

Within Amazon Web Services (AWS), unprecedented computing power is offered. Among the main ones are the Trainium2 and Graviton4 processors, developed for machine learning scenarios and execution of AI-based applications, these solutions are based on ARM architecture.
Amazon Trainium2 – This is a custom-designed AI accelerator chip built by Amazon specifically for training large machine learning models, particularly core models (FM) and large language models (LLM) with trillions of parameters. Trainium2 stands out for accelerating the training process of these complex models.

Image description
Graviton4 is a powerful CPU architecture designed by Amazon specifically for its cloud services and can benefit Amazon Bedrock in several ways:
• Improved cost-effectiveness: Graviton4 processors offer a better price-performance ratio compared to previous generations.

This means that running generative AI applications on Amazon Bedrock models powered by Graviton4 could potentially be more cost-effective.
• Possible performance gains for specific tasks: While Graviton4 is not designed specifically for AI training like Trainium2, some generative AI tasks within Amazon Bedrock applications could benefit from its performance improvements.
This could include tasks that rely heavily on general computing power rather than specialized AI acceleration.
• Trainium2 delivers up to 50% training cost savings over comparable Amazon EC2 instances and is designed for machine learning workloads.

Trainium2 was built to train and deploy ultra-large Generative AI models with hundreds of miles of millions of parameters. In short, Generative AI fits into companies' existing and future business and operating models, as well as productively experimenting with Generative AI use cases.

The combination of scalable cloud computing power, foundational AI models, and AWS's ongoing commitment to technical excellence offers businesses and developers an exceptional platform to drive project creativity, efficiency, and innovation. of companies, generating long-term opportunities resulting from innovative trends.

This is how Amazon Bedrock can develop wide margins of creation and deployments in large projects through Generative AI. AI Agents at Amazon Bedrock AI agents in Amazon Bedrock are crucial for the following reasons.

They accelerate the development of generative AI applications:
• They allow you to create generative AI applications without the need for complex coding, saving time and resources.
• Users can create agents simply by describing their goals in natural language, Amazon Bedrock takes care of the orchestration and execution.
They expand the capabilities of generative AI:
• Agents can connect to enterprise systems and data sources, allowing them to access and process real-world information.
• This allows them to perform more complex tasks and generate more precise and personalized responses.

Improve efficiency and productivity:
• Agents can automate tasks previously performed by humans, freeing up time for humans to focus on more strategic activities.
• They can also improve task accuracy and consistency, reducing errors and rework.
They promote innovation:
• By making it easy to build generative AI applications, Bedrock empowers businesses to explore new ideas and solutions.
• This can lead to the development of new products, services and business models. Amazon Bedrock and its AI agents are catalysts for business innovation, offering a path to efficiency, personalization and intelligent decision making, driving growth and success in today's technology-driven world. In the next installment we will see more about Amazon Bedrock.

Image description
Let's go straight to the project:

Prerequisites
An AWS account
Visual Studio Code installed on your system

AWS IAM Setup

  1. Create an IAM Group :
    o Navigate to IAM in AWS and create a new group named demo.
    o Add BedrockReadOnlyAccesspermission to the group.

  2. Create Custom IAM Policies :
    o Create an inline policy for the demogroup that includes readinvokepermissions for Bedrock models.

  3. Create a Service Account :
    o Create a user named svc-bedrockand add it to the demogroup.

  4. Generate API Keys :
    o Navigate to serviceBedrocksecuritycredentialsand create
    new access keys.

Configure Access to Bedrock Models

  1. Access Bedrock in the AWS Console :
    o Go to the Bedrock service and navigate to Model Access.

  2. Manage model access:
    o Select and add the models you want to access, such as llama, Amazon titan, Anthropic, etc.

Set up local environment

  1. Set up AWS credentials:
    o Edit the .aws/credentials file with the access key and secret key obtained above.

  2. Set region settings:
    o Modify the .aws/config file to specify the desired AWS region.

Developing the application

  1. Setup in Visual Studio Code:
    o Open Visual Studio Code and prepare the application that will invoke the AI ​​models.

  2. Use Bedrock Helper:
    o Implement a helper module to manage the invocation of different AI models with different parameters.

  3. Invoke AI models:
    o Run the application to invoke AI models and process their responses.

first step git clone
git clone https://github.com/EnriqueAguila/Amazon-Bedrock-on-EC2_Visual-Studio-LLM-Project.git

aws configure

In the webserver folder you right click to create Newfolder
You put websites
In the terminal you put:

cd bedrock-main

docker network create donut-net

pip install virtualenv

python -m venv ./venv

. venv/bin/activate

It appears in the root at the beginning of the line (venv)

git clone https://github.com/EnriqueAguila/Amazon-Bedrock-on-EC2_Visual-Studio-LLM-Project.git

cd Amazon-Bedrock-----

cd bedrock-main

pip install boto3

pip install rich

python app.py

In the file line 20 you change the prompt again

python app.py

Starting bedrock.py comes out, the text sausage comes out and you apply this command:

python autorun.py

Select a model comes out:
you press 3 or 5
it asks you:

Why is sky blue?

And it answers

python manage.py migrate

chmod -R a+w ../donutwebsite

You can check my repo to extract the code:
https://github.com/EnriqueAguila/Amazon-Bedrock-on-EC2_Visual-Studio-LLM-Project/tree/main

The complete course on this exercise will be available soon on Udemy.
Enrique Aguilar Martinez
AI Engineer Azure.

Top comments (0)