Today, we’re excited to announce a new capability that allows you to deploy over 100 open-weight and proprietary models from amazon SageMaker JumpStart and register them with amazon Bedrock, allowing you to seamlessly access them through the powerful amazon Bedrock APIs. You can now use amazon Bedrock features such as amazon Bedrock Knowledge Bases and amazon Bedrock Guardrails with models deployed through SageMaker JumpStart.
SageMaker JumpStart helps you get started with machine learning (ML) by providing fully customizable solutions and one-click deployment and fine-tuning of more than 400 popular open-weight and proprietary generative ai models. amazon Bedrock is a fully managed service that provides a single API to access and use various high-performing foundation models (FMs). It also offers a broad set of capabilities to build generative ai applications. The amazon Bedrock Converse API is a runtime API that provides a consistent interface that works with different models. It allows you to use advanced features in amazon Bedrock such as the playground, guardrails, and tool use (function calling).
SageMaker JumpStart has long been the go-to service for developers and data scientists seeking to deploy state-of-the-art generative ai models. Through this integration, you can now combine the flexibility of hosting models on SageMaker JumpStart with the fully managed experience of amazon Bedrock, including advanced security controls, scalable infrastructure, and comprehensive monitoring capabilities.
In this post, we show you how to deploy FMs through SageMaker JumpStart, register them with amazon Bedrock, and invoke them using amazon Bedrock APIs.
Solution overview
The Converse API standardizes interaction with amazon Bedrock FMs, enabling developers to write code one time and use it across various models without needing to adjust for model-specific differences. It supports multi-turn conversations through conversational history as part of the API request, and developers can perform tasks that require access to external APIs through the usage of tools (function calling). Additionally, the Converse API allows you to block inappropriate inputs or generated content by including a guardrail in your API calls. To review the complete list of supported models and model features, refer to Supported models and model features.
This new feature extends the capabilities of the Converse API into a single interface that developers can use to call FMs deployed in SageMaker JumpStart. This allows developers to use the same API to invoke models from amazon Bedrock and SageMaker JumpStart, streamlining the process to integrate models into their generative ai applications. Now you can build on top of an even larger library of world-class open source and proprietary models through a single API. To view the full list of Bedrock Ready models available from SageMaker JumpStart, refer to the Bedrock Marketplace documentation. You can also use amazon Bedrock Marketplace to discover and deploy these models to SageMaker endpoints.
In this post, we walk through the following steps:
- Deploy the Gemma 2 9B Instruct model using SageMaker JumpStart.
- Register the model with amazon Bedrock.
- Test the model with sample prompts using the amazon Bedrock playground.
- Use the amazon Bedrock
RetrieveAndGenerate
API to query the amazon Bedrock knowledge base. - Set up amazon Bedrock Guardrails to help block harmful content and personally identifiable information (PII) data.
- Invoke models with Converse APIs to show an end-to-end Retrieval Augmented Generation (RAG) pipeline.
Prerequisites
You can access and deploy pretrained models from SageMaker JumpStart in the amazon SageMaker Studio UI. To access SageMaker Studio on the AWS Management Console, you need to set up an amazon SageMaker domain. SageMaker uses domains to organize user profiles, applications, and their associated resources. To create a domain and set up a user profile, refer to Guide to getting set up with amazon SageMaker.
You also need an AWS Identity and Access Management (IAM) role with appropriate permissions. To get started with this example, you can use the AmazonSageMakerFullAccess, AmazonBedrockFullAccess, AmazonOpenSearchAccess managed policies to provide the required permissions to SageMaker JumpStart and amazon Bedrock. For a more scoped down set of permissions, refer to the following:
After applying the relevant permissions, setting up a SageMaker domain, and creating user profiles, you are ready to deploy your SageMaker JumpStart model and register it with amazon Bedrock.
Deploy a model with SageMaker JumpStart and register it with amazon Bedrock
This section provides a walkthrough of deploying a model using SageMaker JumpStart and registering it with amazon Bedrock. In this walkthrough, you will deploy and register the Gemma 2 9B Instruct model offered through Hugging Face in SageMaker JumpStart. Complete the following steps:
- On the SageMaker console, choose Studio in the navigation pane.
- Choose the relevant user profile on the dropdown menu and choose Open Studio.
- In SageMaker Studio, choose JumpStart in the navigation pane.
Here, you will see a list of the available SageMaker JumpStart models. Models that can be registered to amazon Bedrock after they’ve been deployed through SageMaker JumpStart have a Bedrock ready tag.
- The Gemma 2 9B Instruct model for this example is provided by Hugging Face, so choose the Hugging Face model card.
- To filter the list of models to view which models are supported by amazon Bedrock, select Bedrock Ready under Action.
- Search for Gemma 2 9B Instruct and choose the model card for Gemma 2 9B Instruct.
You can review the model card for Gemma 2 9B Instruct to learn more about the model.
- To deploy the model, choose Deploy.
- Review the End User License Agreement for Gemma 2 9B Instruct and select I accept the End User License Agreement (EULA) and read the terms and conditions.
- Leave the endpoint settings with their default values and choose Deploy.
The endpoint deployment process will take a few minutes.
- Under Deployments in the navigation pane, choose Endpoints to view your available endpoints.
After a few minutes, the model will be deployed to the endpoint and its status will change to In service, indicating that the endpoint is ready to serve traffic. You can use the Refresh icon at the bottom of the endpoint screen to get the latest information.
- When your endpoint is in service, choose it to go to the endpoint details page.
- Choose Use with Bedrock to start the registration process.
You will be redirected to the amazon Bedrock console.
- On the Register endpoint page, the SageMaker endpoint amazon Resource Name (ARN) and model ARN have already been prepopulated. Review these values and choose Register.
Your SageMaker endpoint will be registered with amazon Bedrock in a few minutes.
After your SageMaker endpoint is registered with amazon Bedrock, you can invoke it using the Converse API. Then you can test your endpoint in the amazon Bedrock playground.
- In the navigation pane on the amazon Bedrock console, choose Marketplace deployments under Foundation models.
- From the list of managed deployments, select your registered model, then choose Open in playground.
You will now be in the amazon Bedrock playground for Chat/text. The Chat/text playground allows to you test your model with a single prompt, or provides chat capability for conversational use cases. Because this example will be an interactive chat session, leave the Mode as the default Chat. The chat capability in the playground should be set to test your Gemma 2 9B Instruct model.
Now you can test your SageMaker endpoint through amazon Bedrock! Use the following prompt to test summarizing a meeting transcript, and review the results:
- Enter the prompt into the playground, then choose Run.
You can view the response in the chat generated by your deployed SageMaker JumpStart model through amazon Bedrock:
You can also test the model with your own prompts and use cases.
Use amazon Bedrock APIs with the deployed model
This section demonstrates using the AWS SDK for Python (Boto3) and Converse APIs to invoke the Gemma 2 9B Instruct model you deployed earlier through SageMaker and registered with amazon Bedrock. The full source code associated with this post is available in the accompanying <a target="_blank" href="https://github.com/aws-samples/sagemaker-genai-hosting-examples/blob/main/jumpstart-bedrock/amazon-bedrock-with-amazon-sageMaker-jumpstart.ipynb” target=”_blank” rel=”noopener”>GitHub repo. For additional Converse API examples, refer to Converse API examples.
In this code sample, we also implement a RAG architecture in conjunction with the deployed model. RAG is the process of optimizing the output of a large language model (LLM) so it references an authoritative knowledge base outside of its training data sources before generating a response.
Use the deployed SageMaker model with the RetrieveAndGenerate
API offered by amazon Bedrock to query a knowledge base and generate responses based on the retrieved results. The response only cites sources that are relevant to the query. For information on creating a Knowledge Base, refer to Creating a Knowledge Base. For additional code samples, refer to RetrieveAndGenerate.
The following diagram illustrates the RAG workflow.
Complete the following steps:
- To invoke the deployed model, you need to pass the endpoint ARN of the deployed model in the
modelId
parameter of the Converse API.
To obtain the ARN of the deployed model, navigate to the amazon Bedrock console. In the navigation pane, choose Marketplace deployments under Foundation models. From the list of managed deployments, choose your registered model to view more details.
You will be directed to the model summary on the Model catalog page under Foundation models. Here, you will find the details associated with your deployed model. Copy the model ARN to use in the following code sample.
- Invoke the SageMaker JumpStart model with the
RetrieveAndGenerate
API. Thegeneration_template
andorchestration_template
parameters in theretrieve_and_generate
API are model specific. These templates define the prompts and instructions for the language model, guiding the generation process and the integration with the knowledge retrieval component.
Now you can implement guardrails with the Converse API for your SageMaker JumpStart model. amazon Bedrock Guardrails enables you to implement safeguards for your generative ai applications based on your use cases and responsible ai policies. For information on creating guardrails, refer to Create a Guardrail. For additional code samples to implement guardrails, refer to Include a guardrail with Converse API.
- In the following code sample, you include a guardrail in a Converse API request invoking a SageMaker JumpStart model:
Clean up
To clean up your resources, use the following code:
The SageMaker JumpStart model you deployed will incur cost if you leave it running. Delete the endpoint if you want to stop incurring charges. Deleting the endpoint will also de-register the model from amazon Bedrock. For more details, see Delete Endpoints and Resources.
Conclusion
In this post, you learned how to deploy FMs through SageMaker JumpStart, register them with amazon Bedrock, and invoke them using amazon Bedrock APIs. With this new capability, organizations can access leading proprietary and open-weight models using a single API, reducing the complexity of building generative ai applications with a variety of models. This integration between SageMaker JumpStart and amazon Bedrock is generally available in all AWS Regions where amazon Bedrock is available. Try this <a target="_blank" href="https://github.com/aws-samples/sagemaker-genai-hosting-examples/blob/main/jumpstart-bedrock/amazon-bedrock-with-amazon-sageMaker-jumpstart.ipynb” target=”_blank” rel=”noopener”>code to use ConverseAPIs, Knowledge bases and Guardrails with SageMaker.
About the Author
Vivek Gangasani is a Senior GenAI Specialist Solutions Architect at AWS. He helps emerging GenAI companies build innovative solutions using AWS services and accelerated compute. Currently, he is focused on developing strategies for fine-tuning and optimizing the inference performance of Large Language Models. In his free time, Vivek enjoys hiking, watching movies and trying different cuisines.
<img loading="lazy" class="alignleft wp-image-95315 size-full" src="https://d2908q01vomqb2.cloudfront.net/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59/2024/12/03/badgephotos.corp_.amazon-1.jpg” alt=”” width=”100″ height=”133″/>Abhishek Doppalapudi is a Solutions Architect at amazon Web Services (AWS), where he assists startups in building and scaling their products using AWS services. Currently, he is focused on helping AWS customers adopt Generative ai solutions. In his free time, Abhishek enjoys playing soccer, watching Premier League matches, and reading.
June Won is a product manager with amazon SageMaker JumpStart. He focuses on making foundation models easily discoverable and usable to help customers build generative ai applications. His experience at amazon also includes mobile shopping applications and last mile delivery.
Eashan Kaushik is an Associate Solutions Architect at amazon Web Services. He is driven by creating cutting-edge generative ai solutions while prioritizing a customer-centric approach to his work. Before this role, he obtained an MS in Computer Science from NYU Tandon School of Engineering. Outside of work, he enjoys sports, lifting, and running marathons.
Giuseppe Zappia is a Principal ai/ML Specialist Solutions Architect at AWS, focused on helping large enterprises design and deploy ML solutions on AWS. He has over 20 years of experience as a full stack software engineer, and has spent the past 5 years at AWS focused on the field of machine learning.
Bhaskar Pratap is a Senior Software Engineer with the amazon SageMaker team. He is passionate about designing and building elegant systems that bring machine learning to people’s fingertips. Additionally, he has extensive experience with building scalable cloud storage services.