Uploading model weights for DeepSeek-R1 to an Amazon S3 bucket involves several steps. Here's a detailed guide on how to accomplish this:
Step 1: Download the DeepSeek-R1 Model
First, you need to download the DeepSeek-R1 model artifacts. These can be obtained from the Hugging Face Hub using the `snapshot_download` function from the `huggingface_hub` library. The model repository ID for DeepSeek-R1 is typically "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"[1][3].python
from huggingface_hub import snapshot_download
repo_id = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
local_dir = snapshot_download(repo_id)
print(f"Model downloaded to: {local_dir}")
Step 2: Set Up Your AWS Environment
Ensure you have an AWS account with access to Amazon S3 and the necessary permissions. You will need an IAM role with policies like `AmazonS3FullAccess` for testing purposes, though for production, you should use more restrictive policies[1][3].Step 3: Create an S3 Bucket
Create an S3 bucket in the AWS Management Console. This bucket will store your model weights. You can name it something like "deepseek-manav" or "llm-weights-demo-deepseek3"[2][3].Step 4: Install Required Libraries
Install the `boto3` library, which is used to interact with AWS services like S3. You can install it using pip:bash
pip install boto3
Step 5: Upload Model Weights to S3
Use the following Python script to upload the model weights to your S3 bucket:python
import boto3
import os
# Define your S3 bucket name and prefix
bucket_name = "llm-weights-demo-deepseek3"
s3_prefix = "DeepSeek-R1-Distill-Llama-8B"
# Initialize S3 client
s3_client = boto3.client('s3')
def upload_to_s3(local_path, bucket_name, s3_prefix):
for root, dirs, files in os.walk(local_path):
for filename in files:
local_file_path = os.path.join(root, filename)
# Create S3 key (path in bucket)
clean_prefix = s3_prefix.lstrip('models/').rstrip('/')
s3_key = f"models/{clean_prefix}/{os.path.relpath(local_file_path, local_path)}"
# Replace backslashes with forward slashes for S3
s3_key = s3_key.replace('\\', '/')
print(f"Uploading {local_file_path} to s3://{bucket_name}/{s3_key}")
s3_client.upload_file(local_file_path, bucket_name, s3_key)
# Execute upload
upload_to_s3(local_dir, bucket_name, s3_prefix)
Step 6: Verify Upload
After uploading, verify that all files are correctly uploaded by checking your S3 bucket in the AWS Console[3].Step 7: Import Model into Amazon Bedrock (Optional)
If you plan to use the model with Amazon Bedrock, navigate to the Bedrock console, select "Imported Models," and import the model from your S3 bucket. Ensure your IAM role has the necessary permissions for Bedrock and S3 access[1][3].This process allows you to securely store and manage your DeepSeek-R1 model weights in an S3 bucket, ready for deployment in various AWS services like SageMaker or Bedrock.
Citations:
[1] https://tutorialsdojo.com/deepseek-in-amazon-bedrock-a-comprehensive-demo/
[2] https://substack.com/home/post/p-156004714
[3] https://crossasyst.com/blog/deepseek-r1-on-aws-bedrock/
[4] https://www.youtube.com/watch?v=1aq_ju70qHQ
[5] https://aws.amazon.com/blogs/machine-learning/optimize-hosting-deepseek-r1-distilled-models-with-hugging-face-tgi-on-amazon-sagemaker-ai/
[6] https://www.youtube.com/watch?v=MlvdpDJn59E
[7] https://aws.amazon.com/blogs/machine-learning/deploy-deepseek-r1-distilled-models-on-amazon-sagemaker-using-a-large-model-inference-container/
[8] https://www.linkedin.com/posts/sushantanandy_springai-deepseek-artificialintelligence-activity-7291214173487738880-vW5f