<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: bismillahkani</title>
    <description>The latest articles on Forem by bismillahkani (@bismillahkani).</description>
    <link>https://forem.com/bismillahkani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1033585%2F8e515b90-04ef-4f19-b514-aae6cc12a876.png</url>
      <title>Forem: bismillahkani</title>
      <link>https://forem.com/bismillahkani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bismillahkani"/>
    <language>en</language>
    <item>
      <title>Architecting MLOps for Computer Vision using AWS Sagemaker</title>
      <dc:creator>bismillahkani</dc:creator>
      <pubDate>Mon, 29 Jan 2024 08:48:59 +0000</pubDate>
      <link>https://forem.com/aws-builders/architecting-mlops-for-computer-vision-using-aws-sagemaker-1j6g</link>
      <guid>https://forem.com/aws-builders/architecting-mlops-for-computer-vision-using-aws-sagemaker-1j6g</guid>
      <description>&lt;p&gt;In this post, we will dive into the world of Machine Learning Operations (MLOps) and explore how it can revolutionize the process of creating, deploying, and managing machine learning models. We will also walk you through a practical use case involving computer vision to demonstrate the real-world application of MLOps principles and how AWS SageMaker plays a pivotal role in streamlining this journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is MLOps?
&lt;/h2&gt;

&lt;p&gt;Let's start with the basics. MLOps, short for Machine Learning Operations, is all about making the process of creating, deploying, and managing machine learning models as smooth and efficient as possible. It's like taking the principles of DevOps, which helps streamline software development, and applying them to the world of machine learning. Imagine it as the smart engine that powers the lifecycle of machine learning, making it easier to build and deploy intelligent solutions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frx48jdavlopuwl6uay0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frx48jdavlopuwl6uay0g.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://neptune.ai/blog/mlops" rel="noopener noreferrer"&gt;https://neptune.ai/blog/mlops&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's break down MLOps into four key principles that guide us through this journey. First, we have 'Version control,' which is like keeping track of changes in our machine learning assets, just like you would with documents. Next, there's 'Automation,' think of it as creating repeatable and consistent processes using ML pipelines to make your work smoother. Then, 'Continuous X' is all about continuous training and deployment of models, ensuring they stay up to date. Lastly, 'Model governance' is like having a structured process to review and validate our models, making sure they're reliable. As for the three levels of MLOps implementation, think of them as steps in our journey. Level 0 is the manual phase, where everything is done by hand. Level 1 brings in continuous model training through pipelines. And Level 2, that's the gold standard, where we cover everything from data collection, training, all the way to deployment, creating a seamless MLOps process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use case
&lt;/h2&gt;

&lt;p&gt;Before we delve into MLOps, consider this practical scenario: improving quality control in a metal luggage tag manufacturing line using machine learning. Our goal is to detect defects like scratches in real-time, whether on the edge for immediate monitoring or in a cloud environment like AWS SageMaker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F785z55sxnob7297xhk18.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F785z55sxnob7297xhk18.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://aws.amazon.com/blogs/machine-learning/" rel="noopener noreferrer"&gt;https://aws.amazon.com/blogs/machine-learning/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MLOps pipeline
&lt;/h2&gt;

&lt;p&gt;Now, let's outline the architecture of our MLOps pipeline. At this stage, we're focusing on the big picture, not specific technologies. Our goal is to automate the entire process, starting with capturing raw images of metal tags using an edge camera. We then label these images with bounding boxes, ensuring version control for traceability. Next, we train, fine-tune, and evaluate the model before deploying it, either at the edge for real-time inferences or in the cloud with AWS SageMaker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frjhrmtlj8gewuvc9sej2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frjhrmtlj8gewuvc9sej2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MLOps Solution Architecture
&lt;/h2&gt;

&lt;p&gt;Let's now take a closer look at how we can build our architecture using AWS services. We've designed a workflow that seamlessly integrates these services to optimize our MLOps pipeline. We start by storing raw image data in Amazon S3 for cost-efficiency. Next, we orchestrate the labeling process with AWS Step Functions and SageMaker Ground Truth, leveraging AWS Lambda for data preparation. For model training and evaluation, we rely on SageMaker Pipelines, SageMaker Training jobs, and SageMaker Processing jobs. The trained model is registered in Amazon SageMaker Model Registry for management and version control. For edge deployment, we automate the process with Step Functions and utilize AWS IoT Greengrass as our edge device runtime environment. Alternatively, we can deploy the model as SageMaker endpoints in the cloud for flexibility. This architecture minimizes operational effort by leveraging managed and serverless services while maintaining the integrity of our MLOps pipeline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Factb0tmsix9kewny0g2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Factb0tmsix9kewny0g2d.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CI/CD pipeline
&lt;/h2&gt;

&lt;p&gt;Now, let's explore how we integrate our data labeling, model training, and edge deployment steps into a fully automated CI/CD system using AWS services. We begin with AWS CodeCommit as our Git repository and use the AWS CDK to automate infrastructure deployment, allowing for independent deployments of each part. AWS CodePipeline is utilized to automate both code and infrastructure deployments, and we have separate pipelines for assets and workflows. This setup ensures that changes in our code or data trigger the orchestration process, making our end-to-end pipeline responsive to updates and data modifications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbmp6dnjcks4qim8m5wuv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbmp6dnjcks4qim8m5wuv.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Orchestrating Data Labelling
&lt;/h2&gt;

&lt;p&gt;We employ AWS Step Functions to automate our labeling pipeline, which comprises four major steps. These steps include checking for new images, data preparation, initiating labeling and label verification jobs, and writing the final labels to the feature store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokmhpoci0x3xe83lw59z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokmhpoci0x3xe83lw59z.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Orchestrating Model Training
&lt;/h2&gt;

&lt;p&gt;In this workflow, we have three key steps: data processing, model training, and model registration. First, data is loaded and split, then the model is trained and evaluated for mAP. If it meets the threshold, the model is registered in the SageMaker Model Registry.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8azmkbn1rfwzoknwz4le.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8azmkbn1rfwzoknwz4le.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Model deployment
&lt;/h2&gt;

