Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support for Meta models provided by Amazon SageMaker #1241

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

JGalego
Copy link
Contributor

@JGalego JGalego commented Jul 3, 2024

Refactors AWSMeta to work with Amazon SageMaker endpoints.

Fixes #1009

Example

import os

import boto3
import dspy

from sagemaker.jumpstart.model import JumpStartModel

# 0a. Get AWS region
region_name = boto3.session.Session().region_name

# 0b. Deploy Llama3 70B Instruct model via SageMaker JumpStart SDK
# https://aws.amazon.com/blogs/machine-learning/meta-llama-3-models-are-now-available-in-amazon-sagemaker-jumpstart/
# https://aws.amazon.com/blogs/machine-learning/deploy-and-fine-tune-foundation-models-in-amazon-sagemaker-jumpstart-with-two-lines-of-code/
model = JumpStartModel(
    model_id="meta-textgeneration-llama-3-70b-instruct",
    model_version="2.0.2",
    instance_type="ml.g5.48xlarge",
    region=region_name
)
if os.environ.get('ENDPOINT_NAME'):
    predictor = model.deploy(
        accept_eula=input("Accept EULA? [y/n]") == "y"
    )

# 1. Initialize SageMaker provider
sagemaker = dspy.Sagemaker(
    region_name=region_name
)

# 2. Configure Meta model
lm_sagemaker = dspy.AWSMeta(
    aws_provider=sagemaker,
    model=os.environ.get('ENDPOINT_NAME', predictor.endpoint_name)
)
dspy.configure(lm=lm_sagemaker)

# 3. Create Q&A CoT
qa = dspy.ChainOfThought('question -> answer')

# 4. Run a query
response = qa(question="Who was Albert Einstein?")
print(response)

# 999. Clean up everything 馃Ч
predictor.delete_endpoint()

Output

Prediction(
    rationale="Here is the completed response:\n\nQuestion: Who was Albert Einstein?\nReasoning: Let's think step by step in order to identify the famous physicist. We know that Albert Einstein was a renowned German-born physicist who is widely regarded as one of the most influential scientists of the 20th century.",
    answer='Albert Einstein was a renowned German-born physicist who is widely regarded as one of the most influential scientists of the 20th century.'
)

@JGalego
Copy link
Contributor Author

JGalego commented Jul 5, 2024

@arnavsinghvi11
Copy link
Collaborator

Thanks @JGalego for the PR and the wonderful blog post!

@arnavsinghvi11 arnavsinghvi11 merged commit 46f0c73 into stanfordnlp:main Jul 8, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_call_model in aws_models.py raises error when using Sagemaker as aws_provider
2 participants