1 of 15

LLM fine-tuning

with Healthcare data 이론 및 실습

2024-11-14, 10:00 ~ 12:00

Seongsu Bae, Sujeong Im

KAIST AI @ Edlab (Advised by Edward Choi)

KoSAIM 2024 개발자를 위한 의료 AI 심화교육 II

2 of 15

Speaker Bio

Sujeong Im (임수정)

Education

  • POSTECH Creative IT Engineering, B.Sc�(2018-2022)
  • KAIST Kim Jaechul Graduate School of AI, M.Sc (2023-)

��Research Interests

  • Foundation Model
  • Natural Language Processing
  • Machine Learning for Healthcare

Seongsu Bae (배성수)

Education

  • Hanyang University Mathematics, B.Sc (2013-2019)
  • KAIST Kim Jaechul Graduate School of AI, M.Sc (2020-2022)
  • KAIST Kim Jaechul Graduate School of AI, Ph.D (2022-)

Research Interests

  • Semantic Machine
  • Multimodal Learning
  • Machine Learning for Healthcare

3 of 15

Asclepius-Meta-Llama-3-8B

4 of 15

How can we build an instruction-following LLM in the clinical domain?

Prepare a pre-trained large language model

Pre-training on clinical corpus for domain adaptation

Perform supervised fine-tuning using domain-specific clinical instruction data

Asclepius-Meta-Llama-3-8B

use Meta-Llama3-8B model

Pre-training (1 epoch): 2h 59m with 4x A100 80G

dataset: 158k synthetic clinical notes

Instruction fine-tuning (3 epoch): 30h 41m with 4x A100 80G

dataset: 158k clinical instruction-response pairs with synthetic notes

5 of 15

How can we build an instruction-following LLM in the clinical domain?

Prepare a pre-trained large language model

Pre-training on clinical corpus for domain adaptation

Perform supervised fine-tuning using domain-specific clinical instruction data

(실습) Asclepius-phi-2

use phi-2 (2.7B) model

LLM fine-tuning (QLoRA) on a T4 GPU (16 GiB), using a sampled set from 158k clinical instruction-response pairs with synthetic notes.

6 of 15

Deep learning memory layout

  • Model size: B (billion) scale
    • xB parameters = xB floating point numbers = 2x GB (bf16/fp16)
  • Deep Learning Memory Requirements
    • model parameter: 2x GB
    • gradient state: 2x GB
    • optimizer state: 2x ~ 12x GB
    • Total: 6~16x GB + alpha
  • Our requirements
    • model: phi-2 (2.7B)
    • GPU VRAM: Colab T4 (16GB)
    • 2.7*6=16.2

7 of 15

Can You Run it?

8 of 15

LoRA (Hu and Shen et al., 2021)

9 of 15

QLoRA (Dettmers and Pagnoni et al., 2023)

10 of 15

Parameter-Efficient Fine-Tuning (PEFT)

11 of 15

Colab 실습 파트

12 of 15

Colab 실습 개요

  • Goal: LLM (instruction) fine-tuning with Healthcare data
    • (step 1) 환경 세팅
    • (step 2) 사전 학습된 모델 및 토크나이저 불러오기
    • (step 3) Asclepius-Synthetic-Clinical-Notes 데이터셋 확인하기
    • (step 4) 학습 데이터 전처리
    • (step 5) 모델 학습
    • (step 6) huggingface hub에 모델 업로드
    • (step 7) 모델 추론
    • (step 8) 모델 평가

13 of 15

Colab 실습 주의사항

  • Colab GPU 사용 시간 제한에 걸리는 경우, 새로운 Google 아이디로 Colab에 접속해주시기 바랍니다.
  • LLM 학습 과정 중 Colab을 절대 끄지 마세요. (새로고침 금지, 코랩 내 다른 버튼 클릭 금지)

14 of 15

Colab 실습 링크

15 of 15

Thank you :D

If you require any further information, feel free to contact us: seongsu@kaist.ac.kr, sujeongim@kaist.ac.kr

KoSAIM 2024 개발자를 위한 의료 AI 심화교육 II