&lt;p&gt;After training and evaluation, deploying an ML model for real-world impact is crucial. Continuing our journey, we now turn our attention to automating the edge deployment phase in our end-to-end MLOps pipeline. There are two approaches for model deployment: one is IoT Greengrass for real-time edge inference, but today, due to time constraints, we'll focus on the second approach, AWS SageMaker endpoints, which offers a more straightforward deployment process. We've ensured portability and optimization by exporting the model in ONNX format and registering it in Amazon SageMaker Model Registry. Our deployment package consists of the trained model in ONNX format, and alongside it, we've implemented a private component for inference code. This component handles data preparation, communication with the model, and post-processing of results to ensure seamless and effective model deployment in production systems.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2e1oxbxg76w8dgn7t19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2e1oxbxg76w8dgn7t19.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;MLOps streamlines machine learning by applying DevOps principles, featuring version control, automation, continuous training, and model governance. We explored applying MLOps principles to an industrial computer vision use case, improving quality control in luggage tag manufacturing. Leveraging AWS services, we created an efficient MLOps pipeline, managing data, labeling, training, and deployment seamlessly. Through automated CI/CD using AWS tools, we ensure responsiveness to code and data changes throughout the end-to-end pipeline, ensuring efficiency and flexibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/machine-learning/build-an-end-to-end-mlops-pipeline-for-visual-quality-inspection-at-the-edge-part-1/" rel="noopener noreferrer"&gt;https://aws.amazon.com/blogs/machine-learning/build-an-end-to-end-mlops-pipeline-for-visual-quality-inspection-at-the-edge-part-1/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/machine-learning/build-an-end-to-end-mlops-pipeline-for-visual-quality-inspection-at-the-edge-part-2/" rel="noopener noreferrer"&gt;https://aws.amazon.com/blogs/machine-learning/build-an-end-to-end-mlops-pipeline-for-visual-quality-inspection-at-the-edge-part-2/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/machine-learning/build-an-end-to-end-mlops-pipeline-for-visual-quality-inspection-at-the-edge-part-3/" rel="noopener noreferrer"&gt;https://aws.amazon.com/blogs/machine-learning/build-an-end-to-end-mlops-pipeline-for-visual-quality-inspection-at-the-edge-part-3/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>ai</category>
      <category>mlops</category>
      <category>sagemaker</category>
    </item>
    <item>
      <title>When Generative AI meets AWS Community Builders : Unveiling the Ultimate AWS Cost Advisor</title>
      <dc:creator>bismillahkani</dc:creator>
      <pubDate>Fri, 30 Jun 2023 10:18:35 +0000</pubDate>
      <link>https://forem.com/aws-builders/aws-cost-advisor-cb-ai-hackathon-44ck</link>
      <guid>https://forem.com/aws-builders/aws-cost-advisor-cb-ai-hackathon-44ck</guid>
      <description>&lt;p&gt;&lt;em&gt;Building a &lt;a href="https://ai.facebook.com/blog/retrieval-augmented-generation-streamlining-the-creation-of-intelligent-natural-language-processing-models/" rel="noopener noreferrer"&gt;Retrieval Augmented Generation (RAG)&lt;/a&gt; Pipeline with AWS SageMaker, Hugging Face Transformer and Langchain&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffrrsjp0b12lyaannxw6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffrrsjp0b12lyaannxw6s.png" alt="Image description" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AWS Community Builders&lt;/strong&gt; gave us an interesting opportunity to work on Integrating AI tools and solve AWS use-cases.&lt;/p&gt;

&lt;p&gt;This unique collaboration sparked our collective imagination, leading us to brainstorm the (perfect) solution. After countless hours of innovation and collaboration, we are thrilled to unveil this groundbreaking tool that will redefine AWS Cost Savings and FinOps landscape: a Q&amp;amp;A Chatbot powered by Sagemaker, HuggingFace, LangChain, and supercharged with Retrieval Augmented Generation. Join us on this captivating journey as we present our revolutionary solution that harmonizes the worlds of generative AI and AWS Solution Architect skills&lt;/p&gt;

&lt;p&gt;AWS Cost Advisor is an AI tool that is designed to help users optimize their cloud costs by providing cost recommendations, identifying cost anomalies, and offering cost-saving suggestions. The tool is built using Retrieval-Augmented Generation (RAG), a combination of retrieval-based and generation-based techniques. The knowledge database of the AWS Cost Advisor is built using AWS Cost Management FAQs as a vector database that is integrated into the RAG pipeline. In this blog post, we will demonstrate the Cost Advisor tool and its improved performance as compared to a generic text generation Q&amp;amp;A assistant.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;The AWS Cost Advisor tool was designed to help users optimize their cloud costs by providing cost recommendations, identifying cost anomalies, and offering cost-saving suggestions. However, the tool was facing a problem of accuracy and relevancy of the answers provided by the tool. The generic text generation Q&amp;amp;A assistant would often provide irrelevant answers or not answer the user's question at all. To solve this problem, we implemented the RAG pipeline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmz5fjvbzzirqr1nzpd5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmz5fjvbzzirqr1nzpd5.png" alt="Image description" width="687" height="1031"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;No more Unnecessary Cash Burn&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Available Solutions:
&lt;/h2&gt;

&lt;p&gt;Before we delve into our groundbreaking solution, let's explore the existing options. Conventional cost optimization tools often lack the sophistication to comprehensively analyze complex billing data and provide granular insights. Additionally, chatbots typically struggle to handle the intricacies of AWS services and generate meaningful recommendations. These limitations hinder Solution Architect's progress, making it challenging to unlock the full potential of savings in the Cloud.&lt;/p&gt;

&lt;p&gt;Existing solutions like Cost Explorer, AWS Budgets, can feel lot like DIY&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxoodquwdixtrfr1j4xa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxoodquwdixtrfr1j4xa.png" alt="Image description" width="800" height="551"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Tools, tools, and lot of knobs and levers everywhere&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Retrieval-Augmented Pipeline
&lt;/h2&gt;

