You are on page 1of 40

AWS 기반 비용 효율적 고성능

기계학습(ML) 플랫폼 뛰어들기


윤석찬 / AWS 테크니컬 에반젤리스트

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
본 세션에서 다루는 점

 클라우드 기반 기계 학습 및 딥러닝 모델 훈련 방법을 알고


싶으세요?

 시간과 비용을 적게 들이고 빠르게 좋은 모델을 만들고


싶으세요?

 모델 훈련 및 서비스까지 자동화 하는 방법에 대한 고민이


많으세요?

 추론 작업을 좀 더 빠르게 하는 방법을 알고 싶으세요?

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
모든 개발자를 위한 인공 지능 도구 제공
VISION CHATBOTS SPEECH LANGUAGES VERTICAL

Amazon Amazon Amazon Amazon Amazon


AI 서비스
Amazon Amazon Amazon Amazon Amazon
Rekognition Rekognition Lex Polly Transcribe Comprehend Translate Personalize Forecast
Image Video Textract
NEW NEW NEW

NEW NEW NEW NEW


Amazon
ML 서 비 스 SageMaker
Ground Truth Notebooks Algorithms + Marketplace RL Training Optimization Deployment Hosting

NEW NEW

P3 P3dn C5 C5n Elastic inference Inferentia AWS Greengrass


ML 프 레 임 워 크
+ 인프라
FRAMEW ORKS INTERFACES INFRASTRUCTURE

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Deep Learning AMIs
다양한 딥러닝 프레임워크를 미리 설치하고
최적 설정을 완료한 머신 이미지(Machine Image) 제공

Conda AMI Base AMI AMI with source code


별도 가상 환경에 사전 설치된 딥 개별 딥러닝 엔진 리포지토리 공유 Python 개발 환경에서 DL
러닝 프레임워크 및 PIP 패키지 또는 맞춤형 빌드를 설치 엔진 및 소스 코드를 함께 제공
제공 가능
(우분투, 아마존리눅스, 윈도용) (우분투, 아마존리눅스용)

https://aws.amazon.com/machine-learning/amis/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
심지어 Deep Learning AMI는 진짜 빠릅니다!
차세대 C5 인스턴스에서 Intel AVX 및 MKL-dnn에 최적화된 TensorFlow 1.6 포함
ImageNet 데이터세트로 일반 바이너리 버전 대비 7.4배 빠른 모델 훈련 속도 제공

https://aws.amazon.com/ko/blogs/machine-learning/faster-training-with-optimized-
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. tensorflow-1-6-on-amazon-ec2-c5-and-p3-instances/
여기서 잠깐! C5 인스턴스 이란?
차세대 클라우드 가상화 환경인 Nitro를 기반한 컴퓨팅 전용 타입

C4 C5
36 vCPUs 72 vCPUs
2X vCPUs

“Haswell” “Skylake” AVX 512


2X performance
Intel® AVX-512 고급 명령어
세트를 지원하므로 AI/기계 학습 4 Gbps to EBS 12 Gbps to EBS
또는 동영상 처리와 같은 단일 및
3X throughput
이중 부동 소수점 정밀도 기반
벡터 처리 작업을 효율적으로 60 GiB memory 144 GiB memory
수행
2.4X memory

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EC2 P3 인스턴스 - 클라우드 기반 고성능 GPU 지원
1 PetaFLOPs의 컴퓨팅 성능 제공
300 GB/s GPU-to-GPU(NVLink) 네트워크 속도

P3 인스턴스 세부 정보
• NVIDIA Tesla V100 GPU 기반
• 40,960 CUDA cores 및 5120 Tensor Codes
• 128GB의 GPU 메모리
• 최대 8개의 GPU를 지원하는 다양한 인스턴스
타입 (p3.2xlarge, 8xlarge 및 16xlarge) 제공

만약… 인터넷에서 구매하시면?

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EC2 P3 인스턴스로 GPU 클러스터를 만들어 본다면?

p3.2xlarge
= $5 per hour
(서울 리전 기준)

초당 1페타플롭스 (CPU 100개에 해당 하는 연산 능력)

