aws / amazon-sagemaker-examples

Example 📓 Jupyter notebooks that demonstrate how to build, train, and deploy machine learning models using 🧠 Amazon SageMaker.
https://sagemaker-examples.readthedocs.io
Apache License 2.0
9.79k stars 6.66k forks source link

[Example Request] #4667

Open math-sasso opened 1 month ago

math-sasso commented 1 month ago

Describe the use case example you want to see I would like to know how can I use Tensorboard with SagemakerJumpstart. Could you please provide an example? If you could specially train in a llama3 (can be 8B for testing purposes) would be amazing.

How would this example be used? Please describe. I am training my models but can not get the loss curves. Would like to export to tensorboard.

Describe which SageMaker services are involved Sagemaker Jumpstart

**Describe what other services (other than SageMaker) are involved*** Tensorboard

Describe which dataset could be used. Provide its location in s3://sagemaker-sample-files or another source. You can use your own example datasets.

taitaitai1777 commented 17 hours ago

Title

## SageMaker Notebook: Train, Deploy, Predict Model

Summary

**Summary:**

This notebook demonstrates how to use Amazon SageMaker for training, deploying, and making predictions with a machine learning model. It includes steps to load essential libraries, configure the environment, define and train a SageMaker Estimator, and subsequently deploy the model for real-time predictions. Finally, it concludes with the cleanup process to manage resources effectively. Ensure prerequisites are met for a seamless experience.

Detailed Notebook Setup

Markdown Cell (Introduction and Custom Styling)

<style>
    .black-background {
        background-color: black;
        color: yellow;
        padding: 10px;
        border-radius: 5px;
    }
    .note {
        background-color: yellow;
        color: black;
        padding: 10px;
        border-left: 5px solid black;
        margin-bottom: 10px;
        border-radius: 5px;
    }
</style>

<div class="black-background">
    <h2>SageMaker Notebook: Train, Deploy, Predict Model</h2>
    <p>This notebook demonstrates how to use Amazon SageMaker for training, deploying, and making predictions with a machine learning model. It includes steps to load essential libraries, configure the environment, define and train a SageMaker Estimator, and subsequently deploy the model for real-time predictions. Finally, it concludes with the cleanup process to manage resources effectively. Ensure prerequisites are met for a seamless experience.</p>
</div>

<div class="note">
    <strong>Prerequisites:</strong> 
    Ensure you have the following:
    <ul>
        <li>An AWS account</li>
        <li>Necessary IAM permissions</li>
        <li>Data uploaded to an S3 bucket</li>
    </ul>
</div>

Code Cells (Step-by-Step Execution)

# Ensure the latest SageMaker SDK is installed
!pip install --upgrade sagemaker

import sagemaker
from sagemaker import get_execution_role
from sagemaker.estimator import Estimator
from sagemaker.serializers import JSONSerializer
from sagemaker.deserializers import JSONDeserializer

# Set up SageMaker execution role and S3 bucket paths
role = get_execution_role()
bucket = '<your-bucket-name>'
data_path = f's3://{bucket}/path/to/training/data'
# Define the Estimator with necessary parameters
estimator = Estimator(
    image_uri='<your-image-uri>',  # Image URI for the Docker container
    role=role,                     # IAM role for SageMaker
    instance_count=1,              # Number of instances
    instance_type='ml.m5.large',   # Instance type
    output_path=f's3://{bucket}/output/'  # Output path in S3 bucket
)
# Train the model using the training dataset from S3
estimator.fit({'train': data_path})  # Specify the training channel with your data
# Deploy the model to an endpoint for real-time inference
predictor = estimator.deploy(
    initial_instance_count=1,         # Number of instances for deployment
    instance_type='ml.m5.large',      # Instance type for deployment
    serializer=JSONSerializer(),      # Serializer for input
    deserializer=JSONDeserializer()   # Deserializer for output
)
# Make predictions using the deployed model
sample_input = [<your_sample_data>]  # Provide sample input data here
predictions = predictor.predict(sample_input)
print(predictions)  # Output the predictions
# Delete the endpoint to clean up resources
predictor.delete_endpoint()