&lt;p&gt;The RAG pipeline uses a combination of retrieval-based and generation-based techniques to provide more relevant and accurate answers. The pipeline consists of three components: a retriever, a reader, and a generator. The retriever retrieves the most relevant documents from the knowledge database, the reader extracts the answer from the retrieved documents, and the generator generates a more concise and accurate answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq4nkjbyo5nlnuge35umi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq4nkjbyo5nlnuge35umi.png" alt="Image description" width="800" height="410"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Solution Architecture&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  High level solution overview
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://huggingface.co/" rel="noopener noreferrer"&gt;Huggingface&lt;/a&gt; Open-Source LLM Models&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Huggingface open-source large language models (LLMs) are used by AWS Cost Advisor for the generation-based component of the Retrieval-Augmented Generation (RAG) pipeline. These models are pre-trained on large amounts of text data and can generate high-quality responses to natural language questions. Huggingface LLM models are hosted as &lt;a href="https://aws.amazon.com/sagemaker/" rel="noopener noreferrer"&gt;Sagemaker &lt;/a&gt;endpoints.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MODEL_CONFIG = {
    "huggingface-text2text-flan-t5-xxl": {
        "instance type": "ml.g4dn.xlarge",
        "env": {"SAGEMAKER_MODEL_SERVER_WORKERS": "1", "TS_DEFAULT_WORKERS_PER_MODEL": "1"},
        "parse_function": parse_response_model_flan_t5,
        "prompt": """Answer based on context:\n\n{context}\n\n{question}""",
    },
    "huggingface-textembedding-gpt-j-6b": {
        "instance type": "ml.g4dn.2xlarge",
        "env": {"SAGEMAKER_MODEL_SERVER_WORKERS": "1", "TS_DEFAULT_WORKERS_PER_MODEL": "1"},
    },
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newline, bold, unbold = "\n", "\033[1m", "\033[0m"

for model_id in _MODEL_CONFIG_:
    endpoint_name = name_from_base(f"aws-costadvisor-rag-{model_id}")
    inference_instance_type = _MODEL_CONFIG_[model_id]["instance type"]

    # Retrieve the inference container uri. This is the base HuggingFace container image for the default model above.
    deploy_image_uri = image_uris.retrieve(
        region=None,
        framework=None,  # automatically inferred from model_id
        image_scope="inference",
        model_id=model_id,
        model_version=model_version,
        instance_type=inference_instance_type,
    )
    # Retrieve the model uri.
    model_uri = model_uris.retrieve(
        model_id=model_id, model_version=model_version, model_scope="inference"
    )
    model_inference = Model(
        image_uri=deploy_image_uri,
        model_data=model_uri,
        role=aws_role,
        predictor_cls=Predictor,
        name=endpoint_name,
        env=_MODEL_CONFIG_[model_id]["env"],
    )
    model_predictor_inference = model_inference.deploy(
        initial_instance_count=1,
        instance_type=inference_instance_type,
        predictor_cls=Predictor,
        endpoint_name=endpoint_name,
    )
    print(f"{bold}Model {model_id} has been deployed successfully.{unbold}{newline}")
    _MODEL_CONFIG_[model_id]["endpoint_name"] = endpoint_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;a href="https://python.langchain.com/docs/get_started/introduction.html" rel="noopener noreferrer"&gt;Langchain&lt;/a&gt; Retrieval QA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Langchain Retrieval QA is used by AWS Cost Advisor as the retrieval-based component of the RAG pipeline. This tool is designed to retrieve the most relevant documents from the knowledge database based on the user's query. Langchain Retrieval QA uses a combination of semantic search and keyword matching to retrieve the most relevant documents, ensuring that the retrieved documents are highly relevant to the user's query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://aws.amazon.com/aws-cost-management/faqs/" rel="noopener noreferrer"&gt;AWS Cost Management FAQs&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Answer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Who should use the AWS Cost Management products?&lt;/td&gt;
&lt;td&gt;We have yet to meet a customer who does not consider cost management a priority. AWS Cost Management tools are used by IT professionals, financial analysts, resource managers, and developers across all industries to access detailed information related to their AWS costs and usage, analyze their cost drivers and usage trends, and take action on their insights.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How do I get started with the AWS Cost Management tools?&lt;/td&gt;
&lt;td&gt;The quickest way to get started with the AWS Cost Management tools is to access the Billing Dashboard. From there, you can access a number of products that can help you to better understand, analyze, and control your AWS costs, including, but not limited to, AWS Cost Explorer, AWS Budgets, and the AWS Cost &amp;amp; Usage Report.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What are the benefits of using AWS Cost Explorer?&lt;/td&gt;
&lt;td&gt;AWS Cost Explorer lets you explore your AWS costs and usage at both a high level and at a detailed level of analysis, and empowering you to dive deeper using a number of filtering dimensions (e.g., AWS Service, Region, Member Account, etc.) AWS Cost Explorer also gives you access to a set of default reports to help you get started, while also allowing you to create custom reports from scratch.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What kinds of default reports are available?&lt;/td&gt;
&lt;td&gt;AWS Cost Explorer provides a set of default reports to help you get familiar with the available filtering dimensions and types analyses that can be done using AWS Cost Explorer. These reports include a breakdown of your top 5 cost-accruing AWS services, and an analysis of your overall Amazon EC2 usage, an analysis of the total costs of your member accounts, and the Reserved Instance Utilization and Coverage reports.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can I create and save custom AWS Cost Explorer reports?&lt;/td&gt;
&lt;td&gt;Yes. You can currently save up to 50 custom AWS Cost Explorer reports.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/" rel="noopener noreferrer"&gt;FAISS&lt;/a&gt; Vector Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The FAISS vector database is used by AWS Cost Advisor to store the vector representations of the documents in the knowledge database. These vector representations are used by the retriever component of the RAG pipeline to retrieve the most relevant documents based on the user's query. The FAISS vector database allows for fast and efficient retrieval of documents, ensuring that the user receives a response in real-time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index_creator = VectorstoreIndexCreator(
    vectorstore_cls=FAISS,
    embedding=embeddings,
    text_splitter=CharacterTextSplitter(chunk_size=300, chunk_overlap=0),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AWS Cost Advisor leverages HuggingFace open-source large language models (LLMs) for the generation-based component of the RAG pipeline. The Langchain Retrieval QA is used for the retrieval-based component. The FAISS vector database is used to store the vector representations of the documents in the knowledge database, which are used by the retriever component to retrieve the most relevant documents.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Talk is cheap. Show me the code. ~ Linus Torvalds&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9u474mxpk3otk5b7e0fs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9u474mxpk3otk5b7e0fs.png" alt="Image description" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without any further ado, check out our Solution on Github:&lt;br&gt;
