How to deploy and fine-tune DeepSeek models on AWS
DeepSeek-R1's distilled Llama and Qwen models can be deployed on AWS through Hugging Face Inference Endpoints, Bedrock Marketplace, SageMaker with Hugging Face LLM DLCs (TGI v3) on GPUs or Neuron, and EC2 Inferentia via the Hugging Face Neuron AMI. The guide includes SageMaker Python SDK code and a recommended instance table (e.g. ml.g6.48xlarge with 8 GPUs for the 70B distill), plus Neuron settings such as 24 cores, bf16, batch size 4 and 4096 total tokens using pre-compiled models. The full R1 runs on Inference Endpoints as an Unsloth GGUF quantization for about $8.3/hour, while full-R1 SageMaker deployment and all fine-tuning paths are still marked as coming soon.
Related posts
- Introducing the Hugging Face LLM Inference Container for Amazon SageMaker
Hugging Face mediumAdeptHugging Face's LLM Inference Deep Learning Container for Amazon SageMaker is built on Text Generation Inference (TGI), which provides tensor parallelism, continuous batching, flash-attention, bitsandbytes quantization, safetensors loading and SSE token streaming. The walkthrough deploys the 12B Pythia Open Assistant model on an ml.g5.12xlarge instance (4 A10G GPUs) using the sagemaker Python SDK, with environment variables for GPU count and token limits. It then covers TGI generation parameters such as temperature, top_p, stop sequences and repetition penalty, and builds a Gradio chatbot on top of the endpoint. For a cheaper setup, a g5.2xlarge with int8 quantization is suggested.
- Deploy Hugging Face models easily with Amazon SageMaker
Hugging Face mediumAdeptHugging Face Inference Deep Learning Containers and the SageMaker Hugging Face Inference Toolkit let Transformers models be deployed as SageMaker endpoints with a few lines of Python, using transformers pipelines for zero-code pre- and post-processing. Models can be deployed straight after a SageMaker training job via the Estimator, from a model.tar.gz in S3 via HuggingFaceModel's model_data, or directly from the Model Hub by setting the HF_MODEL_ID and HF_TASK environment variables. Requests use an `inputs` key plus optional pipeline `parameters`, and custom inference code can override the defaults when needed.
- Hugging Face Text Generation Inference available for AWS Inferentia2
Hugging Face mediumAdeptText Generation Inference (TGI) is now generally available on AWS Inferentia2 through Amazon SageMaker, offering an alternative to GPUs for serving open LLMs such as Llama and Mistral. A walkthrough deploys Zephyr 7B on an ml.inf2.8xlarge using the TGI Neuronx container. Because Inferentia2 lacks dynamic shapes, batch size, sequence length, core count and cast type must be fixed at compile time. A neuron model cache provides pre-compiled configurations; compiling an uncached one with optimum-cli can take up to 45 minutes. The deployment environment variables (HF_NUM_CORES, HF_BATCH_SIZE, HF_SEQUENCE_LENGTH, MAX_TOTAL_TOKENS) must match those compile-time settings.
- The Partnership: Amazon SageMaker and Hugging Face
Hugging Face mediumAdeptHugging Face and AWS partner, making AWS Hugging Face's preferred cloud and introducing Hugging Face Deep Learning Containers plus a HuggingFace Estimator in the SageMaker Python SDK for training Transformers models. An end-to-end walkthrough fine-tunes DistilBERT on IMDB binary sentiment classification: setting up a SageMaker session and IAM role, writing a Trainer-based train.py that reads SageMaker environment variables, tokenizing and uploading datasets to S3, and launching a training job with estimator.fit(). The containers also support SageMaker's data-parallel and model-parallel distributed training libraries through a distribution parameter, along with automatic hyperparameter tuning.
- Introducing the Hugging Face Embedding Container for Amazon SageMaker
Hugging Face mediumAdeptThe Hugging Face Embedding Container for Amazon SageMaker, built on Text Embedding Inference (TEI), is now generally available for deploying open embedding models such as Snowflake Arctic Embed and BGE. TEI uses token-based dynamic batching, Flash Attention and Candle, and ships separate CPU and GPU images. A walkthrough with the sagemaker Python SDK covers retrieving the image URI, deploying snowflake-arctic-embed-m-v1.5 and load testing it. In the test, embedding ~1M tokens took about 841s (~5 req/s, 2s latency) on a ~$150/month CPU instance versus about 30s (~130 req/s, 4ms latency) on an ml.g5.xlarge A10G GPU at $1.408/hour. The recommendation is GPUs for bulk embedding and CPUs for low-cost endpoints.