da extração dos dados ao deploy em produção machine learning efetivo com aws · 2019-05-17 ·...
TRANSCRIPT
![Page 1: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/1.jpg)
1
#TheDevConf 2019
Machine Learning Efetivo com AWS:Da extração dos dados ao deploy em produção
BRUNO BITENCOURTSoftware Architect
![Page 2: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/2.jpg)
2
#TheDevConf 2019
Agenda
• Machine Learning e AWS
• SageMaker
• Dicas
• Links úteis
![Page 3: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/3.jpg)
3
#TheDevConf 2019
@brunowdev
• Arquiteto de Software - P&D da Betha Sistemas
• +5 anos experiencia
• Aluno de Engenharia da Computação na FASATC e Machine Learning Engineer
na Udacity
![Page 4: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/4.jpg)
4
#TheDevConf 2019
Machine Learning e AWS
![Page 5: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/5.jpg)
5
#TheDevConf 2019
Workflow
![Page 6: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/6.jpg)
6
#TheDevConf 2019
Quanta coisa, não é mesmo?
![Page 7: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/7.jpg)
7
#TheDevConf 2019
SageMaker
![Page 8: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/8.jpg)
8
#TheDevConf 2019
Treinamento
Factorization MachinesLinear RegressionPCAK-MeansXGBoost
E vários outros!
Algoritmos Built-in Traga a sua Impl. Traga seu container
![Page 9: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/9.jpg)
9
#TheDevConf 2019
Interagindo com o SageMaker
Python SDK
• Notebooks
• Algoritmos
• Treinamento
• Deploy
• Tuning
• AWS CLI: ‘aws sagemaker’
• AWS SDK: boto3, entre outros.
• Interface WEB
![Page 10: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/10.jpg)
10
#TheDevConf 2019
Mas antes disso...
![Page 11: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/11.jpg)
11
#TheDevConf 2019
Etapa 0: Dados
• SQL
• NoSQL
• Aquele dataset do Governo com 500GB
• Outros sistemas
• Data Lake?
![Page 12: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/12.jpg)
12
#TheDevConf 2019
Pipeline de Machine Learning Serverless
![Page 13: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/13.jpg)
13
#TheDevConf 2019
![Page 14: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/14.jpg)
14
#TheDevConf 2019
S3
• Buckets para armazenamento
• Big Data
• Velocidade na escrita/acesso
• Também armazenamos nossos modelos de ML
![Page 15: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/15.jpg)
15
#TheDevConf 2019
Glue• Catalogo de dados (S3, SQL, NoSQL)
• Serverless ETL
• Jobs de extração
○ Python (Spark ou Shell)
○ Scala
• Segurança e parametrização
• Storage no S3
![Page 16: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/16.jpg)
16
#TheDevConf 2019
SchedulingJob ETL
![Page 17: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/17.jpg)
17
#TheDevConf 2019
SQL
![Page 18: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/18.jpg)
18
#TheDevConf 2019
Particionamento no S3
Eventos: Sucesso, Falha, etc.
Data Cleaning
![Page 19: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/19.jpg)
19
#TheDevConf 2019
![Page 20: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/20.jpg)
20
#TheDevConf 2019
Etapa 1: Usando o Dataset
![Page 21: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/21.jpg)
21
#TheDevConf 2019
Infos
• Standard - Sem GPU
• Compute Optimized - Sem GPU
• GPU Instances - Com GPU - inicia $ 1.26 hora
• O disco varia de 5GB SSD ate 16TB
• Não é obrigatório
• Scripts de Setup e Integração com o Git (não é git friendly)
![Page 22: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/22.jpg)
22
#TheDevConf 2019
GPU
Tensorflow e MxNet
![Page 23: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/23.jpg)
23
#TheDevConf 2019
Etapa 2: SageMaker
![Page 24: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/24.jpg)
24
#TheDevConf 2019
Infos
• Imagens Docker - Train mode e Invocations (HTTP)
• Serverless ou Endpoint
• Qualquer linguagem ou framework
• Lê os dados do S3
• Escreve os modelos no S3
![Page 25: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/25.jpg)
25
#TheDevConf 2019
Devo fazer o meu container?
• Os modelos da AWS são mais otimizados
• Podem ser uma caixa “preta”
• Vendor lock-in
![Page 26: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/26.jpg)
26
#TheDevConf 2019
Levando o SciKit Learn para o SageMaker
![Page 27: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/27.jpg)
27
#TheDevConf 2019
Exemplo - Treinamento
![Page 28: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/28.jpg)
28
#TheDevConf 2019
Exemplo - Treinamento
![Page 29: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/29.jpg)
29
#TheDevConf 2019
Exemplo - Treinamento
![Page 30: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/30.jpg)
30
#TheDevConf 2019
Exemplo - Predictor
![Page 31: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/31.jpg)
31
#TheDevConf 2019
Exemplo - Predictor
![Page 32: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/32.jpg)
32
#TheDevConf 2019
Exemplo - Predictor
![Page 33: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/33.jpg)
33
#TheDevConf 2019
Treinando o modelo
• Manual
• Baseado em eventos
![Page 34: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/34.jpg)
34
#TheDevConf 2019
Treinando o modelo
![Page 35: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/35.jpg)
35
#TheDevConf 2019
AWS Lambda
● Funções Serverless
● Várias linguagens disponíveis
● Integração com eventos
● Baixo custo
● Comunicação direta com os demais
serviços
![Page 36: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/36.jpg)
36
#TheDevConf 2019
![Page 37: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/37.jpg)
37
#TheDevConf 2019
Rastreabilidade
![Page 38: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/38.jpg)
38
#TheDevConf 2019
Hyperparameter Tuning
• Semelhante a job de treinamento
• Qualquer modelo
• Warmup (incremental iterativo ou outra versão)
![Page 39: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/39.jpg)
39
#TheDevConf 2019
Hyperparameter Tuning
![Page 40: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/40.jpg)
40
#TheDevConf 2019
Deploy
• Endpoint Configuration - Middleman
○ Roteia com base em headers (id de usuário, região, etc.)
• Sem Downtime
• Auto Scaling
• Canary Deployment
• Teste A/B
○ Monitoramento/Scoring é manual
![Page 41: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/41.jpg)
41
#TheDevConf 2019
Inferência
• Endpoint SageMaker - Requer uma instância rodando
• Batch Transform Jobs
![Page 42: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/42.jpg)
42
#TheDevConf 2019
![Page 43: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/43.jpg)
43
#TheDevConf 2019
Consumindo as Predições
![Page 44: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/44.jpg)
44
#TheDevConf 2019
Considerações
• Para gerenciar os componentes: Terraform, Cloudformation:
○ Todas se integram com facilidade com CI (Jenkins, Gitlab, etc.)
![Page 45: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/45.jpg)
45
#TheDevConf 2019
Dicas
• Use só as peças que você precisa
• Desligue os seus notebooks (pode ser automatizado)
• Ajuste as instâncias de treino/predição de acordo com a sua necessidade
• Use as imagens/algoritmos disponíveis, sempre que possível
• Use RecordIO / TFRecord
![Page 46: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/46.jpg)
46
#TheDevConf 2019
Outros recursos
GroundTruth
• Automatizar o processo de labelling
Marketplace
• Publique e venda seus modelos
![Page 47: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/47.jpg)
47
#TheDevConf 2019
Outras informações
SageMaker
• Possue free-tier
• Ainda não está disponível na sa-east-1
○ Latência pode ser um problema
![Page 48: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/48.jpg)
48
#TheDevConf 2019
Por onde começar?
AWS
• Getting Started
• Playlist - This is my Architecture
SageMaker
• Julien Simon
• Exemplos GitHub
![Page 50: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/50.jpg)
50
#TheDevConf 2019
Perguntas?
![Page 51: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/51.jpg)
51
#TheDevConf 2019
![Page 52: Da extração dos dados ao deploy em produção Machine Learning Efetivo com AWS · 2019-05-17 · Software Architect. 2 #TheDevConf 2019 Agenda • Machine Learning e AWS • SageMaker](https://reader034.vdocuments.net/reader034/viewer/2022050309/5f70f90c5c9ddb39c8789b8e/html5/thumbnails/52.jpg)
52
#TheDevConf 2019