&lt;a href="https://github.com/bismillahkani/aws-cost-advisor/tree/main" rel="noopener noreferrer"&gt;https://github.com/bismillahkani/aws-cost-advisor/tree/main&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Performance Comparison with Examples
&lt;/h2&gt;

&lt;p&gt;To demonstrate the improved performance of the AWS Cost Advisor tool, we compared it to a generic text generation Q&amp;amp;A assistant. We asked both tools the same question: &lt;code&gt;"How to get started with AWS cost and usage report?"&lt;/code&gt; The generic text generation Q&amp;amp;A assistant provided an irrelevant answer, while the AWS Cost Advisor tool provided a relevant answer with cost-saving suggestions.&lt;/p&gt;

&lt;p&gt;Answer generated by LLM&lt;br&gt;
&lt;code&gt;Create an AWS account for a company or an individual. Navigate to the report section, then click on Create report. Select the Report template, and click Create Report.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Answer generated by RAG &lt;br&gt;
&lt;code&gt;The quickest way to get started with the AWS Cost Management tools is to access the Billing Dashboard.&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  How we're different?
&lt;/h2&gt;

&lt;p&gt;Enter AMAC (Ask Me Anything/AWS Cost Advisor), a fusion of cutting-edge technologies poised to redefine the AWS FinOps experience. Powered by HuggingFace, the industry-leading natural language processing (NLP) platform, and LangChain, an innovative language understanding tool, our chatbot possesses unrivaled contextual comprehension and robust question-answering abilities. By integrating FinOps and AWS Solution Architect expertise, we empower the chatbot with the knowledge to provide insightful cost optimization recommendations specific to participants' AWS deployments.&lt;/p&gt;

&lt;p&gt;But that's not all – our Q&amp;amp;A Chatbot goes beyond traditional approaches by incorporating Retrieval Augmented Generation. This groundbreaking technique seamlessly blends retrieval-based models and generative models to deliver the most accurate and contextually rich responses. The chatbot efficiently scans massive billing datasets, extracts pertinent information, and then generates coherent and concise answers, providing participants with actionable insights tailored to their specific cost optimization needs.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-life use-cases
&lt;/h2&gt;

&lt;p&gt;The AWS Cost Advisor AI Hackathon Scenario: Imagine a team of Cloud/DevOps/FinOps/Solution Architects/Engineers eager to optimize costs in their AWS deployments. Empowered by our Q&amp;amp;A Chatbot, they effortlessly navigate through complex billing reports, analyzing costs and identifying areas for improvement. The chatbot comprehends their queries, retrieves relevant cost data, and provides instant, accurate recommendations, enabling the team to make informed decisions that result in substantial cost savings.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion (Why we should win)
&lt;/h2&gt;

&lt;p&gt;Our solution is a game-changer for the AWS Cost Management landscape and We're just getting started as this is a side-project for an AI Hackathon (imagine what this will turn out into as a Full-blown project!!!), providing AWS customers with a powerful and efficient tool that significantly enhances their ability to optimize costs in their AWS deployments. By combining the cutting-edge technologies of Sagemaker, HuggingFace, LangChain, and Retrieval Augmented Generation with the expertise of AWS Solution Architects, our Q&amp;amp;A Chatbot offers unparalleled comprehension, lightning-fast retrieval, and human-like responses.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Meet the team behind this:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bismillah Kani

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.to/bismillahkani"&gt;https://dev.to/bismillahkani&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/bismillah-kani-49a31115/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/bismillah-kani-49a31115/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Manoj Partibhan

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/manojparthiban/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/manojparthiban/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Md. Mostafa Al Mahmud

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.linkedin.com/in/md-mostafa/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/md-mostafa/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/md__mostafa"&gt;https://dev.to/md__mostafa&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Omkar Kadam

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.linkedin.com/in/omkarokkadam/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/omkarokkadam/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/omkarokkadam"&gt;https://dev.to/omkarokkadam&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@omkarokkadam" rel="noopener noreferrer"&gt;https://medium.com/@omkarokkadam&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>ai</category>
      <category>hackathon</category>
      <category>community</category>
    </item>
    <item>
      <title>Introduction to AWS CDK</title>
      <dc:creator>bismillahkani</dc:creator>
      <pubDate>Mon, 26 Jun 2023 04:24:41 +0000</pubDate>
      <link>https://forem.com/aws-builders/introduction-to-aws-cdk-4aa5</link>
      <guid>https://forem.com/aws-builders/introduction-to-aws-cdk-4aa5</guid>
      <description>&lt;h2&gt;
  
  
  What is AWS CDK?
&lt;/h2&gt;

&lt;p&gt;AWS CDK is an opensource software development framework to create and deploy the cloud infrastructure using your familiar languages like Python. AWS CDK make the infrastructure management fun and easy 🕺&lt;/p&gt;

&lt;h2&gt;
  
  
  Manual infrastructure Deployment
&lt;/h2&gt;

&lt;p&gt;Let’s have a look into the process of deploying infrastructure manually. Typically we use the management console to create and deploy resources but sometimes we use CLI tools. For instance, to create a S3 bucket you log into the AWS account, click &lt;code&gt;Create Bucket&lt;/code&gt; and fill the form. In addition to creation of resources, you have to manually create the bucket policy, ACL and IAM policy in order to integrate to other components in the application. This is fine to begin with and when the infrastructure requirements are minimal. When it comes to enterprise level infrastructure management where you have to manage multiple applications with multiple stacks that has many resources the manual process of deployment is not reliable nor consistent. It is error prone and maintenance of application infrastructure becomes nightmare. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1b9crzwn5fiu6s6m8ku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1b9crzwn5fiu6s6m8ku.png" alt="Image description" width="800" height="974"&gt;&lt;/a&gt;&lt;br&gt;
From this example, we can understand that deploying and managing infrastructure manually for a fairly complex application is not a viable solution.  &lt;/p&gt;
&lt;h2&gt;
  
  
  Infrastructure as Code (IaC)
&lt;/h2&gt;

