Slide 1

Slide 1 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 3 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Yoshitaka Haribara, Ph.D. A W S S T A R T U P L O F T T O K Y O Sr. GenAI/Quantum Startup Solutions Architect AWS 🐳 DeepSeek を AWS で動かす!

Slide 2

Slide 2 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4 • 背景: Reasoning (論理的推論) と Chain-of-Thought (CoT) • DeepSeek-R1 と蒸留モデルの概要 • AI アクセラレータ: NVIDIA H200 GPU と AWS Trainium, Inferentia • AWS サービスの選択: Amazon Bedrock Marketplace, Amazon SageMaker AI, Amazon EC2 • ハンズオン: Amazon Bedrock Marketplace, Amazon SageMaker (ml.inf2.xlarge) Agenda

Slide 3

Slide 3 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5 Generative Pre-trained Transformer (GPT) に代表されるように、大量の学習 データを用いた自己教師あり学習により、高い汎化性能を持つ言語モデル: LLM 事前学習 (Pre-training) は重要なパラダイムであり、スケーリング則 (モデル サイズ・データ量・計算リソース) を増やすと性能が単調増加: Scaling law Supervised Finetuning (SFT) や Chain-of-Thought (CoT) に代表される In-context learning といった事後学習が徐々に脚光を浴び、 推論に時間をかけることで高い性能が達成されるようになってきた LLM の学習: 事前学習・事後学習

Slide 4

Slide 4 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 6 課題: 元々 LLM は算数や論理的推論が不得意 (cf. 非形式的 演繹的 推論; Informal deductive reasoning) これを克服するため、以下のような手法が研究・提案されてきた (後述) • Chain-of-Thought (CoT) • Zero-shot CoT • CoT with Self-consistency (Multi-path CoT) • Tree of thought (ToT) Reasoning (論理的推論)

Slide 5

Slide 5 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 7 LLM に中間的な推論ステップを生成させることで、論理的推論能力が向上 モデル入力 Q: ロジャーは🎾を5個持っている。2缶の🎾を買い足した。 1缶には3個の🎾が入ってる。今、彼は合計で何個の🎾を持ってる? A: ロジャーは🎾を最初5個持っていた。3個入り x 2缶分 (6個) 🎾を買い足した。 5 + 6 = 11で、答えは11個。 Q: カフェテリアに🍏が23個あった。そのうち20個をランチの準備に使い、 新たに6個買い足した。今、カフェテリアに🍏は何個? モデル出力 A: カフェテリアには最初🍏が23個。ランチの準備に20個使った。 よって23 - 20 = 3個に。6個買い足し、3 + 6 = 9個。答えは9個。 Chain-of-Thought (CoT) [arXiv:2201.11903]

Slide 6

Slide 6 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 8 “Let‘s think step by step” (「ステップバイステップで考えよう」) と言うだけ モデル入力: Q: ジョンは16個のフルーツを買いたい。 フルーツの半分はリンゴで、そのの半分は🍏にする。🍏は何個? A: ステップバイステップで考えよう。 モデル出力: フルーツは全部で16個。 フルーツの半分がリンゴ、つまりリンゴは8個。 リンゴの半分が🍏、つまり🍏は4個。 Zero-shot CoT [arXiv:2205.11916]

Slide 7

Slide 7 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9 複数経路の推論を行いそれらの回答から最終的な結果を導く ジャネットの🪿は1日に16個の🥚を産む。彼女は毎朝3個を朝食に食べ、 毎日4個を使って友人のためにマフィンを焼く。残りの🥚は1個2ドルで売る。 彼女は毎日いくら稼げる? • 彼女は16 - 3 - 4 = 9個の🥚が残る。∴ 1日に2ドル × 9 = 18ドル稼ぐ。 • 彼女は残りの卵を2ドル × (16 - 4 - 3) = 26ドルで売ることになる。 • 彼女は朝食に3個食べ、16 - 3 = 13個が残る。次にマフィンを焼き、13 - 4 = 9個の卵が残る。∴ 9個の卵 × 2ドル = 18ドル ⇒ 答えは18ドル Multi-path CoT with Self-consistency [arXiv:2203.11171]

Slide 8

Slide 8 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10 木構造のような思考プロセスにより解を探索 Tree of thought (ToT) [arXiv:2305.08291, arXiv:2305.10601] ToT 論文 [arXiv:2305.10601] より

Slide 9

Slide 9 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 13 課題: LLM で事後学習に強化学習を使うと計算量が多くなる 事前学習済み DeepSeek-V3-Base をベースに、強化学習フレームワークとして Group Relative Policy Optimization (GRPO) [arXiv:2402.03300] を採用 DeepSeek-R1-Zero [arXiv:2501.12948] DeepSeekMath [arXiv:2402.03300] の図を改変 Rule-based

Slide 10

Slide 10 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 14 課題: 可読性や言語の混在 強化学習する前に少量のコールドースタートデータと複数ステージ学習: • DeepSeek-V3-Base の fine-tuining のため数千のコールドスタートデータ収集 • DeepSeek-R1-Zero のように Reasoning 重視の強化学習 • 強化学習が収束しそうな時点で棄却サンプリングにより SFT データを収集。 DeepSeek-V3 のドメイン教師データ (writing, factural QA, self-congnition) も 合わせる • DeepSeek-V3-Base を再学習 (SFT) • 学習後、全てのシナリオで強化学習させたチェックポイントが DeepSeek-R1 DeepSeek-R1 [arXiv:2501.12948]

