Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DeepSeek を AWS で動かしてみよう!!

Soh Ohara
February 25, 2025
75

DeepSeek を AWS で動かしてみよう!!

2025/02/25 「【DeepSeek解剖!】使い方から技術の核心まで」https://ai-fest-tokyo.connpass.com/event/345811/
のイベントの登壇で使用した資料になります。

Amazon Bedrock Marketplace: https://aws.amazon.com/bedrock/marketplace/

Amazon Bedrock Custom Model Import での使い方: https://aws.amazon.com/jp/blogs/news/deploy-deepseek-r1-distilled-llama-models-with-amazon-bedrock-custom-model-import/

SageMaker AI でのデプロイ方法: https://huggingface.co/blog/deepseek-r1-aws

DeepSeek on AWS ブログ: https://aws.amazon.com/jp/blogs/news/deepseek-r1-models-now-available-on-aws/

書籍「AWS のための生成 AI アプリ構築実践ガイド」https://www.amazon.co.jp/dp/4296205234

Soh Ohara

February 25, 2025
Tweet

Transcript

  1. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 1 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Soh Ohara Startup Solutions Architect AWS DeepSeek を AWS で動かしてみよう
  2. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 2 2 ⾃⼰紹介 尾原 颯 アマゾン ウェブ サービス ジャパン合同会社 ソリューションアーキテクト スタートアップ(⽣成 AI ・ヘルスケア)の お客様中⼼に技術⽀援をしています。 東京⼤学⼯学部機械⼯学科卒業. 学⽣時代は ヘルスケアスタートアップなどにて 機械学習エンジニアインターン 3⽉に初ハーフマラソンに挑戦 🏃 著書 @soh_ohara 𝕏
  3. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 3 AWS LLM 開発⽀援プログラム (2023 年) 国内に法⼈または拠点を持つ 17 の企業・団体を⽀援 会社・団体名(社名五⼗⾳順・敬称略) カラクリ株式会社・株式会社サイバーエージェント・ストックマーク株式会社・Sparticle 株式会社・Turing 株式会社・ ⽇本電信電話株式会社・株式会社 Preferred Networks・株式会社 Poetics・ 株式会社松尾研究所・株式会社マネーフォワード・株式会社ユビタス・株式会社 Lightblue・ 株式会社リクルート・株式会社リコー・rinna 株式会社・株式会社ロゼッタ・株式会社わたしは ふりかえり ※企業・団体名はプログラム採択発表当時のものです
  4. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 4 引⽤元: https://www.meti.go.jp/policy/mono_info_service/geniac/index.html (経済産業省)
  5. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 5 引⽤元: https://www.meti.go.jp/policy/mono_info_service/geniac/index.html (経済産業省) GENIAC で予定する GPU リソース確保⽅式のうち、 「経済産業省がリソース提供事業者から⼀括で確保し提案者に提供」 ⽅式について AWS を採⽤ (2024 年 7 ⽉ 16 ⽇公開)
  6. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 6 • AI アクセラレータ: NVIDIA H200 GPU と AWS Trainium, Inferentia • AWS サービスの選択: Amazon Bedrock Marketplace / Custom Model Import • Amazon SageMaker AI • Amazon EC2 Agenda
  7. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 7 DeepSeek: オープン重みモデルといくつかの蒸留モデル ベース (V3) と R1 モデル (671B パラメータ) • DeepSeek-V3: ベース Mixture of Expert (MoE) モデル • DeepSeek-R1-Zero: 強化学習のみ • DeepSeek-R1: コールドスタートデータして強化学習 Distilled Models • DeepSeek-R1-Distill-Qwen (1.5B, 7B, 14B, 32B) • DeepSeek-R1-Distill-Llama (8B and 70B) DeepSeek で、複数のタスクにおいて ⾼度な推論能⼒を活⽤可能に
  8. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 8 Core Capabilities • 複雑な問題解決のための⾼い論理的推論能⼒ (数学やコーディングへの応⽤) • AIME 2024, MATH-500, and SWE-bench などの ベンチマークで⾼い性能 • 671B パラメータの Mixture of Experts (MoE) アーキテクチャ • 37B activation parameter • DeepSeek-R1 の推論には FP8 で少なくとも 800 GB of HBM が必要
  9. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 9 AI/ML 向け EC2 アクセラレータインスタンス G6 (L4) P5 (H100) DL1 G6e (L40S) P4 (A100) P5e (H200) Inf1 Inf2 P5en (H200) Trn1 GPUs AI/ML accelerators and ASICs Trn2 G5 (A10G) AWS Trainium, AWS Inferentia H100, H200, B200, GB200, A100, L40S, L4, A10G Cloud AI100 Standard Radeon GPU Xilinx accelerator Xilinx FPGA DL2q Gaudi accelerator Announced GB200 B200
  10. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 10 CPU CPU NSC EBS Host EFA PCIe SSD EFA SSD … Switching layer PCIe PCIe PCIe ML chip interconnect ML chip ML chip ML chip ML chip … Accelerators Accelerated compute architecture
  11. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 11 P5 インスタンス AI の学習や推論に最適化 GPU 間で 900 GB/s の NVSwitchを使った通信 ノンブロッキングネットワークである Elastic Fabric Adapter (EFA)による相互接続を使った スケールアウト Instance GPU GPU memory CPU vCPU Instance memory Networking Local storage P5 8 NVIDIA H100 640 GB AMD Milan 192 2 TB 3200 Gbps EFAv2 30 TB SSD P5e 8 NVIDIA H200 1128 GB AMD Milan 192 2 TB 3200 Gbps EFAv2 30 TB SSD P5en 8 NVIDIA H200 1128 GB Intel SPR 192 2 TB 3200 Gbps EFAv3 30 TB SSD
  12. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 12 G5/G6 インスタンス G コンピュートやグラフィクスに最適化された GPU 複数のインスタンスサイズによる柔軟性 単⼀ GPU もしくは単⼀ノードでのワークロードに適合 Instance GPU GPU memory CPU vCPU Instance memory Networking Local storage G5 Up to 8 NVIDIA A10G Up to 192 GB AMD Rome Up to 192 Up to 768 GB Up to 100 Gbps Up to 7.6 TB SSD G6 Up to 8 NVIDIA L4 Up to 192 GB GDDR6 AMD Milan Up to 192 Up to 768 GB Up to 100 Gbps Up to 7.6 TB SSD G6e Up to 8 NVIDIA L40S Up to 384 GB GDDR6 AMD Milan Up to 192 Up to 1.536 TB Up to 400 Gbps Up to 7.6 TB SSD
  13. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 13 Bedrock Marketplace での実装 • Bedrock Marketplace で DeepSeek-R1 と蒸留モデルが利⽤可能 • 簡単デプロイ • Amazon Bedrock のセキュリティ・ モニタリング機能が利⽤できる ml.p5e.48xlarge を使ったデプロイになるので、 インスタンス料⾦だけで $124.375/hour かかる
  14. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 14 • コンソール画⾯で完結するシンプルな開発ワークフロー • カスタムスケールポリシーを指定した マネージドなエンドポイントでモデルをデプロイ • Agents、Knowledge Bases、Guardrails などの Amazon Bedrockが提供するツールとのネイティブ統合 • セキュアな API 経由でモデルへアクセスが可能 • ⽇本企業が提供するモデルも利⽤可能 • CyberAgentLM3-22B-Chat KARAKURI LM 8x7B Instruct、 Preferred Networks PLaMo、Stockmark LLM 13B (※アルファベット順) Amazon Bedrock Marketplace (GA) 100以上のモデルを Amazon Bedrock 上でテスト、検索、利⽤ https://aws.amazon.com/bedrock/marketplace/ ⼀ 般 利 ⽤ 開 始
  15. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 15 Bedrock Marketplace delivers 100+ models from 30+ providers EVOLUTIONARY SCALE WIDN CAMB.AI GRETEL ARCEE AI PREFERRED NETWORKS WRITER UPSTAGE NCSOFT STOCKMARK KARAKURI JOHN SNOW LABS LIQUID DATABRICKS CYBERAGENT HUGGING FACE STABILITY AI LG AI RESEARCH M I S T R A L AI SNOWFLAKE N V I D I A DEEPSEEK
  16. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 16 事前準備: デプロイ前に上限緩和 (R1: ml.p5e.48xlarge)
  17. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 17 Step1: Model catalog で DeepSeek-R1 モデルを⾒つける
  18. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 18 Step2: デプロイ
  19. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 19 Step3: Playground か InvokeModel API で遊ぶ
  20. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 20 Tips: 適切な chat template (model tokenizer) を利⽤ Example with DeepSeek-Distill-Llama-8B (via Bedrock CMI) 20 <|begin▁of▁sentence|><|User|>A man has 53 socks in his drawer: 21 identical blue, 15 identical black and 17 identical red. The lights are out, and he is completely in the dark. How many socks must he take out to make 100 percent certain he has at least one pair of black socks?<|Assistant|> Bedrock Playground で使う際には、適切な chat template タグをつける必要がある: InvokeModel API を使う場合、適切な tokenizer を使う必要がある: tokenizer = AutoTokenizer.from_pretrained(hf_model_id) messages = [{"role": "user", "content": test_prompt}] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=not continuation) Bad quality output Good quality output
  21. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 21 DeepSeek-R1 利⽤における「責任ある AI」 21 (through the ApplyGuardrail API) can provide an extra layer of security and responsible AI measures
  22. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 22 エンタープライズレベルの 保護 • エンタープライズグレードのセキュリティ機能を内蔵 • AWS サービス利⽤時の完全なデータプライバシー • モデルプロバイダーとのデータ共有なし • すべての操作におけるエンドツーエンドの暗号化 • アクセス制御とガバナンス機能 • AWS セキュリティ基準への準拠
  23. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 23 重⼤な懸念事項 • AWSによってホストされるモデルで、DeepSeekサーバー やAPIとの通信なし • ベースモデルの改善に顧客データは使⽤されない • エンタープライズレベルのデータ保護機能 • AWSサービスを通じたプライバシー管理
  24. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 26 モデル選択肢 • レイテンシ・コストを抑えつつ コア機能を保った蒸留モデル • 複数サイズを要件に応じて選択 • DeepSeek-R1-Distill-Qwen (1.5B, 7B, 14B, 32B) • DeepSeek-R1-Distill-Llama (8B, 70B)
  25. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 27 Custom Model Import での実装 • Bedrock Custom Model Import で DeepSeek-R1 モデルのデプロイが可能 • Llama 8B と 70B の DeepSeek R1 Distilled モデルをサポート • 迅速な実装のためのコードサンプルとステップごとのデプロ イガイドを提供 • Amazon Bedrock の標準的なセキュリティ機能と モニタリング機能を利⽤可能 • 最初のモデル呼び出し成功から、5分窓の オンデマンド料⾦体系 • コールドスタート・スケールアップ・ダウンの 時間が発⽣に注意 8B モデルであれば $0.1570/minute + $3.90/month から利⽤可能 (70B ではざっくり4倍) https://aws.amazon.com/jp/blogs/news/deploy-deepseek-r1-distilled-llama-models-with-amazon-bedrock-custom-model-import/ 詳細なやり⽅は こちらのブログを チェック︕
  26. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 29 Trn1/Trn2 インスタンス 独⾃ MLチップ AWS Trainium/Trainium2 を利⽤ ⼤規模な分散学習ワークロードに最適化 1兆パラメータ級モデルのための NeuronLink を使った Trn2 UltraServers Neuron Kernel Interface (NKI) カスタムオペレーションを実装 Instance Accelerators Accelerator memory vCPU Instance memory Networking trn1.32xlarge 16 512 GB 128 512 GB 800 Gbps EFAv2 trn1n.32xlarge 16 512 GB 128 512 GB 1600 Gbps EFAv2 trn2.48xlarge 16 1.5 TB 192 2 TB 3.2 Tbps EFAv3
  27. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 30 AWS Trainium アーキテクチャ • Tensor engine are based on power-optimized systolic array • AWS Neuron SDK supports typical architecutres such as Llama
  28. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 31 Amazon EC2 Inf2 instances powered by AWS Inferentia2 ⽣成 AI モデルのための最低価格でハイパフォーマンスなインスタンス Instance size vCPUs Instance memory Inferentia2 chips Chip memory NeuronLink Instance networking On-demand price 3Yr RI price Inf2.xlarge 4 16 GB 1 32 GB N/A Up to 15 Gbps $0.76/hr $0.30/hr Inf2.8xlarge 32 128 GB 1 32 GB N/A Up to 25 Gbps $1.97/hr $0.79/hr Inf2.24xlarge 96 384 GB 6 192 GB Yes 50 Gbps $6.49/hr $2.60/hr Inf2.48xlarge 192 768 GB 12 384 GB Yes 100 Gbps $12.98/hr $5.19/hr 最⼤ 4 倍のスループットと 1/10 のレイテンシ (vs. Inf1) 同等インスタンスに⽐べて最⼤ 80% ⾼いコストあたりのスループット 同等インスタンスに⽐べて最⼤ 74% 低いレイテンシー
  29. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 32 Amazon SageMaker AI Model Inference 32 1 2 3 MLモデルの準備 Configure endpoint リアルタイム HTTP リクエスト Model artifacts コンテナイメージ IAM ロール 準備した ML model デプロイモード コンピュート / GPU の 選択 オートスケールポリシー SageMaker Endpoint secure, elastic, managed クライアントアプリ 推論 リクエスト 推論 結果 モデルサーブスタック input Bring your own models, containers, and algorithms; or use ones provided by AWS. Example above illustrates “Real-time Inference.” v DeepSeek-R1 / DeepSeek-distilled モデルは SageMaker エンドポイントでデプロイが可能
  30. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 33 SageMaker AI でのデプロイ⽅法は 下記ブログをチェック︕ https://huggingface.co/blog/deepseek-r1-aws (g6/inf2 インスタンスでのデプロイ⽅法について解説)
  31. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 36 DeepSeek-R1 on AWS まとめ 1. Amazon Bedrock Marketplace (Amazon SageMaker JumpStart) で DeepSeek-R1/Distill モデルのデプロイ 2. Amazon Bedrock Custom Model Import で DeepSeek-R1-Distill モデルのデプロイ 3. Trn1/Inf2 インスタンスを使った DeepSeek-R1-Distilled モデルのデプロイ (EC2 / SageMaker エンドポイントでのデプロイ) DeepSeek on AWS ブログ ↑ https://aws.amazon.com/jp/blogs/news/deepseek-r1-models-now-available-on-aws/
  32. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 37 モデル Amazon Bedrock Marketplace / SageMaker JumpStart / SageMaker Real-time endpoint Amazon Bedrock Custom Model Import (us-east-1、us-west-2 のみ) Amazon EC2 G5/P5 インスタンス Amazon EC2 / Amazon SageMaker Inf2 インスタンス DeepSeek-R1 $124.3725/hour (ml.p5e.48xlarge) 東京リージョン未対応 N/A $84.80/hour (EC2, p5e.48xlarge) 東京リージョン未対応 N/A Distilled-Llama-8B $2.197/hour (ml.g5.2xlarge), $0.157/min + $3.80/month $9.42/hour + $3.80/month 東京リージョン未対応 $1.212/hour (g5.2lxarge) $0.7582/hour (EC2, inf2.xlarge) $0.99/hour (SageMaker, ml.inf2.xlarge) Distilled-Llama-70B $20.36/hour (ml.g5.48xlarge) $0.628/min + $15.60/month $37.68/hour + $15.60/month 東京リージョン未対応 $16.288/hour (g5.48xlarge) $12.9817/hour (EC2, inf2.48xlarge) $15.58/hour (SageMaker, ml.inf2.48xlarge) Distilled-Qwen-7B $2.197/hour (ml.g5.2xlarge), N/A $1.212/hour (g5.2lxarge) N/A Distilled-Qwen-32B $7.09/hour (ml.g5.12xlarge) N/A $5.673/hour (g5.12xlarge) N/A ※オハイオ(us-east-2)リージョンでの料⾦ モデル間のデプロイオプションと料⾦⽐較 2025年02⽉25⽇ 時点 ※複数のインスタンスサイズ・種類でデプロイできるため、料⾦は⼀例
  33. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 38 実際に動かしてみよう
  34. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 39 AWSのための⽣成AIアプリ構築実践ガイド ⽣成AIアプリを構築するための基礎概念を解説 (プロンプトエンジニアリング、RAG、エージェント) 基礎概念の応⽤をするためのより実践的なハンズオン (RAG、エージェント) 本番導⼊するためのポイントも解説 (責任ある AI、Working Backwards etc) 対象読者︓⽣成 AI の本格活⽤を検討している技術者 39 2025年春頃発売予定︕ https://www.amazon.co.jp/dp/4296205234
  35. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 40 Thank you! © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Soh Ohara X: @soh_ohara
  36. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 41 Further reading • DeepSeek • Anthropic CEO Dario Blog • https://darioamodei.com/on-deepseek-and-export-controls • Startup Customer Case Studies on AWS • Sakana AI • https://aws.amazon.com/startups/learn/letting-nature-lead-how-sakana-ai-is- transforming-model-building?lang=en-US • ELYZA (Llama2 Speculative Decoding on AWS Inferentia2 chip) • https://aws.amazon.com/jp/blogs/startup/tech-interview-elyza-2024/ • LLM Development on Trn1 • https://aws.amazon.com/jp/blogs/machine-learning/unlocking-japanese-llms- with-aws-trainium-innovators-showcase-from-the-aws-llm-development-support- program/
  37. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 42 Distilled Llama DeepSeek-R1 のデプロイ時の料⾦計算例 42 Pricing example 1 - Experimentation: • DeepSeek-R1-Distill-Llama-8B (128K seq. length) を us-east-1 で利⽤開始し、5時間後に消去 • 2 Custom Model Units が必要なので、1分あたり $0.157 と⽉当たりのストレージコスト $3.90 がかかる • 5 hours の間テストように⽴ち上げる • ⽉額コスト: 5 時間 x $0.157 + $3.90 = $4.69 Pricing example 2 – Production app: • DeepSeek-R1-Distill-Llama-70B (128K seq. length) を us-east-1 で利⽤開始し、1ヶ⽉後に消去 • 8 Custom Model Units が必要なので、1分あたり $0.628 と⽉あたりのストレージコスト $15.60 がかかる • ユーザーは1⽇あたり 8 時間エンドポイント利⽤ • Total for the month: 20 days x 8 hours x $0.628 + $15.60 = $116.08