p3.2xlarge x 20
x 20
= $100 per hour
CPU 2,000 개 연산 능력
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
남는 여유 자원을 70% 할인된 가격에
모델 훈련 시에만 사용한다면
= $30 per hour
손으로 하실 필요 없어요~ 인프라를 코드로 짜면 됩니다!
API와 데브옵스를 통해 손쉽게 딥러닝 클러스터 구성 가능
다양한 CI/CD 기반 데브옵스 환경으로 빠른 학습 가능

$aws ec2-run-instances ami-b232d0db


--instance-count 1
--instance-type p2.8xlarge
--region us-east-1
--user-data my_data_training.sh

$aws ec2-stop-instances i-10a64379

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
여러분… 인생은 짧습니다! 시간을 아끼세요~

• 16개의 P3.16xlarge 인스턴스를 사용해서


18분만에 ResNet-50 모델 학습 완료 (정확도 93%)
• 저렴한 스팟 인스턴스 구매 옵션을 활용하여 $40 비용에 처리 가능
• PyTorch 기반으로 기존 DAWNBench 기록 보다 40% 빠른 속도
http://www.fast.ai/2018/08/10/fastai-diu-imagenet/
https://aws.amazon.com/blogs/machine-learning/new-speed-record-set-for-training-deep-learning-models-on-aws/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
여기서 잠깐… 시간을 더 아끼시려면?
16 Resnet 152

Inceptin V3

12.25 Alexnet
Speed up (x)

Ideal

8.5 91% 88%


Efficiency Efficiency
4.75

1
1 4.75 8.5 12.25 16 # GPUs

P2.16xlarge (8 Nvidia Tesla K80 - 16 GPUs) 16x P2.16xlarge by AWS CloudFormation


Synchronous SGD (Stochastic Gradient Descent) Mounted on Amazon EFS

Apache MXNet은 GPU 갯수가 증가하더라도 이상적인 수준의 성능을 보여주는


오픈 소소 딥러닝 프레임워크로서 멀티 GPU 환경에서 탁월한 성능 제공
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
MXNET 공부하세요…
아직은 블루오션입니다!
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo - 딥러닝 AMI와 스팟 인스턴스 구동하기

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
기계학습은 일반 개발자에게 여전히 복잡하고 어렵다?!

데이터 수집 괜찮아 보이는 모델 훈련


모델 훈련을 최적화한 API 서비스
및 저장 및 기계학습
전처리 알고리즘 선택
위한 서버 및 튜닝 모델 배포 확장 및 운영
인프라 설정 (계속 반복)

지겨운 데이터 전처리… 모델 튜닝… 될때까지 계속 반복&반복

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
그래서 준비했습니다… Amazon SageMaker

모델 개발 및 생성, 훈련 및 서비스 배포를 위한 완전 관리 서비스

Jupyter 고성능 원클릭 Hyper- 원클릭 완전 관리


Notebook 알고리즘 데이터 parameter 모델 및 자동
기반 서비스 미리 제공 훈련 최적화 배포 스케일링

모델 생성 모델 훈련 모델 배포

https://aws.amazon.com/ko/sagemaker
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SageMaker를 통한 ML 서비스 아키텍처

Build Train static website


hosted on S3

Web assets on
Cloudfront
Amazon
SageMaker Training SageMaker Amazon S3 Cloudfront
Notebooks Algorithm Training

Deploy

Code Commit SageMaker


Hosting

AWS API Inference requests


Code Pipeline Amazon ECR Lambda Gateway

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SageMaker 기반 ML 모델 생성 및 훈련
Amazon S3
Save Model
Fetch Training data ML Artifacts
Training
code
Save Inference
Image
Amazon ECR

BUILT DEEP LEARNING BRING YOUR OWN


ALGORITHMS FRAMEWORKS MODEL

K-Means Clustering
Principal Component Analysis
Neural Topic Modelling
Factorization Machines
Linear Learner - Regression
XGBoost Caffe2, CNTK, PyTorch, Torch
Bring Your Own Script
Latent Dirichlet Allocation (IM builds the Container)
Image Classification
Seq2Seq IM Estimators in Spark AWS MARKETPLACE
Linear Learner - Classification MACHINE LEARNING

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SageMaker - 자동 하이퍼 파라미터 최적화(HPO) 기능