Slide 11

Slide 11 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 15 DeepSeek-R1 から蒸留したモデル: Qwen と Llama の2系統 • DeepSeek-R1-Distill-Qwen (1.5B, 7B, 14B, 32B) • DeepSeek-R1-Distill-Llama (8B, 70B) DeepSeek-R1-Distill (蒸留モデル) [arXiv:2501.12948] https://github.com/deepseek-ai/DeepSeek-R1

Slide 12

Slide 12 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 16 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 は 複数のタスクにおいて 高度な論理的推論能力を発揮

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 19 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, Inferentia H100, H200, B200, GB200, A100, L40S, L4, A10G Cloud AI100 Standard Radeon GPU Xilinx accelerator Xilinx FPGA DL2q Gaudi accelerator Announced GB200 B200

Slide 16

Slide 16 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 20 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

Slide 17

Slide 17 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 23 P5 インスタンス Optimized for AI training and inference 900 GB/s NVSwitch for GPU peer-to-peer connections Scale-out with non-blocking interconnect 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

Slide 18

Slide 18 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 24 G5/G6 インスタンス G Compute and graphics optimized GPUs Flexibility with multiple instance sizes Great for single GPU or single node workloads 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

Slide 19

Slide 19 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 25 Bedrock Marketplace implementation • Bedrock Marketplace で DeepSeek-R1 と蒸留モデルが利用可能 • 簡単デプロイ • Bedrock のセキュリティ・モニタリング機能が 利用できる

Slide 20

Slide 20 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 26 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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 32 ハンズオン1: Amazon Bedrock Marketplace • Amazon Bedrock を開く • Model catalog を開く • DeepSeek と打ち込んでフィルター • DeepSeek-R1-Distill-Llama-8B などを選んでデプロイ • Marketplace deployments に表示されてるモデルを選び Playground • https://gist.github.com/hariby/c6b4d1f7ceee8e976b8b752c388d7ae5

Slide 26

Slide 26 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 36 Tips: 適切な chat template (model tokenizer) を利用 36 <|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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 38 Enterprise Protection • Enterprise-grade security features built-in • Complete data privacy when using AWS services • No data sharing with model providers • End-to-end encryption for all operations • Access controls and governance features • Compliance with AWS security standards

Slide 29

Slide 29 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 39 Critical Concerns • Models hosted by AWS without any communication with DeepSeek servers or APIs • No customer data used to improve base models • Enterprise data protection capabilities • Privacy control through AWS services

Slide 30

Slide 30 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 43 Custom Model Import implementation • Bedrock Custom Model Import enables DeepSeek deployment • Support for Llama 8B and 70B distilled DeepSeek R1 variants • Complete code samples and step-by-step deployment guides provided for quick implementation • Standard Bedrock security and monitoring features • Pricing is on-demand in 5-minute window from first successful invocation • There is a cold-start and scaling up/down time

Slide 31

Slide 31 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 49 Customizing & Deploying models with Amazon SageMakerAI Select Evaluate Customize Deploy Amazon Build, train, and deploy ML models—including FMs—for any use case with fully managed infrastructure, tools, and workflows Data Scientists and ML Engineers Bring Your Own Model Bring Your Own Container Choice of hundreds of models from SageMaker JumpStart Automated & Human evaluation of models Customize models to your use cases by pre-training, fine-tuning, model distillation, etc. Optimize and deploy for inference

Slide 32

Slide 32 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 61 Trn1/Trn2 インスタンス Powered by AWS Trainium/Trainium2 custom ML chips Optimized for large-scale training distributed workloads Trn2 Ultraservers with extended NeuronLink for trillion-parameter AI Neuron Kernel Interface (NKI) for custom operators 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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 63 ハンズオン2: Amazon SageMaker AI • SageMaker AI のページを開く • Notebook インスタンスを作る (CPU インスタンスで ok) • Hugging Face で使いたいモデルを選び、 Deploy > Amazon SageMaker から Python スクリプトをコピー https://huggingface.co/collections/deepseek-ai/deepseek-r1 • deepseek-ai/DeepSeek-R1-Distill-Llama-8B • Noteobok インスタンス上から SageMaker Python SDK で エンドポイントに DeepSeek-Distill モデルデプロイ

Slide 35

Slide 35 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 64 ハンズオン2: Amazon SageMaker AI • SageMaker Notebook インスタンスの Jupyter Notebook に Python スクリプトを貼り付ける • huggingface_model.deploy: デプロイ, predictor.predict: 推論

Slide 36

Slide 36 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 66 DeepSeek-R1 on AWS まとめ 1. Amazon Bedrock Marketplace (Amazon SageMaker JumpStart) で DeepSeek-R1/Distill モデルのデプロイ 2. Amazon SageMaker AI Inf2 インスタンスへ DeepSeek-R1-Distill モデルのデプロイ 3. Amazon Bedrock Custom Model Import で DeepSeek-R1-Distill モデルのデプロイ DeepSeek on AWS ブログもあります ↑ https://aws.amazon.com/jp/blogs/news/deepseek-r1-models-now-available-on-aws/

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 69 Thank you! © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Yoshitaka Haribara, Ph.D. X: @_hariby

Slide 39

Slide 39 text

© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. 70 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/