&lt;p&gt;Infrastructure as Code is the process of provisioning and managing the resources programmatically through machine readable definition files applying the same rigor as the application code development. For AWS the Infrastructure as Code is implemented using AWS CloudFormation. With AWS CloudFormation the application resources can be provisioned by writing the definition of resources in a cloud formation template either in YAML or JSON. For example, the following YAML template describes AWS S3 bucket to create.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWSTemplateFormatVersion: 2010-09-09
Resources:
  S3Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      AccessControl: PublicRead
      WebsiteConfiguration:
        IndexDocument: index.html
        ErrorDocument: error.html
    DeletionPolicy: Retain
  BucketPolicy:
    Type: 'AWS::S3::BucketPolicy'
    Properties:
      PolicyDocument:
        Id: MyPolicy
        Version: 2012-10-17
        Statement:
          - Sid: PublicReadForGetBucketObjects
            Effect: Allow
            Principal: '*'
            Action: 's3:GetObject'
            Resource: !Join 
              - ''
              - - 'arn:aws:s3:::'
                - !Ref S3Bucket
                - /*
      Bucket: !Ref S3Bucket
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Cloud formation YAML template&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;AWS CloudFormation takes this template and will create, update and delete resources on your AWS account according to the description in the template. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of IaC:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Visibility&lt;/strong&gt; - The template act as singe source of reference for the resources. Web console is not required. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stability&lt;/strong&gt; - Version controlled and rollback to previous stable version incase new changes break the application. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt; - Reusable and scales horizontally seamlessly.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How CDK works?
&lt;/h2&gt;

&lt;p&gt;CDK is built on top of the AWS CloudFormation service and uses it as the engine for provisioning resources. AWS CDK uses the familiarity and expressive power of favorite programming languages for modelling your applications. The AWS CDK supports TypeScript, JavaScript, Python, Java, C#/.Net, and (in developer preview) Go. Developers can use their favorite programming languages to define reusable components called Constructs and compose several Constructs into Stacks and Apps. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xgihhwn85dlz8nhlrxi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xgihhwn85dlz8nhlrxi.png" alt="Image description" width="800" height="595"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image credit: &lt;a href="https://docs.aws.amazon.com/cdk/v2/guide/home.html"&gt;https://docs.aws.amazon.com/cdk/v2/guide/home.html&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  CDK Constructs
&lt;/h2&gt;

&lt;p&gt;Constructs are basic building blocks of AWS CDK apps. Constructs are high level components that preconfigure cloud resources with proven defaults to make the infrastructure provisioning easier. AWS CDK provides a library of constructs that cover many AWS features and services. Developers can define the application infrastructure at high level using these constructs. Constructs are adjustable and composable and one can easily change the parameters and build custom constructs.&lt;/p&gt;
&lt;h2&gt;
  
  
  AWS Constructs library
&lt;/h2&gt;

&lt;p&gt;The CDK constructs library includes all the resources that are available in AWS. For example, &lt;code&gt;s3.Bucket&lt;/code&gt; class represents an AWS S3 bucket and &lt;code&gt;dynamodb.Table&lt;/code&gt; represents an AWS DynamoDB table.&lt;/p&gt;

&lt;p&gt;There are three level of constructs in this library,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;L1 Constructs&lt;/strong&gt; are the low level constructs that directly represents the resources in AWS CloudFormation. It is also called &lt;em&gt;CFN Resources&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L2 Constructs&lt;/strong&gt; are the next higher level constructs that are similar in function to L1 constructs but provide defaults, boiler plate and glue logic. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L3 Constructs&lt;/strong&gt; which are called as &lt;strong&gt;&lt;em&gt;patterns&lt;/em&gt;&lt;/strong&gt; are designed to accomplish common tasks in AWS For example, &lt;code&gt;aws-apigateway.LambdaRestApi&lt;/code&gt; construct represents an API Gateway backed by AWS Lambda function.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from aws_cdk import App, Stack
import aws_cdk.aws_s3 as s3
from constructs import Construct

class HelloCdkStack(Stack):

    def __init__(self, scope: Construct, id: str, **kwargs) -&amp;gt; None:
        super().__init__(scope, id, **kwargs)

        s3.Bucket(self, "MyFirstBucket", versioned=True)

app = App()
HelloCdkStack(app, "HelloCdkStack")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  CDK Stacks and Apps
&lt;/h2&gt;

&lt;p&gt;The smallest unit of deployment in AWS CDK is called a &lt;em&gt;stack&lt;/em&gt;. All of the resources defined within the scope of a stack is deployed as a single unit. You can define any number of stacks inside your AWS CDK app. &lt;/p&gt;

&lt;p&gt;As an example, here we declare a stack class &lt;code&gt;MyFirstStack&lt;/code&gt; that includes a single Amazon S3 bucket. However, this only declares a stack and the stack have to defined in some scope in order to be deployed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyFirstStack(Stack):

    def __init__(self, scope: Construct, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)

        s3.Bucket(self, "MyFirstBucket")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app = App()

MyFirstStack(app, 'stack1')
MySecondStack(app, 'stack2')

app.synth()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CDK Toolkit
&lt;/h2&gt;

&lt;p&gt;The AWS CDK Toolkit known as &lt;code&gt;cdk&lt;/code&gt; is the command line tool is the primary tool to provision and manage AWS CDK app. It executes the app, generates and deploys the AWS CloudFormation templates. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;AWS CLI - Make sure you have the latest version of the AWS CLI installed on your system.&lt;/li&gt;
&lt;li&gt;AWS Account and User - You’ll need access to an AWS account. Create IAM user with programmatic access and attach &lt;em&gt;AdministratorAccess&lt;/em&gt; policy to the IAM user. &lt;/li&gt;
&lt;li&gt;Node.js - The AWS CDK uses Node.js (&amp;gt;= 10.13.0, except for versions 13.0.0 - 13.6.0).&lt;/li&gt;
&lt;li&gt;VSCode - IDE&lt;/li&gt;
&lt;li&gt;Python - 3.6 or later.&lt;/li&gt;
&lt;li&gt;AWS CDK Toolkit
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g aws-cdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CDK commands
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk ls&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Lists the stacks in the app&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk synt&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Synthesizes and prints the CloudFormation template for the specified stack(s)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk bootstrap&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Deploys the CDK Toolkit staging stack; see Bootstrapping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk deploy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Deploys the specified stack(s)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk destroy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Destroys the specified stack(s)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk diff&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compares the specified stack with the deployed stack or a local CloudFormation template&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;cdk init&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Creates a new CDK project in the current directory from a specified template&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Your first CDK project
&lt;/h2&gt;

&lt;p&gt;Create project directory 📁&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir cdk_workshop 
cd cdk_workshop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;code&gt;cdk init&lt;/code&gt; to create a new Python CDK projects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk init sample-app --language python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Activating the Virtualenv. The init script created bunch of code to get started and also created a virtual environment. Activate the virtual environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source .venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the Python modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Project directory&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixz80w0ra29iqlvh14zu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixz80w0ra29iqlvh14zu.png" alt="Image description" width="800" height="1096"&gt;&lt;/a&gt;&lt;br&gt;
The application entry point is &lt;strong&gt;&lt;em&gt;app.py&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env python3

import aws_cdk as cdk

from cdk_workshop.cdk_workshop_stack import CdkWorkshopStack

app = cdk.App()
CdkWorkshopStack(app, "cdk-workshop")

app.synth()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The constructs are defined in &lt;strong&gt;&lt;em&gt;cdk_workshop/cdk_workshop_stack.py&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from constructs import Construct
from aws_cdk import (
    Duration,
    Stack,
    aws_sqs as sqs,
    aws_sns as sns,
    aws_sns_subscriptions as subs,
)

class CdkWorkshopStack(Stack):

    def __init__(self, scope: Construct, id: str, **kwargs) -&amp;gt; None:
        super().__init__(scope, id, **kwargs)

        queue = sqs.Queue(
            self, "CdkWorkshopQueue",
            visibility_timeout=Duration.seconds(300),
        )

        topic = sns.Topic(
            self, "CdkWorkshopTopic"
        )

        topic.add_subscription(subs.SqsSubscription(queue))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Synthesize&lt;/strong&gt; cloud formation template from the CDK app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk synth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output the following template&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Resources:
  CdkworkshopQueue18864164:
    Type: AWS::SQS::Queue
    Properties:
      VisibilityTimeout: 300
    Metadata:
      aws:cdk:path: cdkworkshop/CdkworkshopQueue/Resource
  CdkworkshopQueuePolicy78D5BF45:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Ref: CdkworkshopTopic58CFDD3D
            Effect: Allow
            Principal:
              Service: sns.amazonaws.com
            Resource:
              Fn::GetAtt:
                - CdkworkshopQueue18864164
                - Arn
        Version: "2012-10-17"
      Queues:
        - Ref: CdkworkshopQueue18864164
    Metadata:
      aws:cdk:path: cdkworkshop/CdkworkshopQueue/Policy/Resource
  CdkworkshopQueuecdkworkshopCdkworkshopTopic7642CC2FCF70B637:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: sqs
      TopicArn:
        Ref: CdkworkshopTopic58CFDD3D
      Endpoint:
        Fn::GetAtt:
          - CdkworkshopQueue18864164
          - Arn
    Metadata:
      aws:cdk:path: cdkworkshop/CdkworkshopQueue/cdkworkshopCdkworkshopTopic7642CC2F/Resource
  CdkworkshopTopic58CFDD3D:
    Type: AWS::SNS::Topic
    Metadata:
      aws:cdk:path: cdkworkshop/CdkworkshopTopic/Resource
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.18.0,jsii-runtime=Python/3.7.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The template contains the following resources:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AWS::SQS::Queue - queue&lt;/li&gt;
&lt;li&gt;AWS::SNS::Topic - topic&lt;/li&gt;
&lt;li&gt;AWS::SNS::Subscription - the subscription between the queue and the topic&lt;/li&gt;
&lt;li&gt;AWS::SQS::QueuePolicy - the IAM policy which allows this topic to send messages to the queue&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Bootstrapping the environment&lt;/strong&gt; 💼&lt;/p&gt;

&lt;p&gt;For the first time you deploy CDK app into an environment or region, a bootstrap stack has to be installed which includes the needed resources for toolkit operations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk bootstrap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploy 🚀&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the CloudFormation console, you will see that the stack has been created successfully. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7le09oojsmh2cwzxcemv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7le09oojsmh2cwzxcemv.png" alt="Image description" width="800" height="137"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Clean up&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cdk destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How CDK improve developers experience?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Infrastructure and code in one place &lt;/li&gt;
&lt;li&gt;Easy to define IAM policy - minimal code and minimal permissions&lt;/li&gt;
&lt;li&gt;Refactoring code &lt;/li&gt;
&lt;li&gt;Snapshot test - Compare the changes to previously successful state&lt;/li&gt;
&lt;li&gt;Fine grained assertion tests - Test specific aspects of cloud formation templates&lt;/li&gt;
&lt;li&gt;Validation tests - Validate rules and checks&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;AWS CDK is a game changer in Infrastructure as Code. It is a complete developer friendly tool to provision and manage all your cloud infrastructure resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html"&gt;https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/v1/python/index.html"&gt;https://docs.aws.amazon.com/cdk/api/v1/python/index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/v2/guide/home.html"&gt;https://docs.aws.amazon.com/cdk/v2/guide/home.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cdkworkshop.com/"&gt;https://cdkworkshop.com/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Author
&lt;/h3&gt;

&lt;p&gt;Bismillah Kani is a passionate and multi-faceted AI Scientist and Cloud Architect with a passion for deep learning, machine learning, and artificial intelligence. As an AWS certified professional he is constantly striving for excellence and innovation in the field of AI and Cloud.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloud</category>
      <category>devops</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Generative AI using AWS SageMaker Jumpstart</title>
      <dc:creator>bismillahkani</dc:creator>
      <pubDate>Sun, 16 Apr 2023 10:26:53 +0000</pubDate>
      <link>https://forem.com/aws-builders/generative-ai-using-aws-sagemaker-jumpstart-1ckm</link>
      <guid>https://forem.com/aws-builders/generative-ai-using-aws-sagemaker-jumpstart-1ckm</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Stable Diffusion&lt;/li&gt;
&lt;li&gt;
AWS SageMaker Jumpstart

&lt;ul&gt;
&lt;li&gt;Deploy a pre-trained Stable Diffusion model&lt;/li&gt;
&lt;li&gt;Fine-tune a Stable Diffusion model&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Amazon Bedrock&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Generative AI has become an increasingly popular topic in the field of machine learning, with applications in areas such as computer vision, natural language processing, and creative arts. Unlike traditional machine learning, which focuses on finding patterns in data, generative AI aims to create new data that mimics the patterns found in the training data. This can be useful for tasks such as image and text generation, as well as for creating realistic simulations of real-world scenarios.&lt;/p&gt;

&lt;p&gt;One approach to Generative AI that has shown promising results is Stable Diffusion. Stable Diffusion is a type of generative model that uses a diffusion process to transform a noise vector into a sequence of image-like samples. This approach has several advantages over other generative models, including improved sample quality and stability.&lt;/p&gt;

&lt;p&gt;In this blog post, we will explore how to use Stable Diffusion for Generative AI on AWS SageMaker Jumpstart, a cloud-based platform for building, training, and deploying machine learning models. We will start by introducing Stable Diffusion and its advantages for Generative AI, then move on to exploring how to deploy pre-trained models and fine-tune models on custom collections of images. Finally, we will discuss how Amazon Bedrock can be used to democratize Generative AI and scale projects. By the end of this post, you will have a practical understanding of how to use Stable Diffusion on AWS SageMaker Jumpstart for your own Generative AI projects.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stable Diffusion
&lt;/h2&gt;

&lt;p&gt;Stable Diffusion is a generative model that uses a diffusion process to transform a noise vector into a sequence of image-like samples. Unlike other generative models such as Generative Adversarial Networks (GANs) or Variational Autoencoders (VAEs), Stable Diffusion does not require a discriminator or an encoder, making it simpler and more stable to train.&lt;/p&gt;

&lt;p&gt;In Stable Diffusion, the noise vector is iteratively transformed by a diffusion process that adds noise to the current sample. The diffusion process is controlled by a diffusion coefficient, which determines the amount of noise added at each iteration. The resulting sequence of samples is then transformed back into a single image using a reverse process.&lt;/p&gt;

&lt;p&gt;Stable Diffusion has several advantages over other generative models. One key advantage is its stability during training, which can be a challenge for GANs and VAEs. Stable Diffusion does not require a discriminator to be trained against the generator, which can lead to instability and mode collapse. Instead, Stable Diffusion directly optimizes the likelihood of the data given the noise vector.&lt;/p&gt;

&lt;p&gt;Another advantage of Stable Diffusion is its ability to generate high-quality samples. By iteratively adding noise to the samples, Stable Diffusion generates images that have fine details and realistic textures. This can be especially useful for tasks such as image generation or style transfer.&lt;/p&gt;

&lt;p&gt;Stable Diffusion has been applied to a variety of tasks, including image generation, video prediction, and text generation. It has also been used in creative applications, such as generating realistic paintings or music.&lt;/p&gt;

&lt;p&gt;In the next section, we will explore how to use Stable Diffusion on AWS SageMaker Jumpstart for Generative AI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0S-A9H1T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lilianweng.github.io/posts/2021-07-11-diffusion-models/unCLIP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0S-A9H1T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lilianweng.github.io/posts/2021-07-11-diffusion-models/unCLIP.png" alt="High level steps of text-to-image generation" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;
High level steps of text-to-image generation&lt;a href="https://arxiv.org/abs/2204.06125"&gt;Ramesh et al. 2022&lt;/a&gt;

  



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS SageMaker Jumpstart
&lt;/h2&gt;

&lt;p&gt;AWS SageMaker Jumpstart provides a variety of tools and resources for developers and data scientists, including pre-built machine learning models, notebooks, and data sets. Jumpstart also includes a range of features for deploying and scaling machine learning models, such as automatic model tuning and model hosting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8rud7q6nibt6d2ob9pi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8rud7q6nibt6d2ob9pi.png" alt="Image description" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;
SageMaker Studio

  

&lt;p&gt;One of the benefits of using AWS SageMaker Jumpstart for Generative AI is the ability to quickly deploy pre-trained models. AWS provides a number of pre-trained models for Stable Diffusion, which can be used to generate high-quality images with minimal training. These pre-trained models can be deployed and used in a variety of applications, such as image generation or style transfer.&lt;/p&gt;

&lt;p&gt;Another advantage of using AWS SageMaker Jumpstart for Generative AI is the ability to fine-tune models on custom collections of images. Jumpstart provides a range of tools for fine-tuning models, including automatic hyperparameter tuning and data augmentation. This allows developers and data scientists to quickly and easily train models that are tailored to their specific use case.&lt;/p&gt;

&lt;p&gt;Overall, AWS SageMaker Jumpstart provides a powerful platform for building, training, and deploying Generative AI models. With its range of pre-built models, notebooks, and tools, Jumpstart makes it easy for developers and data scientists to get started with Generative AI and to build models that are tailored to their specific use case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltxjrhzrokfl058m54qs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltxjrhzrokfl058m54qs.png" alt="Image description" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;
SageMaker Jumpstart in Studio

  

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy a pre-trained Stable Diffusion model
&lt;/h2&gt;

&lt;p&gt;To deploy a pre-trained Stable Diffusion model on AWS SageMaker Jumpstart, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the AWS SageMaker Studio console and select the "Stable Diffusion 2.1 base" model from the list of pre-built models in SageMaker Jumpstart. Once you click on the model card you will directed to the deploy and train page where you can deploy a pre-trained model easily.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvzjnlr29m25l3t6o9m1b.png" alt="Image description" width="800" height="781"&gt;
&lt;/li&gt;
&lt;li&gt;Choose the pre-trained Stable Diffusion model that best matches your use case. AWS provides a range of pre-trained models for Stable Diffusion, each of which is optimized for a specific type of generative AI task.&lt;/li&gt;
&lt;li&gt;Once you have selected the pre-trained model, choose the instance type and number of instances that you want to use for deployment. AWS SageMaker Jumpstart provides a range of instance types, from small instances suitable for testing and development to large instances suitable for production deployments.&lt;/li&gt;
&lt;li&gt;After selecting the instance type, configure the deployment settings for the pre-trained model. This includes settings such as the endpoint name, and other configurations. Once you have configured the deployment settings, deploy the pre-trained model to the selected instance type. AWS SageMaker Jumpstart will automatically provision the necessary resources and deploy the model to the specified instance type.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvkgpqaybgytssm0hv7vc.png" alt="Image description" width="643" height="867"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8g0pe601p42usx0naamx.png" alt="Image description" width="800" height="317"&gt;
&lt;/li&gt;
&lt;li&gt;After the model is deployed, you can use the AWS SageMaker Jumpstart console to test the model and generate images. AWS provides a range of tools for testing and evaluating generative AI models, including tools for visualizing the generated images and evaluating the quality of the generated output.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Overall, deploying a pre-trained Stable Diffusion model on AWS SageMaker Jumpstart is a straightforward process that can be completed quickly and easily. With a range of pre-built models and deployment options, AWS SageMaker Jumpstart provides a powerful platform for building and deploying generative AI models.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fine-tune a Stable Diffusion model
&lt;/h2&gt;

&lt;p&gt;In addition to deploying pre-trained models, AWS SageMaker Jumpstart also provides tools for fine-tuning Stable Diffusion models on custom collections of images. This can be useful for tasks such as generating images that are specific to a particular use case or domain. In this section, we will explore how to fine-tune a Stable Diffusion model on AWS SageMaker Jumpstart for a custom collection of images.&lt;br&gt;
Before fine-tuning a Stable Diffusion model on a custom collection of images, you will need to prepare the data. This includes selecting a set of high-quality images that are representative of the domain you want to generate images in. For this example, we will fine-tune the model on a set of Koala bear images.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhmyx93jkgl9uuawpr9c.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhmyx93jkgl9uuawpr9c.jpg" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;
Collection of Koala images for fine-tuning

  

&lt;p&gt;To fine-tune a Stable Diffusion model on a custom collection of images, you can use the example notebook provided by AWS SageMaker Jumpstart. This allows you to fine-tune pre-trained models on your custom collection of images. Clone the notebook, create a directory ‘training_images’, upload the Koala bear images to the directory, change the ‘use_local_images’ = True and run all cells. SageMaker spins up a training job for fine-tuning the model on the Koala bear images. After the training is completed, the model can be deployed for generating new images. &lt;/p&gt;

&lt;p&gt;Once you have fine-tuned the Stable Diffusion model on your custom collection of images, you can use it to generate new images. &lt;/p&gt;

&lt;p&gt;Overall, fine-tuning a Stable Diffusion model on AWS SageMaker Jumpstart is a powerful tool for generating high-quality images that are tailored to your specific use case. By selecting a custom collection of images and fine-tuning the model, you can generate images that are specific to your domain and that meet your specific requirements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ro7ui221kvpg75azau7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ro7ui221kvpg75azau7.png" alt="Image description" width="800" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncwcep8j63v1e71th62g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncwcep8j63v1e71th62g.png" alt="Image description" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Amazon Bedrock
&lt;/h2&gt;

&lt;p&gt;Amazon Bedrock is a new service that offers customers access to powerful foundation models (FMs) from various providers through an API. It democratizes access to FMs, making it easier for customers to build and scale generative AI-based applications. It allows customers to find the right model for their needs, customize FMs with their own data, and integrate and deploy them using AWS tools without managing any infrastructure. Bedrock is a scalable, reliable, and secure AWS managed service. It simplifies the development of generative AI applications without the need for managing physical infrastructure or high operational overhead.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cch0XQ6z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://d2908q01vomqb2.cloudfront.net/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59/2023/04/13/building-generative-ai-on-aws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cch0XQ6z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://d2908q01vomqb2.cloudfront.net/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59/2023/04/13/building-generative-ai-on-aws.png" alt="High level steps of text-to-image generation" width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;
Building with Generative AI on AWS

  

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this blog post, we explored Stable Diffusion, a type of generative model that uses a diffusion process to transform a noise vector into a sequence of image-like samples. We discussed its advantages over other generative models, including improved stability and sample quality. We then moved on to explore how to use AWS SageMaker Jumpstart, a cloud-based platform for building, training, and deploying machine learning models, for Generative AI. We discussed how to deploy pre-trained models and fine-tune models on custom collections of images. Finally, we discussed Amazon Bedrock, a new service that offers customers access to powerful foundation models (FMs) from various providers through an API, making it easier for customers to build and scale generative AI-based applications. With these tools, developers and data scientists can quickly and easily build and deploy Generative AI models that are tailored to their specific use case.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;"Stable Diffusion 2.1." GitHub, &lt;a href="https://github.com/ermongroup/stable-diffusion"&gt;https://github.com/ermongroup/stable-diffusion&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;"Amazon SageMaker Jumpstart." AWS, &lt;a href="https://aws.amazon.com/sagemaker/jumpstart/"&gt;https://aws.amazon.com/sagemaker/jumpstart/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;"Amazon Bedrock." AWS, &lt;a href="https://aws.amazon.com/bedrock/"&gt;https://aws.amazon.com/bedrock/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Text to image on AWS SageMaker Jumpstart, &lt;a href="https://aws.amazon.com/blogs/machine-learning/generate-images-from-text-with-the-stable-diffusion-model-on-amazon-sagemaker-jumpstart/"&gt;https://aws.amazon.com/blogs/machine-learning/generate-images-from-text-with-the-stable-diffusion-model-on-amazon-sagemaker-jumpstart/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Fine tune text to image on AWS SageMaker Jumpstart, &lt;a href="https://aws.amazon.com/blogs/machine-learning/fine-tune-text-to-image-stable-diffusion-models-with-amazon-sagemaker-jumpstart/"&gt;https://aws.amazon.com/blogs/machine-learning/fine-tune-text-to-image-stable-diffusion-models-with-amazon-sagemaker-jumpstart/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer: This blog post was generated with the assistance of AI tools. While the author has edited and reviewed the content, some portions of the article may have been generated or suggested by the AI tool. The opinions and views expressed in this post are solely those of the author.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
  </channel>
</rss>