Keras 기반 Plant Seedling CPU (ml.m5.xlarge) 작업 시 GPU (ml.p2.xlarge) 작업 시


Speed = 4 mins/epoch Speed = 4.8 seconds/epoch
Dataset을 위한 CNN 학습 모델 Total Runtime = ~20 hours Total Runtime = ~3 hours
(최대 150 Epoch 학습) Cost = .269 * 20 = $5.38 Cost = 1.26 * 3 = $3.78

https://medium.com/datadriveninvestor/auto-model-tuning-for-keras-on-amazon-sagemaker-plant-seedling-dataset-7b591334501e
https://aws.amazon.com/blogs/machine-learning/amazon-sagemaker-automatic-model-tuning-produces-better-models-faster/
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ML 모델 훈련에 대한 비용과 시간 대비 효과

Distributed, with
$$$$ Strong Machines

$$$ Single
Machine
$$

Minutes Hours Days Weeks Months

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ML 모델 훈련에 대한 비용과 시간 대비 효과

$$$$

$$$
On-premise
$$ EC2 + AMI
$ Amazon SageMaker

Minutes Hours Days Weeks Months

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo – SageMaker 기반 모델 훈련하기

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
사례. SageMaker 기반 기계 학습 구현 사례

“광고 기술 서비스 스타트업인 IGAWorks는 AWS 기반으로


일 50억 건의 디스플레이 광고 요청를 처리하는
트레이딩웍스와 22,000여개 모바일 앱이 탑재된
애드브릭스 등을 운영하고 있습니다. 광고 효율 개선 및
지속적인 최적화를 위한 기계 학습 모델 관리의 편의성과
프로덕션 적용 시간을 단축하는 Amazon SageMaker를
도입해 A.I Lab의 업무 효율성이 높아졌습니다.

기업 규모와 상관 없이
다양한 고객 활용 중!
Machine Learning 모델 학습은 쉽고,
빠르며, 비용 효과적으로 가능하지만… Training

추론 Inference 작업은? Infrastructure


costs

추론 작업이 전체 기계 학습
비용의 대부분을 차지함 Inference

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
추론 비효율의 두 가지 주요 요인 :
복잡성 및 비용
다양한 추론 탄력적인 추론이
케이스가 존재 가능해야 함

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
추론 작업을 더 효율적으로 하는 방법
더 작은 P2 인스턴스를 더 작은 배치 크기로 실행하는 것이 더 효과적입니다.

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
NEW!
EC2
Instance

Amazon
Elastic Inference
EC2
Instance GPU
EC2
Instance

훨씬 저렴한 비용으로 신속한 추론을 위해 Amazon EC2 인스턴스에 GPU 가속 기능 추가 (최대 75 % 절감)

P3 P3
36 TOPS GPU
P3.8XL M5.large

P3 P3
Amazon
Elastic Inference Amazon
Elastic Inference

Before After
NEW!

AWS Inferentia
고성능 기계 학습 추론을 위한 AWS에서 설계 한 맞춤형 칩셋

EC2 인스턴스 지원
고성능 처리량

다양한 다양한 Amazon SageMaker 지원


낮은 대기시간
데이터 타입 ML 프레임워크
INT8, FP16, TensorFlow, MXNet,
수백 TOPS 지원 mixed precision PyTorch, Caffe2, ONNX Amazon Elastic Inference 지원
Amazon Elastic Inference - 확장성 및 비용
Starting at Up to

1 TFLOPS 32 TFLOPS
VPC 내부의 추론 간단한 음성 인식 및 추천 엔진 또는 사기 다양한 인스턴스
자연어 처리 모델 탐지 모델 타입 활용 가능
탄력성 보장

ResNet-50 360,000 $0.22 75%


