Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

JINIers

Building and Deploying Machine Learning Solutions with Vertex AI: Challenge Lab 본문

GCP/Qwiklabs

Building and Deploying Machine Learning Solutions with Vertex AI: Challenge Lab

JINIers 2022. 5. 4. 10:46

220427_vertex AI로 머신러닝 솔루션 구축 및 배포

 

시작하기 전에

이거 시간 진짜 오래걸리고 정말 어려움 퀵랩 기회는 5번인데 막판에 성공했다.

오타 하나라도 나면 에러나서 안되고

기존에 생성되어 있는 것 중에 알파벳 하나라도 지우면 그냥 그날로 끝임

종료하고 새로 시작해야함

ㅎ 진짜... 킹받아

 

 

시작하자..


목표

1. 호스팅된 vertex 노트북에서 로컬로 tensorflow 모델을 훈련시킴
2. cloud build로 학습 코드를 컨테이너화하고 vertex 커스텀 컨테이너 학습 워크플로의 일부로 google cloud artifact registry에 푸시
3. 예측을 제공하기 위해 학습된 모델을 vertex on line prediction endpoint에 배포
4. 온라인 예측 요청 및 응답확인

 


도전 시나리오

제한된 데이터로 고성능 기계 학습 모델을 신속하게 구축 및 배포하기 위해 google cloud의 vertex ai 플랫폼에서 온라인 예측을 위한 맞춤형 tensorflow BERT 감정 분류기를 학습하고 배포하는 과정을 안내함

vertex ai는 google cloud의 차세대 머신러닝 개발플랫폼으로 사전 구축된 최신 ML 구성요소와  autoML을 활용하여 개발 생산성, 워크플로 및 데이터로 의사 결정을 확장하는 기능을 크게 향상하고 가치 실현시간을 단축할 수 있음

* BERT란?
Bidirectional Encoder Representations from Transformers, 구글 인공지능 언어모델

 

 

 

진행순서 

1. tf-hub 및 분류 계층의 사전 훈련된 BERT 구성 요소에서 모델을 구축하여 vertex notebook에서 모델을 훈련 및 평가하는 일반적인 실험 workflow를 진행

2. 모델 코드를 docker 컨테이너에 패키징하여 google cloud의 vertex ai에서 학습

3. vertex pipelines에서 kubeflow pipeline을 정의하고 실행하여 온라인 예측을 쿼리할 vertex endpoint에 모델을 교육하고 배포함

 

 

 

* 참고 : https://www.youtube.com/watch?v=IypIn9tOLA0 


1. vertex notebooks 인스턴스 생성

 

vertex ai > workbench > create notebook >

name : vertex-ai-challenge
version : TensorFlow Enterprise 2.6


2. 챌린지 노트북 다운로드

vertex-ai-challenge > open jupyter > terminal


[리포지토리 복제]

git clone https://github.com/GoogleCloudPlatform/training-data-analyst

 

[패키지 설치]

cd training-data-analyst/quests/vertex-ai/vertex-challenge-lab
pip install -U -r requirements.txt


training-data-analyst/quests/vertex-ai/vertex-challenge-lab 폴더로 이동

vertex-challenge-lab.ipynb 파일 열기

PROJECT_ID및 GCS_BUCKET변수 USER를 정의

 

[데이터 세트 가져오기]

#2

PROJECT_ID = !(gcloud config get-value core/project)
PROJECT_ID = PROJECT_ID [0]


#3

GCS_BUCKET = f"gs://{PROJECT_ID}-vertex-ai-challenge-lab"


3. vertex notebook 에서 로컬로 모델 빌드 및 학습

[tensorFlow BERT 감정 분류기 빌드 및 컴파일]

3.1. BERT 텍스트 전처리를 위해 추가할 섹션을 작성 하십시오.hub.KerasLayer
#18

preprocessor = hub.KerasLayer(hparams['tfhub-bert-preprocessor'], name='preprocessing')


3.2. BERT 텍스트 인코딩을 위해 추가할 섹션을 작성 하십시오.hub.KerasLayer
#18

encoder = hub.KerasLayer(hparams['tfhub-bert-encoder'], trainable=True, name='BERT_encoder')

 


3.3. 섹션을 작성하여 BERT 감정 분류기를 로컬에 저장(./bert-sentiment-classifier-local디렉토리에 저장)
#23

"model-dir" : "./bert-sentiment-classifier-local"


4. cloud build를 사용하여 모델 컨테이터를 빌드하고 google cloud artifact registry에 제출

[섹션을 작성하여 gcloud CLI를 사용하여 Docker Artifact Registry 생성]

#33 '오래걸리는 구간'

!gcloud artifacts repositories create {ARTIFACT_REGISTRY} \
--repository-format=docker \
--location={REGION} \
--description="Artifact registry for ML custom training images for sentiment classification"


[cloud build를 사용하여 컨테이너 이미지를 빌드하고 artifact registry에 제출]

# 36 '오래걸리는 구간'

!gcloud builds submit {MODEL_DIR} --timeout=20m --config {MODEL_DIR}/cloudbuild.yaml


#38

USER = "qwiklabdemo"


#40

display_name=display_name,
container_uri=container_uri,
model_serving_container_image_uri=model_serving_container_image_uri,
base_output_dir=base_output_dir



* 44 '오래걸리는 구간'
와 진짜진짜 오래걸려 주글것같다

30분 넘게 걸림

vertex_piplines_job.run()

 


5. KFP SDK를 사용하여 파이프라인 정리

[위의 셀에 정의된 구성요소를 추가 및 구성하는 섹션 작업]

#46

endpoint_name=ENDPOINT_NAME,
project=PROJECT_ID,
location=REGION

 

 

#47

test_review = "The Dark Knight is the best Batman movie!"


#48

prediction = endpoint.predict([test_review])





 

Comments