Study notes: Using Amazon Bedrock for image generation

Amazon Bedrock New Release

At the 2023 Amazon Cloud Technology re:Invent global cloud computing conference, one of the most eye-catching updates is the new upgrade of Amazon Bedrock. Amazon Cloud Technology has introduced a series of innovative features such as Fine-tuning, Agents, Knowledge Bases and Guardrails to its large model hosting service this time. The addition of these features means that customers can now build various applications in a more efficient, intelligent and secure way, marking an important new step for Amazon Cloud Technology in promoting industry progress and serving customers.

Amazon Bedrock is a fully managed service that helps you build generative AI applications using foundational models from AI leaders like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon. Amazon Bedrock is now officially launched on September 28, 2023. In the latest announcement, you can now access Llama 2 and Meta’s large language models through the Amazon Bedrock API, as well as using the AWS CLI. AWS announced Amazon Bedrock in public preview in April 2023 and at AWS re:Inforce 2023 with a talk on Securely Building Generative AI Applications and Controlling Data with Amazon Bedrock (APS208).

Learning goal identification

  • Amazon Bedrock feature exploration
  • Amazon Bedrock Benefits Defined
  • Common use cases for Amazon Bedrock
  • Solution architecture and pricing for Amazon Bedrock
  • Amazon Bedrock’s real-world industry applications use the AWS Management Console to generate images;

Why choose Amazon Bedrock?

  • Amazon Bedrock is serverless, which means you don’t need to manage any IT infrastructure
  • You can try the base model without writing any code.
  • You can use your own data and customize the base model through fine-tuning or Retrieval Augmentation Generation (RAG), and use agents to perform complex business tasks.

What are the benefits of Amazon Bedrock?

  • You can access foundational models from leading AI companies such as AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon, use Playground to experiment to build generative AI applications, and use the Amazon Bedrock API for inference.
  • You can customize the base model with your own dataset and upload that dataset to Amazon S3 for training and testing.
  • Agents can be built to perform complex business tasks HIPAA eligibility and GDPR compliance Amazon Bedrock data security ensures your data in transit and at rest is encrypted, allowing access keys. Amazon statement:
  • You can use AWS PrivateLink with Amazon Bedrock to establish a private connection between FM and Amazon Virtual Private Cloud (Amazon VPC) without exposing traffic to the Internet.

What are the features of Amazon Bedrock?

Below is an overview of Amazon Bedrock.

These features are outlined in the Amazon Bedrock User Guide and include: Text Playground – a useful text generation application in the AWS Management Console. Image Playground – Practical image generation application in the console.

Chat Playground – A hands-on conversation generation application using a console. Embeddings – Use the API to generate embeddings from Titan Embeddings G1 – Text models. Example Library You can explore example cases from the Example Library.

What is the pricing for Amazon Bedrock?

Amazon Bedrock has two pricing models:

  • On-demand pricing:
    • Text generation models: You pay for each input token processed and for each output token generated.
    • Embedded model: You pay for each input token processed. A token consists of several characters and refers to the basic unit by which the model learns to understand user input and prompts for generated results.
    • Image generation: You pay for the number of images generated.
  • Provisioned throughput pricing:
    You pay a time commitment based on the purchased throughput to run inference on your model. Amazon recommends provisioned throughput for large workloads. With Amazon Bedrock pricing, you can pay to run inference on any third-party base model. Pricing is based on the number of input tokens and output tokens, and whether you purchase provisioned throughput for the model. Provisioned throughput is charged by the hour, and you have the flexibility to choose a 1-month or 6-month commitment period.Base Models Base Models There are a variety of base models to choose from, and these are subject to change.Currently, the following models are accessible:
    • AI21 Labs: Jurassic-2 Mid, Jurassic-2 Ultra
    • Amazon: Titan Text Lite, Titan Text Express, Titan Text Embeddings
    • Anthropic: Claude Instant, Claude
    • Cohere: Command, Command-Light, Embed – English, Embed – Multilingual
    • Meta Llama 2: Llama 2 Chat (13B), Llama 2 Chat (70B)
    • Stability AI: SDXL 0.8, SDXL 1.0

Custom Models You can also bring in your own dataset and customize the model with hyperparameters epoch, batch size, learning rate, and warm-up steps to fine-tune the model. You can build a base model using training data and deploy fine-tuned models using the Amazon Bedrock API.

What are some common use cases?

  • Text generation, such as writing papers and blog posts Virtual assistants, such as accepting user requests and performing tasks
  • Chatbot: for asking and answering questions
  • Search, such as searching for information from a document
  • Text summaries such as summarizing the topic of a book or document
  • Image generation, such as generating realistic photos for property brochures What are some real-world industry applications?

Image generation tutorial

Tutorial: Get started with Amazon Bedrock with Image Playground

Step 1: Navigate to the AWS Management Console. Log in to your AWS account as the IAM administrator user.

Step 2: In this tutorial, we will use the AWS Region Northern Virginia (US-east-1).

Step 3: Enter the word “Bedrock” in the search bar, navigate to the Amazon Bedrock console and click Get Started.

Step 4: Request model access. Navigate to the third-party provider of the underlying model (such as Stability AI) and select Edit Access. Check the box to select a base model and request access. It will take a few minutes to gain access. Refresh your browser.

I chose the base model of Stable Diffusion XL-Preview from Stability AI.

Step 5: Navigate to “Images” to select the image playground to start the prompt. Select the image in the left pane.

Enter a word in natural language to get a prompt. You can enter a few words into the box, such as Sydney Opera House Real Summer. It takes a few seconds to create the image.

On the right side of the image playground, you can adjust the slider to update the inference configuration and thus change the output quality of the generated images.

Step 6: You can also download the generated images and use them in your projects such as blog posts, newsletters, postcards, documents, magazines, etc.

Step 7: Clean up resources As a best practice, if you no longer need to generate images from the base model, remove the third-party base model provided by clicking Edit, unchecking the box for “Stability AI”, and then selecting “Save” Provider’s model access permissions to clean up your resource changes.

Summarize

In the process of writing this study note, I worked hard to explore many features of Amazon Bedrock. I tried to understand the convenience of being a fully managed service and the advantages of serverless architecture and learned as much as I could about leveraging foundational models from leading companies like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, etc. and tried Process image generation, text generation, and other complex business tasks with Amazon Bedrock.

At the same time, I also learned about its pricing structure, the underlying models it supports, and dug as deep as I could into how to deploy and fine-tune models using the Amazon Bedrock API.

This note records my journey of understanding Amazon Bedrock. I hope it can also help me in my future technological exploration and innovation. I look forward to more tutorials and updates on Amazon Bedrock. I will keep learning and recording.

This article participated in the “Building” to the Cloud | Amazon Cloud Technology x Sifou 2023 re:Invent Builder Essay Contest . You who are reading are welcome to join.

Authorization statement: This article authorizes the official Amazon Cloud Technology article to forward and rewrite the rights, including but not limited to Amazon Cloud Technology official channels such as Developer Centre, Zhihu, self-media platforms, third-party developer media, etc.