컴퓨터 비전 사례 추론에 필요한 시간당 시간당 비용 기존 대비
딥러능 모델 이미지 숫자 비용 절감
LOWEST COST
AVAILABLE

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
원하는 용량에 따라 가속기 타입 추가 가능
FP32 FP16 Accelerator
Accelerator Price ($/hr)
Throughput Throughput Memory
Type (US)
(TOPS) (TOPS) (GB)

eia1.medium 1 8 1 $0.13

eia1.large 2 16 2 $0.26

eia1.xlarge 4 32 4 $0.52

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
기존 GPU와 Elastic Inference와 비용 차이

120 70 140

100 60 120

50 100
80
40 80
60
30 60
40
20 40

20 10 20

0 0 0

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EC2에 활용하는 방법
Region

VPC

Availability Zone

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EC2 Auto Scaling groups에 적용하기

Auto Scaling group

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SageMaker에 적용하기
SageMaker Notebooks

SageMaker Hosted Endpoints

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Elastic Inference 설정 및 사용 방법
• 일반 EC2 인스턴스 선택 후, 미리 설정된 AMI에서 원하는 EI 가속기 선택
• EI 가속기가 접속할 수 있는 VPC 엔드포인트 권한 설정 필수

$ aws ec2 run-instances


--image-id <preconfigured_ami_id>
--instance-type <ec2_instance_type>
--key-name <key_name>
--subnet-id <subnet_id>
--security-group-ids <security_group_id
--iam-instance-profile Name=”iam_profile_name”
--elastic-inference-accelerator Type=eia1.<size>

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Elastic Inference 설정 및 사용 방법
• MVCNN 모델 등 TF Estimators 포맷에 추가
• Dimensions: [batch_size , num_views , width , height , color_channels]
classifier = tf.estimator.Estimator(…)
input_tensor = tf.placeholder(dtype=tf.float32,
shape=[1, 80, 128, 128, 1],
name='images_tensor’)
input_map = {'images’ : input_tensor}
classifier.export_savedmodel(model_dir,
tf.estimator.export.build_raw_serving_input_receiver_fn(input_map))

• Tensorflow Serving API를 이용하여 모델 예측 사용

AmazonEI_TensorFlow_Serving_v1.11_v1 --model_name=mvcnn \
--model_base_path=model_dir --port=9000

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
맺으면서

• AWS Deep Learning AMI를 사용하시면, 기존 EC2 보다 7배 이상 빠릅니다!

• 스팟 구매 옵션으로 EC2 GPU 인스턴스를 활용하시면, 70% 저렴 합니다.

• SageMaker를 활용하시면, 모델 생성 부터 훈련, 배포 및 서비스까지 기계 학습


전 과정을 자동화 할 수 있습니다. (다음 세션에서 SageMaker의 더 많은 신기능을 살펴 보세요!)

• Elastic Inference를 활용하면, 추론 비용을 75% 이상 절감 할 수 있습니다.

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
마지막으로… AWS Innovate 에서는

데모 존 전문가에게 물어보세요 AWS 기반 머신러닝

실제 사용 환경에서 AWS 전문가가 질문에 https://aws.amazon.com/


기계학습의 사용방법을 답변드립니다 machine-learning/
살펴보세요

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
클라우드 및 인공 지능 관련 AWS 전문 교육 프로그램

온라인 교육 강의식 교육 AWS 자격증


AWS 전문가가 진행하는 AWS 공인 강사가 진행하는 클라우드 전문성 입증을 위한
무료 온라인 교육 과정 오프라인 교육 과정 업계에서 인정 받는
AWS 공인 자격증

클라우드 역량을 개발할 준비가 되셨다면


https://www.aws.training 을 방문하세요!
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Innovate
AWS Innovate 에 참석해주셔서
에 참석해주셔서 대단히 감사합니다.
대단히 감사합니다.
저희가 준비한 내용, 어떻게 보셨나요?
더 나은 세미나를 위하여 설문을 꼭 작성해 주시기 바랍니다.

aws-korea-marketing@amazon.com
twitter.com/AWSKorea

facebook.com/amazonwebservices.ko
youtube.com/user/AWSKorea

slideshare.net/awskorea
twitch.tv/aws

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

You might also like